Skip to content

Commit ddcf80b

Browse files
authored
Merge pull request #115 from github/list-members-in-orgs
Groovy script to list all visible members in orgs
2 parents c45ee22 + 1134382 commit ddcf80b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

api/groovy/ListMembersInOrgs.groovy

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env groovy
2+
3+
/**
4+
* groovy script to show all members (that are visible to the personal access token) of the specified GitHub organizations
5+
*
6+
* The script will first print all visible members of each org individually, then provide a summary for all orgs
7+
*
8+
* Run 'groovy ListMembersInOrgs.groovy' to see the list of command line options
9+
*
10+
* First run may take some time as required dependencies have to get downloaded, then it should be quite fast
11+
*
12+
* If you do not have groovy yet, run 'brew install groovy'
13+
*/
14+
15+
package org.kohsuke.github
16+
17+
@Grab(group='org.kohsuke', module='github-api', version='1.75')
18+
import org.kohsuke.github.GitHub
19+
20+
class ListMembersInOrgs extends GitHub {
21+
22+
static void main(args) {
23+
24+
def cli = new CliBuilder(usage: 'groovy -t <personal access token> ListMembersInOrgs.groovy [organizations]')
25+
cli.t(longOpt: 'token', 'personal access token', required: false , args: 1 )
26+
27+
OptionAccessor opt = cli.parse(args)
28+
29+
if(opt.arguments().size() < 1) {
30+
cli.usage()
31+
return
32+
}
33+
34+
def githubCom
35+
36+
if (opt.t) {
37+
githubCom = GitHub.connectUsingOAuth(opt.t);
38+
} else {
39+
githubCom = GitHub.connect();
40+
}
41+
42+
def uniqueUsers = new HashSet();
43+
44+
opt.arguments().each {
45+
println "Org ${it} members:"
46+
githubCom.getOrganization(it).listMembers().each {
47+
println it.getLogin();
48+
uniqueUsers << it.getLogin()
49+
}
50+
println "---"
51+
}
52+
53+
println "Unique members of all processed orgs:"
54+
uniqueUsers.each {println it}
55+
56+
println "---";
57+
println "Total member count: ${uniqueUsers.size()}"
58+
}
59+
}

0 commit comments

Comments
 (0)