Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Small helper script to make managing hubot-scripts org less tedious.

View create-hubot-script-repo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!/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.