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
|