class Nucleon::Project::Github
Public Class Methods
expand_url(path, editable = false)
click to toggle source
# File lib/nucleon/project/github.rb 82 def self.expand_url(path, editable = false) 83 if path =~ /^[a-zA-Z0-9_\-\/]+(.git)?$/ 84 path = path.gsub('.git', '') 85 86 if editable 87 protocol = 'git@' 88 separator = ':' 89 else 90 protocol = 'https://' 91 separator = '/' 92 end 93 url = "#{protocol}github.com#{separator}" + path + '.git' 94 else 95 url = path 96 end 97 url 98 end
Public Instance Methods
client()
click to toggle source
# File lib/nucleon/project/github.rb 37 def client 38 set_connection unless @client 39 @client 40 end
init_auth()
click to toggle source
Calls superclass method
# File lib/nucleon/project/github.rb 45 def init_auth 46 super do 47 external_ip = get(:external_ip, Nucleon.ip_address) 48 internal_ip = get(:internal_ip, nil) 49 50 if internal_ip && internal_ip.to_s != external_ip 51 location = "#{external_ip}[#{internal_ip}]" 52 else 53 location = external_ip 54 end 55 56 key_id = ENV['USER'] + '@' + location 57 ssh_key = public_key_str 58 59 if private_key && ssh_key 60 deploy_keys = client.deploy_keys(plugin_name) 61 github_id = nil 62 keys_match = true 63 64 deploy_keys.each do |key_resource| 65 if key_resource.title == key_id 66 github_id = key_resource.id 67 keys_match = false if key_resource.key != ssh_key 68 break 69 end 70 end 71 72 client.remove_deploy_key(myself.plugin_name, github_id) if github_id && ! keys_match 73 client.add_deploy_key(myself.plugin_name, key_id, ssh_key) 74 verify_key 75 end 76 end 77 end
normalize(reload)
click to toggle source
Calls superclass method
Nucleon::Project::Git#normalize
# File lib/nucleon/project/github.rb 13 def normalize(reload) 14 if reference = delete(:reference, nil) 15 myself.plugin_name = normalize_reference(reference) 16 else 17 if url = get(:url, nil) 18 myself.plugin_name = url 19 set(:url, myself.class.expand_url(url, get(:ssh, false))) 20 end 21 end 22 super 23 end
set_connection()
click to toggle source
# File lib/nucleon/project/github.rb 27 def set_connection 28 require 'octokit' 29 30 @client = Octokit::Client.new :netrc => true 31 @client.login 32 end
Protected Instance Methods
normalize_reference(reference)
click to toggle source
# File lib/nucleon/project/github.rb 110 def normalize_reference(reference) 111 reference.sub(/^(git\@|(https?|git)\:\/\/)[^\/\:]+(\/|\:)?/, '').sub(/\.git$/, '') 112 end
verify_key()
click to toggle source
# File lib/nucleon/project/github.rb 102 def verify_key 103 Util::SSH.init_session('github.com', 'git', 22, private_key) 104 Util::SSH.close('github.com', 'git') 105 end