Created
April 22, 2012 00:30
-
-
Save abe4tawa8/2440516 to your computer and use it in GitHub Desktop.
git-dojo setup script
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
#!/usr/bin/env ruby | |
require 'octokit' | |
require 'csv' | |
user_login = 'username' | |
user_password = 'password' | |
organization = 'git-dojo' | |
csv_file = ARGV.first || abort("Usage: #{$0} <csv-file>") | |
github_teams = {} | |
CSV.foreach(csv_file) do |row| | |
user = row[0] | |
team = row[1] | |
github_teams[team] ||= [] | |
github_teams[team] << user | |
end | |
client = Octokit::Client.new(:login => user_login, :password => user_password) | |
org_teams = client.org_teams(organization) | |
org_repos = client.org_repositories(organization) | |
github_teams.each do |team_name, members| | |
repo = org_repos.select {|r| r['name'] == team_name }.first || | |
client.create_repo(team_name, :organization => organization) | |
team = org_teams.select {|t| t['name'] == team_name }.first || | |
client.create_team(organization, nil, | |
:name => team_name, | |
:repo_names => ["#{repo.owner.login}/#{repo.name}"], | |
:permission => 'push') | |
new_members = members - client.team_members(team.id).collect {|m| m.login } | |
new_members.each do |member| | |
client.add_team_member(team.id, member) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment