Skip to content

Instantly share code, notes, and snippets.

@xalvarez
Last active January 21, 2021 11:46
Show Gist options
  • Save xalvarez/0d646888adac58ff71be09139fd6dbea to your computer and use it in GitHub Desktop.
Save xalvarez/0d646888adac58ff71be09139fd6dbea to your computer and use it in GitHub Desktop.
Retrieve the first 100 open pull requests of a team's first 100 GitHub repositories
#!/usr/bin/env bash
# Retrieve the first 100 open pull requests of a team's first 100 GitHub repositories.
# Requires:
# - git: https://git-scm.com/downloads
# - jq: https://stedolan.github.io/jq/download/
APPLICATION_NAME=$0
ORGANIZATION=$1
TEAM=$2
TOKEN=$3
function printHelp {
echo "usage: $APPLICATION_NAME <organization> <team> <token>"
echo " organization Name of a GitHub organization."
echo " team Name of a GitHub team."
echo " token Your GitHub Token."
exit 1
}
if [[ -z "$3" ]]; then
printHelp
fi
wget --quiet \
--method POST \
--header 'content-type: application/json' \
--header 'authorization: Bearer '"$TOKEN"'' \
--body-data '{"query":"query {\n organization(login: \"'"$ORGANIZATION"'\") {\n team(slug: \"'"$TEAM"'\") {\n repositories(first: 100, orderBy: {field: NAME, direction: ASC}) {\n nodes {\n name\n pullRequests(states: OPEN, first: 100, orderBy: {field: CREATED_AT, direction: ASC}) {\n nodes {\n url\n createdAt\n }\n }\n }\n }\n }\n }\n}"}' \
--output-document \
- https://api.github.com/graphql | jq -r '.data.organization.team.repositories.nodes[].pullRequests.nodes[] | select(length > 0) | .url'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment