Created
November 3, 2022 21:07
-
-
Save geoffjay/7a3d6e2e3c47c2e384be76de97486f20 to your computer and use it in GitHub Desktop.
GitHub GraphQL API query to get some simple PR metrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
QUERY='{ | |
search(type: ISSUE, query: "is:pr state:closed repo:clio/grow", first: 100) { | |
nodes { | |
... on PullRequest { | |
title | |
number | |
additions | |
deletions | |
comments { | |
totalCount | |
} | |
reviews(first: 100) { | |
totalCount | |
nodes { | |
comments { | |
totalCount | |
} | |
} | |
} | |
} | |
} | |
} | |
}' | |
# TODO: would like to reduce .reviews.nodes[].comments.totalCount into a single sum and include that as well | |
FIELDS=( | |
".title" | |
"(.number|tostring)" | |
"(.additions|tostring)" | |
"(.deletions|tostring)" | |
"(.comments.totalCount|tostring)" | |
"(.reviews.totalCount|tostring)" | |
) | |
SEP='+","+' | |
REGEX="$(printf "${SEP}%s" "${FIELDS[@]}")" | |
REGEX="${REGEX:${#SEP}}" | |
JQ_FIELDS=$(echo "${REGEX}") | |
echo "Number,Title,Additions,Deletions,Comment Count,Review Count" | |
gh api graphql \ | |
-f query="${QUERY}" \ | |
--jq ".data.search.nodes[] | ${JQ_FIELDS}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment