Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Small helper script to make managing hubot-scripts org less tedious.
#!/usr/bin/env ruby
## Description:
# Small helper script to make managing hubot-scripts org less tedious.
#
## Requirements:
# gem install octokit
#
## Usage:
# create-hubot-script-repo <username>/<repo> [<org>]
raise 'Please set GITHUB_ACCESS_TOKEN envvar' if ENV['GITHUB_ACCESS_TOKEN'].nil?
require 'tmpdir'
require 'octokit'
username = ARGV[0].split('/')[0]
repo = ARGV[0].split('/')[1]
org = ARGV[1] || 'hubot-scripts'
client = Octokit::Client.new :access_token => ENV['GITHUB_ACCESS_TOKEN']
puts "Creating #{org}/#{repo} repo..."
new_repo = client.create_repo repo, {:organization => org}
puts "Cloning and pushing contents to new repo..."
Dir.mktmpdir {|dir|
`git clone git://github.com/#{username}/#{repo} #{dir}/#{repo}`
`git --work-tree=#{dir}/#{repo} --git-dir=#{dir}/#{repo}/.git remote add scripts-org git@github.com:#{org}/#{repo}.git`
`git --work-tree=#{dir}/#{repo} --git-dir=#{dir}/#{repo}/.git push --all scripts-org`
}
team_name = "collaborators-#{repo}"
puts "Creating #{team_name} team for #{repo} repo..."
new_team = client.create_team org, {:name => team_name, :repo_names => ["#{org}/#{repo}"], :permission => 'admin'}
puts "Retrieving repo collaborators on #{username}/#{repo}..."
collaborators = client.collaborators "#{username}/#{repo}"
puts "Adding members to team #{new_team['name']}..."
collaborators.each do |collab|
client.add_team_member new_team['id'], collab['login']
puts "Added #{collab['login']}."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.