Last active
April 26, 2017 03:43
-
-
Save osulyanov/f1ad1de114fb6814e5fcceb5e7855f38 to your computer and use it in GitHub Desktop.
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' | |
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