Skip to content

Instantly share code, notes, and snippets.

@jmassardo
Created November 16, 2021 15:00
Show Gist options
  • Save jmassardo/93f0bc43341ad2871a248aa2cb3b65f9 to your computer and use it in GitHub Desktop.
Save jmassardo/93f0bc43341ad2871a248aa2cb3b65f9 to your computer and use it in GitHub Desktop.
A simple ruby script to get a list of orgs and the user count for each.
#!/usr/bin/env ruby
require 'octokit'
require 'json'
client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
query = <<-GRAPHQL
query {
enterprise(slug: "<MY-ENT-NAME>"){
organizations(first: 100){
nodes{
name
}
}
}
}
GRAPHQL
enterprises = client.post '/graphql', { query: query }.to_json
puts enterprises.data.enterprise.organizations.nodes.inspect
enterprises.data.enterprise.organizations.nodes.each do |org|
puts org.name
org_data = client.org_members(org.name)
puts org_data.count
end
@jmassardo
Copy link
Author

Usage:

Replace your enterprise slug on line 10.

gem install octokit
gem install json

export GITHUB_TOKEN=<My-Super_secret-Token!>

ruby fetch_user_count_by_org.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment