Class: Github
- Inherits:
-
BASECLI
show all
- Defined in:
- lib/railsonfire/subcommands/github.rb
Constant Summary
collapse
- GITHUB_KEY_URL =
"https://api.github.com/repos/%s/%s/keys?access_token=%s"
- RAILSONFIRE_HOOK_URL =
"http://railsonfire.com/hook/%s"
- GITHUB_HOOK_URL =
"https://api.github.com/repos/%s/%s/hooks?access_token=%s"
Instance Method Summary
collapse
#error, #heroku, #is_git_managed?, #notify, #post_json, #select, #send_signal, #shell, #success, #warning, #write_config_file
Instance Method Details
#add_hook ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/railsonfire/subcommands/github.rb', line 32
def add_hook
return false unless Railsonfire.user || invoke("auth:login")
send_signal :github_add_hook_started
return false unless has_github_token
project = Railsonfire.project
say "Adding Post Receive Hook to Github Repository %s/%s" % [project.owner, project.name]
url = RAILSONFIRE_HOOK_URL % [Railsonfire.config["id"]]
json = {:name => "web", :config => {:url => url}}.to_json
response = HTTParty.post(github_url(GITHUB_HOOK_URL), {:body => json})
if response.code != 201
send_signal :github_add_hook_failed
error "Could not add post-receive Hook Github"
error " Please make sure your Railsonfire account is connected with Github on https://www.railsonfire.com/users/edit and run railsonfire github add_hook"
error " If you do not want to give us access to your projects metadata and set your Post-Receive-Hook by hand please go to the edit page of your project and follow the instructions"
notify("github-hook-upload", "Could not hook to github", {:body => response.body, :code => response.code})
false
else
send_signal :github_add_hook_finished
true
end
end
|
#upload_key ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/railsonfire/subcommands/github.rb', line 9
def upload_key
return false unless Railsonfire.user || invoke("auth:login")
send_signal :github_upload_key_started
return false unless has_github_token
project = Railsonfire.project
say "Adding SSH Key to Github Repository %s/%s" % [project.owner, project.name]
key = project.ssh_public_key.sub("\n", "") + " railsonfire/#{project.owner}/#{project.name}"
json = {:title => "railsonfire", :key => key}.to_json
response = HTTParty.post(github_url(GITHUB_KEY_URL), {:body => json})
if response.code != 201
error "Could not upload ssh key to Github"
error " Please make sure your Railsonfire account is connected with Github on https://www.railsonfire.com/users/edit and run railsonfire github upload_key"
error " If you do not want to give us access to your projects metadata and add the SSH key by hand please go to the edit page of your project and follow the instructions"
notify("github-key-upload", "Could not upload key to github", {:body => response.body, :code => response.code})
send_signal :github_upload_key_failed
false
else
send_signal :github_upload_key_finished
true
end
end
|