Removing a collaborator from all GitHub repos

I help manage the GitHub account for the company I work for. Recently, I’ve been in a situation where I needed to remove a former colleague from about 25 GitHub repositories. Admittedly this is only painful because the account we’re using is an individual account. Frustratingly, “Organizations” an account type introduced to deal with this exact issue, is difficult to justify to management because of the additional cost. In the meantime I’ve written a quick script using the GitHub Api that iterates through the repositories and removes a given collaborator. You can find the source code below:

source ""

gem 'httparty'

A library to package up some functionality:

require 'rubygems'
require 'bundler/setup'

class Github
  include HTTParty
  base_uri ''

  def initialize(user, pass)
    @username = user
    self.class.basic_auth user, pass

  def repositories
    response = Github.get("/repos/show/#{@username}")
    response.parsed_response["repositories"]  if response.code==200

  def collaborators(repository)
    response = Github.get("/repos/show/#{@username}/#{repository}/collaborators")
    response.parsed_response["collaborators"] if response.code==200

  def remove_collaborator(respository, name)"/repos/collaborators/#{@username}/#{repository}/remove/#{name}")

And the actual script:

# remove_user.rb
require 'lib/github'

if ARGV.empty?
  puts "Usage: remove_user <username>"
  exit -1

username = ARGV.first

github ='vertis', 'xxxx')
github.repositories.each do |repo|
  if repo["private"]==true
    puts "Checking: #{repo['name']}"
    collaborators = github.collaborators(repo['name'])
    if collaborators.include?(username)
      puts "Removing '#{username}' from collaborators list of '#{repo['name']}'"
      github.remove_collaborator(repo['name'], username)

It’s certainly not a polished script, but it does the job. Hopefully, I’ll eventually be able to convince my manager to upgrade :)