GitHubのRepositoryに紐づいたUserを探すGraphQL
code:graphql
query FindRepo($node_id: String) {
organization(login: "ORG_NAME") {
repositories(first: 20, after: $node_id) {
totalCount
pageInfo {
endCursor
hasNextPage
}
nodes {
id
name
nameWithOwner
collaborators(affiliation: DIRECT) {
edges {
node {
login
}
permission
permissionSources {
source {
__typename
... on Organization {
login
}
... on Repository {
nameWithOwner
}
... on Team {
slug
}
}
}
}
}
}
}
}
}
code:bash
TMP_FILE="$PWD/tmp.json"
DEST="$PWD/repo_list"
QUERY="$PWD/repo.graphql"
set -ex
gh api graphql -f query="$(cat $QUERY)" > $TMP_FILE
jq -r '.data.organization.repositories.nodes[]|select(.collaborators.edges|length > 0)|.nameWithOwner' < $TMP_FILE > $DEST
cat $TMP_FILE
sleep 1
cursor=$(jq -r '.data.organization.repositories.pageInfo.endCursor' < $TMP_FILE )
gh api graphql -F node_id="$cursor" -f query="$(cat $QUERY)" > $TMP_FILE
jq -r '.data.organization.repositories.nodes[]|select(.collaborators.edges|length > 0)|.nameWithOwner' < $TMP_FILE >> $DEST
cat $TMP_FILE
done