Skip to content

Commit 2b2a6c7

Browse files
authored
Merge pull request #705 from github/app-installs-script
2 parents 1d22047 + 1b432ff commit 2b2a6c7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

api/bash/app-installs.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# The first argument passed to the script is assigned to the variable ENTERPRISE
4+
ENTERPRISE="$1"
5+
6+
# This is a GraphQL query that fetches the first 50 organizations of an enterprise
7+
# The query takes two variables: slug (the enterprise's slug) and endCursor (for pagination)
8+
QUERY='
9+
query($slug:String!, $endCursor:String) {
10+
enterprise(slug:$slug){
11+
organizations(first:50, after:$endCursor){
12+
pageInfo{
13+
endCursor
14+
hasNextPage
15+
}
16+
nodes {
17+
login
18+
}
19+
}
20+
}
21+
}'
22+
23+
# This loop iterates over each organization in the enterprise
24+
# The 'gh api graphql' command is used to execute the GraphQL query
25+
# The '-f' option is used to pass the query string
26+
# The '-F' option is used to pass the enterprise's slug
27+
# The '--jq' option is used to parse the JSON response and extract the login of each organization
28+
for organization in $(gh api graphql -f query="${QUERY}" -F slug="${ENTERPRISE}" --jq '.data.enterprise.organizations.nodes[].login'); do
29+
# This line prints a message to the console
30+
echo "Installations for $organization"
31+
# This line fetches the installations for the current organization
32+
# The 'gh api' command is used to make a request to the GitHub API
33+
gh api "/orgs/$organization/installations"
34+
done

0 commit comments

Comments
 (0)