Created
November 4, 2016 10:20
-
-
Save jonico/00423c3cbed1e7980ce913205b37143f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
package org.kohsuke.github | |
@Grab(group='org.kohsuke', module='github-api', version='1.75') | |
import org.kohsuke.github.GitHub | |
class ListUsersInOrganizations extends GitHub { | |
static void main(args) { | |
def cli = new CliBuilder(usage: 'groovy -t <personal access token> ListUsersInOrganizations.groovy [organizations]') | |
cli.t(longOpt: 'token', 'personal access token', required: false , args: 1 ) | |
OptionAccessor opt = cli.parse(args) | |
if(opt.arguments().size() < 1) { | |
cli.usage() | |
return | |
} | |
def githubCom | |
if (opt.t) { | |
githubCom = GitHub.connectUsingOAuth(opt.t); | |
} else { | |
githubCom = GitHub.connect(); | |
} | |
def uniqueUsers = new HashSet(); | |
opt.arguments().each { | |
println "Org ${it} members:" | |
githubCom.getOrganization(it).listMembers().each { | |
println it.getLogin(); | |
uniqueUsers << it.getLogin() | |
} | |
println "---" | |
} | |
println "Unique members of all processed orgs:" | |
uniqueUsers.each {println it} | |
println "---"; | |
println "Total user count: ${uniqueUsers.size()}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment