Module: Github::Hooker
- Defined in:
- lib/github-hooker.rb,
lib/github-hooker/cli.rb,
lib/github-hooker/version.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .add_hook(repo, payload = {}) ⇒ Object
- .config ⇒ Object
- .config_filename ⇒ Object
- .delete_hook(repo, hook) ⇒ Object
- .github_api(method, url, options = {}) ⇒ Object
- .hooks(repo) ⇒ Object
Class Method Details
.add_hook(repo, payload = {}) ⇒ Object
15 16 17 18 19 |
# File 'lib/github-hooker.rb', line 15 def self.add_hook(repo, payload={}) url = "https://api.github.com/repos/#{repo}/hooks" payload = payload.reverse_merge(:active => true) github_api(:post, url, :payload => payload.to_json) end |
.config ⇒ Object
26 27 28 |
# File 'lib/github-hooker.rb', line 26 def self.config @config ||= YAML.load_file(File.(config_filename)) end |
.config_filename ⇒ Object
46 47 48 |
# File 'lib/github-hooker.rb', line 46 def self.config_filename "~/.github-hooker.yml" end |
.delete_hook(repo, hook) ⇒ Object
21 22 23 24 |
# File 'lib/github-hooker.rb', line 21 def self.delete_hook(repo, hook) url = "https://api.github.com/repos/#{repo}/hooks/#{hook}" github_api(:delete, url) end |
.github_api(method, url, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/github-hooker.rb', line 30 def self.github_api(method, url, ={}) .reverse_merge!( :method => method, :url => url, :user => config["user"], :password => config["password"] ) response = RestClient::Request.execute() case response.code when 201, 200 JSON.parse(response) when 204, 404, 500 response end end |
.hooks(repo) ⇒ Object
10 11 12 13 |
# File 'lib/github-hooker.rb', line 10 def self.hooks(repo) url = "https://api.github.com/repos/#{repo}/hooks" github_api(:get, url) end |