Module: Ghrepo
Constant Summary collapse
- VERSION =
"0.0.6"
Instance Method Summary collapse
- #add_collaborator(collab, credentials, repo_name) ⇒ Object
- #add_html(repo_name, git_url) ⇒ Object
- #add_rails(repo_name, git_url) ⇒ Object
- #find_collabs(args, credentials, repo_name) ⇒ Object
- #include_rails(args, repo_name, git_url) ⇒ Object
- #prompt_password ⇒ Object
- #prompt_username ⇒ Object
- #push_rails ⇒ Object
- #set_credentials(args) ⇒ Object
- #set_password ⇒ Object
- #set_url(args) ⇒ Object
- #set_username ⇒ Object
- #start(args) ⇒ Object
Instance Method Details
#add_collaborator(collab, credentials, repo_name) ⇒ Object
111 112 113 114 |
# File 'lib/ghrepo.rb', line 111 def add_collaborator(collab, credentials, repo_name) `curl -i -u "#{credentials[:username]}:#{credentials[:password]}" -X PUT -d '' https://api.github.com/repos/"#{credentials[:username]}"/"#{repo_name}"/collaborators/"#{collab}"` puts "succesfully added collaborator ", collab end |
#add_html(repo_name, git_url) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ghrepo.rb', line 75 def add_html(repo_name, git_url) app_dir = "./#{repo_name}" latest_ghrepo_gem = (Dir.entries(ENV["GEM_HOME"] + "/gems")).select {|l| l.start_with?('ghrep')}.last html5_file = ENV["GEM_HOME"] += "/gems/" + latest_ghrepo_gem + "/lib/html5-boilerplate.html" Dir.chdir(app_dir) `cp #{html5_file} ./index.html` `git add .` `git commit -m "boilerplate html"` `git push -u origin master` end |
#add_rails(repo_name, git_url) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/ghrepo.rb', line 91 def add_rails(repo_name, git_url) puts "\nbuilding your rails app...." `rails new "#{repo_name}"` Dir.chdir(repo_name) `git init` `git remote add origin "#{git_url}"` end |
#find_collabs(args, credentials, repo_name) ⇒ Object
105 106 107 108 109 |
# File 'lib/ghrepo.rb', line 105 def find_collabs(args, credentials, repo_name) starts_with_c = args.drop_while {|arg| arg.start_with?('-c')} collabs_list = starts_with_c.reject {|flags| flags.start_with?('-')} collabs_list.each {|collab| add_collaborator(collab, credentials, repo_name)} end |
#include_rails(args, repo_name, git_url) ⇒ Object
86 87 88 89 |
# File 'lib/ghrepo.rb', line 86 def include_rails(args, repo_name, git_url) add_rails(repo_name, git_url) push_rails end |
#prompt_password ⇒ Object
49 50 51 52 |
# File 'lib/ghrepo.rb', line 49 def prompt_password print "password > " password = STDIN.noecho(&:gets).chomp end |
#prompt_username ⇒ Object
62 63 64 65 |
# File 'lib/ghrepo.rb', line 62 def prompt_username print "github username > " username = STDIN.gets.chomp end |
#push_rails ⇒ Object
99 100 101 102 103 |
# File 'lib/ghrepo.rb', line 99 def push_rails `git add .` `git commit -m "boilerplate rails"` `git push -u origin master` end |
#set_credentials(args) ⇒ Object
71 72 73 |
# File 'lib/ghrepo.rb', line 71 def set_credentials(args) {url: set_url(args), username: set_username, password: set_password} end |
#set_password ⇒ Object
67 68 69 |
# File 'lib/ghrepo.rb', line 67 def set_password ENV['GHREPO_KEY'] || prompt_password end |
#set_url(args) ⇒ Object
54 55 56 |
# File 'lib/ghrepo.rb', line 54 def set_url(args) ENV['GHREPO_SSH'] || args.include?('-ssh') ? 'ssh_url' : 'clone_url' end |
#set_username ⇒ Object
58 59 60 |
# File 'lib/ghrepo.rb', line 58 def set_username ENV['GHREPO_USERNAME'] || prompt_username end |
#start(args) ⇒ Object
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 45 46 47 |
# File 'lib/ghrepo.rb', line 11 def start(args) if args.any? repo_name = args.pop credentials = set_credentials(args) response = `curl -u "#{credentials[:username]}:#{credentials[:password]}" https://api.github.com/user/repos -d '{"name":"'#{repo_name}'"}'` git_url = JSON.parse(response)[credentials[:url]] args.include?('-rails') ? include_rails(args, repo_name, git_url) : `git clone "#{git_url}"` add_html(repo_name, git_url) if args.include?('-html') find_collabs(args, credentials, repo_name) if args.include?('-c') else puts "RTFM dummy!" puts <<-eos ░░░░░░░░░▄░░░░░░░░░░░░░░▄░░░░ ░░░░░░░░▌▒█░░░░░░░░░░░▄▀▒▌░░░ ░░░░░░░░▌▒▒█░░░░░░░░▄▀▒▒▒▐░░░ ░░░░░░░▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐░░░ ░░░░░▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐░░░ ░░░▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌░░░ ░░▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌░░ ░░▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐░░ ░▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌░ ░▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌░ ▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐░ ▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌ ▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐░ ░▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌░ ░▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐░░ ░░▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌░░ ░░░░▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀░░░ ░░░░░░▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀░░░░░ ░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▀▀░░░░░░░░ eos puts "such moron very dumb" end end |