Skip to content

Instantly share code, notes, and snippets.

@patcon
Last active March 9, 2017 10:43
Show Gist options
  • Save patcon/7223992 to your computer and use it in GitHub Desktop.
Save patcon/7223992 to your computer and use it in GitHub Desktop.
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 [email protected]:#{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
@sufie
Copy link

sufie commented May 26, 2016

I am in the process of planning of transfer of a subset of repo' s from one organization to another. Is your script the equivalent of a transfer or is it effectively copying the repo into a new one.

Transfer is important to me as it promises that all urls will work and all data will transfer with the exception of issue ownership.

I would appreciate your advise and feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment