|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +# gets information for all webhooks for in an organization |
| 4 | + |
| 5 | +# need: `gh auth login -h github.com` and auth with a PAT! |
| 6 | +# since the Oauth token can only receive results for hooks it created for this API call |
| 7 | + |
3 | 8 | if [ $# -lt 1 ] |
4 | 9 | then |
5 | | - echo "usage: $0 <enterprise-slug> <format: tsv|json>" > output.csv/json |
| 10 | + echo "usage: $0 <enterprise slug> <hostname> <format: tsv|json> > output.tsv/json" |
6 | 11 | exit 1 |
7 | 12 | fi |
8 | 13 |
|
9 | | -# need: `gh auth login -h github.com` and auth with a PAT! |
10 | | -# sine the Oauth token can only receive results for hooks it created for this API call |
| 14 | +enterpriseslug=$1 |
| 15 | +hostname=$2 |
| 16 | +format=$3 |
| 17 | +export PAGER="" |
11 | 18 |
|
12 | | -auth_status=$(gh auth token 2>&1) |
| 19 | +# set hostname to github.com by default |
| 20 | +if [ -z "$hostname" ] |
| 21 | +then |
| 22 | + hostname="github.com" |
| 23 | +fi |
| 24 | + |
| 25 | +auth_status=$(gh auth token -h $hostname 2>&1) |
13 | 26 |
|
14 | 27 | if [[ $auth_status == gho_* ]] |
15 | 28 | then |
16 | | - echo "Token starts with gho_ - use "gh auth login" and authenticate with a PAT with read:enterprise, reaad:org, and admin:org_hook scope" |
| 29 | + echo "Token starts with gho_ - use "gh auth login" and authenticate with a PAT with read:org and admin:org_hook scope" |
17 | 30 | exit 1 |
18 | 31 | fi |
19 | | - |
20 | | -export PAGER="" |
21 | | -enterpriseslug=$1 |
22 | | -format=$2 |
23 | 32 | if [ -z "$format" ] |
24 | 33 | then |
25 | | - format="tsv"fi |
| 34 | + format="tsv" |
26 | 35 | fi |
27 | 36 |
|
28 | | -organizations=$(gh api graphql --paginate -f enterpriseName="$enterpriseslug" -f query=' |
| 37 | +organizations=$(gh api graphql --hostname $hostname --paginate -f enterpriseName="$enterpriseslug" -f query=' |
29 | 38 | query getEnterpriseOrganizations($enterpriseName: String! $endCursor: String) { |
30 | 39 | enterprise(slug: $enterpriseName) { |
31 | 40 | organizations(first: 100, after: $endCursor) { |
|
48 | 57 | for org in $organizations |
49 | 58 | do |
50 | 59 | if [ "$format" == "tsv" ]; then |
51 | | - gh api "orgs/$org/hooks" --paginate | jq -r --arg org "$org" '.[] | [$org,.active,.config.url, .created_at, .updated_at, (.events | join(","))] | @tsv' |
| 60 | + gh api "orgs/$org/hooks" --hostname $hostname --paginate --jq ".[] | [\"$org\",.active,.config.url, .created_at, .updated_at, (.events | join(\",\"))] | @tsv" |
52 | 61 | else |
53 | | - gh api "orgs/$org/hooks" --paginate | jq -r --arg org "$org" '.[] | {organization: $org, active: .active, url: .config.url, created_at: .created_at, updated_at: .updated_at, events: .events}' |
| 62 | + gh api "orgs/$org/hooks" --hostname $hostname --paginate --jq ".[] | {organization: \"$org\", active: .active, url: .config.url, created_at: .created_at, updated_at: .updated_at, events: .events}" |
54 | 63 | fi |
55 | 64 | done |
0 commit comments