Skip to content

Instantly share code, notes, and snippets.

@zmughal
Last active January 31, 2022 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmughal/76ed32e7c5c02b25fdbe9bb3190d6ca7 to your computer and use it in GitHub Desktop.
Save zmughal/76ed32e7c5c02b25fdbe9bb3190d6ca7 to your computer and use it in GitHub Desktop.
#!/bin/bash
MY_USER=$(gh repo list --json owner -q '.[0].owner.login')
BOTS="dependabot renovate snyk-bot"
BOTS_CONDITION=$(echo $BOTS | tr ' ' '\n' | sed 's/^/ and .author.login != "/; s/$/" /' )
SELECT_AUTHORS=".author.login != \"$MY_USER\" $BOTS_CONDITION"
gh api graphql --paginate -f query='
query($endCursor: String) {
viewer {
repositories(ownerAffiliations: [OWNER,COLLABORATOR,ORGANIZATION_MEMBER], first: 100, after: $endCursor) {
nodes {
viewerPermission,
nameWithOwner,
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
author { login }
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
' --jq '
.[].viewer.repositories.nodes
| map( select(
.pullRequests.totalCount > 0
and
.viewerPermission != "READ"
) )
| .[]' \
| jq -c '
.pullRequests.authors = [
.pullRequests.nodes | map(select( '"$SELECT_AUTHORS"' ))
| .[] | .author.login ]
| {
name: (.nameWithOwner),
count: (.pullRequests.authors | length),
authors: (.pullRequests.authors)
}' \
| jq -sc ' map(select(.count>0)) | .[]' \
| sort | jq -c .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment