Skip to content

Instantly share code, notes, and snippets.

@osulyanov
Last active April 26, 2017 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osulyanov/f1ad1de114fb6814e5fcceb5e7855f38 to your computer and use it in GitHub Desktop.
Save osulyanov/f1ad1de114fb6814e5fcceb5e7855f38 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'octokit'
project = ARGV[0]
if project.nil?
puts 'project is empty'
abort
end
client = Octokit::Client.new(:access_token => "")
# Create repo
repo = client.create_repository project, private: true, has_issues: true, has_wiki: true, organization: 'm2hagency'
# Generate ssh key
key_result = `ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/#{project}_deploy`
public_key = `cat ~/.ssh/#{project}_deploy.pub`
# Add public key to repo
client.add_deploy_key repo.full_name, 'Deploy Dev', public_key, read_only: false
# Add teams to repo
# Backend
client.add_team_repository 2342274, repo.full_name, permission: 'push'
# Design
client.add_team_repository 2342273, repo.full_name, permission: 'push'
# Frontend
client.add_team_repository 2151403, repo.full_name, permission: 'push'
# Configure ssh config
ssh_config = "Host #{project}.github.com\r\n HostName github.com\r\n User git\r\n IdentityFile /home/deploy/.ssh/#{project}_deploy\r\n IdentitiesOnly yes\r\n"
`echo "#{ssh_config}" >> ~/.ssh/config`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment