#!/usr/bin/env nix-shell #!nix-shell -i bash -p curl jq sta -I nixpkgs=channel:nixpkgs-unstable # https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line TOKEN= prs() { if [ -n "$1" ]; then after=", after: \"$1\"" fi QUERY=$(cat <<-EOF { repository(name: "nixpkgs", owner: "NixOS") { pullRequests(first: 100, states: OPEN$after) { nodes { url createdAt mergeable } pageInfo { hasNextPage endCursor } } } } EOF ) DATA=$(jq -n --arg query "$QUERY" '{ query : $query }') response=$(curl -sS -H "Authorization: token $TOKEN" -d "$DATA" https://api.github.com/graphql) #echo "$response" result=$(jq '.data.repository.pullRequests' <<< "$response") now=$(date +%s) echo "$result" | jq -cr '.nodes[]' | while read json; do url=$(jq -r '.url' <<< "$json") createdAt=$(jq -r '.createdAt' <<< "$json") mergeable=$(jq -r '.mergeable' <<< "$json") age=$(( now - $(date --date="$createdAt" +%s) )) if [ "$mergeable" != "CONFLICTING" ]; then echo "$age" else echo "Skipping $url since it's conflicting (age $age)" >&2 fi done if [ "$(echo "$result" | jq -r '.pageInfo.hasNextPage')" = true ]; then prs "$(echo "$result" | jq -r '.pageInfo.endCursor')" fi } prs | sta --median --mean