Created
February 17, 2013 05:33
-
-
Save supernullset/4970331 to your computer and use it in GitHub Desktop.
Quick task to add org members to a specific repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'github_api' | |
require 'io/console' | |
class Teams < Thor | |
include Thor::Actions | |
desc "ls", "list users in an organization" | |
def ls(org) | |
connenction = connect | |
members = connenction.orgs.members.list org | |
members.map(&:login).each {|name| puts name} | |
end | |
desc "remove_access", "remove all users in an org from a repo" | |
def remove_access(org, repo) | |
connenction = connect | |
username = connenction.login | |
members = connenction.orgs.members.list org | |
members.map(&:login).each do |name| | |
if connenction.repos.collaborators.collaborator? username, repo, name | |
puts "removing #{name} from #{repo}" | |
connenction.repos.collaborators.remove username, repo, name | |
else | |
puts "#{name} is not a collaborator on #{repo}" | |
end | |
end | |
end | |
desc "add_access", "add all users in an org from a repo" | |
def add_access(org, repo) | |
connenction = connect | |
username = connenction.login | |
members = connenction.orgs.members.list org | |
members.map(&:login).each do |name| | |
if !connenction.repos.collaborators.collaborator? username, repo, name | |
puts "adding #{name} to #{repo}" | |
connenction.repos.collaborators.add username, repo, name | |
else | |
puts "#{name} is already a collaborator on #{repo}" | |
end | |
end | |
end | |
private | |
def connect | |
github_id = ask("What is your github login?\n") | |
puts "What is your github password?(hidden)" | |
github_pw = STDIN.noecho(&:gets).strip | |
Github.new login: github_id, password: github_pw | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And now it hides your password! Woohoo