Class: GithubControl::Actions::RemoveCollaborators

Inherits:
GithubControl::Action show all
Defined in:
lib/github-control/actions/remove_collaborators.rb

Instance Method Summary collapse

Methods inherited from GithubControl::Action

#initialize, #options, register, set

Constructor Details

This class inherits a constructor from GithubControl::Action

Instance Method Details

#add_options(parser) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/github-control/actions/remove_collaborators.rb', line 6

def add_options(parser)
  parser.on("-R name", "--repository name", "The repository on Github") do |repository_name|
    options[:repository_name] = repository_name
  end

  parser.on("-U name", "--user name", "The user on Github") do |user_name|
    options[:user_name] = user_name
  end
end

#callObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/github-control/actions/remove_collaborators.rb', line 16

def call
  puts "Removing #{user.name} from the collaborators of #{repository.full_name}"
  puts "-" * 40
  unless repository.collaborators.include?(user)
    puts "#{user.name} is not a collaborator"
  else
    repository.collaborators.delete(user.name)
    puts "Done"
  end
end

#repositoryObject



27
28
29
# File 'lib/github-control/actions/remove_collaborators.rb', line 27

def repository
  @cli.console.current_user.repositories.get(options[:repository_name] || raise(ProblemWithOptions, "Please specify a repository"))
end

#userObject



31
32
33
# File 'lib/github-control/actions/remove_collaborators.rb', line 31

def user
  @cli.console.user_for(options[:user_name] || raise(ProblemWithOptions, "Please specify a user"))
end