Module: Hooker::Hooks
Instance Method Summary collapse
- #ensure_exists(repo, hook_url, events, opts) ⇒ Object
- #format_string(hook, longest_url_length) ⇒ Object
- #list(repo, options = {}) ⇒ Object
Instance Method Details
#ensure_exists(repo, hook_url, events, opts) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hooker/hooks.rb', line 9 def ensure_exists(repo, hook_url, events, opts) opts = {} hooks = Hooker.client.hooks(repo, opts).select { |h| h.name == 'web' } hook = hooks.select { |h| h.config.url == hook_url }.first if hook res = Hooker.client.edit_hook(repo, hook.id, 'web', { url: hook_url, content_type: 'json' }, { events: events, active: true }) "updated: #{res.url}" else res = Hooker.client.create_hook(repo, 'web', { url: hook_url, content_type: 'json' }, { events: events, active: true }) "created: #{res.url}" end end |
#format_string(hook, longest_url_length) ⇒ Object
36 37 38 39 |
# File 'lib/hooker/hooks.rb', line 36 def format_string(hook, longest_url_length) url_format = "%-#{longest_url_length}s" "#{'%-10d' % hook.id} | #{url_format % hook.config[:url]} | #{hook.events.join(',')}" end |
#list(repo, options = {}) ⇒ Object
4 5 6 7 |
# File 'lib/hooker/hooks.rb', line 4 def list(repo, = {}) opts = {} Hooker.client.hooks(repo, opts).select { |h| h.name == 'web' } end |