Skip to content

Commit d1c07c7

Browse files
Merge pull request #78 from joshjohanning/org-custom-repo-roles-count-script
Add organizations custom repository roles count script
2 parents 5d63e5f + 5b9dd0f commit d1c07c7

9 files changed

+65
-2
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)

gh-cli/get-organization-webhooks.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# need: `gh auth login -h github.com` and auth with a PAT!
66
# since the Oauth token can only receive results for hooks it created for this API call
77

8+
# note: tsv is the default format
9+
# tsv is a subset of fields, json is all fields
10+
811
if [ $# -lt 1 ]
912
then
1013
echo "usage: $0 <org> <hostname> <format: tsv|json> > output.tsv/json"

gh-cli/get-organizations-apps-count.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise`
66

7-
# note: tsv is the default format
8-
# tsv is a subset of fields, json is all fields
7+
# note: format is tsv
98

109
if [ $# -lt 1 ]
1110
then

gh-cli/get-organizations-codeowner-usage.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise`
66

7+
# note: format is tsv
8+
79
if [ $# -lt 1 ]; then
810
echo "usage: $0 <enterprise slug> <hostname> > output.tsv"
911
exit 1
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

gh-cli/get-organizations-discussions-count.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise`
66

7+
# note: format is tsv
8+
79
if [ $# -lt 1 ]; then
810
echo "usage: $0 <enterprise slug> <hostname> > output.tsv"
911
exit 1

gh-cli/get-organizations-projects-count-classic.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise`
66

7+
# note: format is tsv
8+
79
if [ $# -lt 1 ]; then
810
echo "usage: $0 <enterprise slug> <hostname> > output.tsv"
911
exit 1

gh-cli/get-organizations-projects-count.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise`
66

7+
# note: format is tsv
8+
79
if [ $# -lt 1 ]; then
810
echo "usage: $0 <enterprise slug> <hostname> > output.tsv"
911
exit 1

gh-cli/get-organizations-webhooks.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# need: `gh auth login -h github.com` and auth with a PAT!
66
# since the Oauth token can only receive results for hooks it created for this API call
77

8+
# note: tsv is the default format
9+
# tsv is a subset of fields, json is all fields
10+
811
if [ $# -lt 1 ]
912
then
1013
echo "usage: $0 <enterprise slug> <hostname> <format: tsv|json> > output.tsv/json"

0 commit comments

Comments
 (0)