Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Forked from jdennes/Gemfile
Last active May 20, 2020 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kalbasit/06b3eb6bf9f2a70849286c3fe71d2894 to your computer and use it in GitHub Desktop.
Save kalbasit/06b3eb6bf9f2a70849286c3fe71d2894 to your computer and use it in GitHub Desktop.
Export a list of members from a GitHub organisation

Usage:

Get set up:

$ git clone https://gist.github.com/11404512.git export-members; cd export-members 

Bundle (we're going to use Octokit):

$ bundle install

Replace <org-username> with the username of your organization in export-all-members.rb and/or export-all-members-with-2fa-disabled.rb.

Then export all members:

$ OCTOKIT_ACCESS_TOKEN=<yourtoken> bundle exec ruby export-all-members.rb
$ cat export-all.csv

or, export members with 2FA disabled:

$ OCTOKIT_ACCESS_TOKEN=<yourtoken> bundle exec ruby export-all-members-with-2fa-disabled.rb
$ cat export-2fa-disabled.csv
#! /usr/bin/env ruby
# Set OCTOKIT_ACCESS_TOKEN to authenticate
require "octokit"
Octokit.auto_paginate = true
members = Octokit.org_members "<org-username>"
# Then, for example:
require "csv"
CSV.open("export-all.csv", "wb") do |csv|
csv << ["id", "login", "name", "type", "profile-url"]
members.each do |m|
m_info = Octokit.user(m[:login])
csv << [m[:id], m[:login], m_info[:name], m[:html_url]] # etc
end
end
source "https://rubygems.org"
gem "octokit"
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
faraday (1.0.1)
multipart-post (>= 1.2, < 3)
multipart-post (2.1.1)
octokit (4.18.0)
faraday (>= 0.9)
sawyer (~> 0.8.0, >= 0.5.3)
public_suffix (4.0.5)
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
PLATFORMS
ruby
DEPENDENCIES
octokit
BUNDLED WITH
1.17.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment