-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathget-users-directly-added-to-repositories.sh
executable file
·40 lines (38 loc) · 1.25 KB
/
get-users-directly-added-to-repositories.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# note: this is a bit of a hack; there is no direct way to pull users added directly to repositories
# note: custom repository roles will show up as the base permission role
# credits @kenmuse
gh api graphql -F org="joshjohanning-org" -f query='
query ($org: String!) {
organization(login: $org) {
repositories(first: 100) {
pageInfo{
hasNextPage
endCursor
}
nodes {
name
collaborators(first: 100, affiliation:DIRECT) {
pageInfo{
hasNextPage
endCursor
}
edges {
permissionSources {
permission
source {
... on Repository {
nameWithOwner
repoName: name
}
}
}
node {
userHandle: login
}
}
}
}
}
}
}' --template '{{range .data.organization.repositories.nodes}}{{ $repo:= .name }}{{range .collaborators.edges }}{{ $handle := .node.userHandle }}"{{ $repo }}", "{{ $handle }}", {{ range .permissionSources }}{{ $permission := .permission }}{{ with .source.repoName }}"{{ $permission }}"{{ break }}{{ end }}{{ end }}{{ println }}{{ end }}{{ end }}'