Module: Bouncer

Defined in:
lib/bouncer.rb,
lib/bouncer/version.rb

Constant Summary collapse

VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.remove_collaborator(options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bouncer.rb', line 5

def self.remove_collaborator(options)
  collaborator, , token = options[:collaborator], options[:account], options[:token]

  return puts "Must provide a account" if .nil?
  return puts "Must provide a github token" if token.nil?
  return puts "Must provide a collaborator to remove" if collaborator.nil?

  return puts "You can't remove yourself from your projects" if !collaborator.nil? && collaborator == 

  repos = repositiories(, token)
  repos.each do |repo|
    remove_from_project(collaborator, repo['name'], , token)
    sleep 1 # to avoid hitting the github rate limit
  end

  puts "#{collaborator} was removed from #{repos.size} repositiories"
end

.remove_from_project(collaborator, repo_name, account, token) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bouncer.rb', line 29

def self.remove_from_project(collaborator, repo_name, , token)
  result = Curl::Easy.http_post("https://github.com/api/v2/json/repos/collaborators/#{repo_name}/remove/#{collaborator}",
                                Curl::PostField.content('login', ),
                                Curl::PostField.content('token', token))
  remaining_collaborators = JSON.parse(result.body_str)['collaborators']

  if remaining_collaborators.include?(collaborator)
    puts "Failed to remove #{collaborator} from #{repo_name}"
  else
    puts "Removed #{collaborator} from #{repo_name}"
  end
end

.repositiories(account, token) ⇒ Object



23
24
25
26
27
# File 'lib/bouncer.rb', line 23

def self.repositiories(, token)
  JSON.parse(Curl::Easy.http_post("https://github.com/api/v2/json/repos/show/#{}",
                                  Curl::PostField.content('login', ),
                                  Curl::PostField.content('token', token)).body_str)['repositories']
end