Skip to content

Commit 453cbe8

Browse files
committed
feat: add custom repo rules count script
1 parent 5d63e5f commit 453cbe8

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

gh-cli/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,10 @@ Gets a list of apps (and app information) in all organizations in a given enterp
808808

809809
Gets the usage of CODEOWNERS files in all repositories in all organizations in a given enterprise (checks `HEAD` for `./`, `./.github`, and `./docs` and returns `TRUE` or `FALSE` for each repository)
810810

811+
### get-organizations-custom-repository-roles-count.sh
812+
813+
Gets the count of custom repository roles in all organizations in a given enterprise
814+
811815
### get-organizations-discussions-count.sh
812816

813817
Gets the usage of discussions in all repositories in all organizations in a given enterprise (org-wide discussions have to be created in a repository, so this covers that as well)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# gets the custom repository roles for all organizations in an enterprise
4+
5+
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise`
6+
7+
# note: format is tsv
8+
9+
if [ $# -lt 1 ]
10+
then
11+
echo "usage: $0 <enterprise-slug> <hostname> > output.tsv"
12+
exit 1
13+
fi
14+
15+
export PAGER=""
16+
enterpriseslug=$1
17+
hostname=$2
18+
19+
# set hostname to github.com by default
20+
if [ -z "$hostname" ]
21+
then
22+
hostname="github.com"
23+
fi
24+
25+
organizations=$(gh api graphql --paginate --hostname $hostname -f enterpriseName="$enterpriseslug" -f query='
26+
query getEnterpriseOrganizations($enterpriseName: String! $endCursor: String) {
27+
enterprise(slug: $enterpriseName) {
28+
organizations(first: 100, after: $endCursor) {
29+
nodes {
30+
id
31+
login
32+
}
33+
pageInfo {
34+
endCursor
35+
hasNextPage
36+
}
37+
}
38+
}
39+
}' --jq '.data.enterprise.organizations.nodes[].login')
40+
41+
echo -e "Org\tCustoim Role Count"
42+
43+
for org in $organizations
44+
do
45+
gh api "orgs/$org/custom-repository-roles" --hostname $hostname --jq ". | [\"$org\", .total_count] | @tsv"
46+
done

0 commit comments

Comments
 (0)