/
webhooks.go
41 lines (33 loc) · 1.11 KB
/
webhooks.go
1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
package v1
import (
"errors"
"net/url"
"k8s.io/client-go/rest"
buildv1 "github.com/openshift/api/build/v1"
)
var ErrTriggerIsNotAWebHook = errors.New("the specified trigger is not a webhook")
type WebHookURLInterface interface {
WebHookURL(name string, trigger *buildv1.BuildTriggerPolicy) (*url.URL, error)
}
func NewWebhookURLClient(c rest.Interface, ns string) WebHookURLInterface {
return &webhooks{client: c, ns: ns}
}
type webhooks struct {
client rest.Interface
ns string
}
func (c *webhooks) WebHookURL(name string, trigger *buildv1.BuildTriggerPolicy) (*url.URL, error) {
hooks := c.client.Get().Namespace(c.ns).Resource("buildConfigs").Name(name).SubResource("webhooks")
switch {
case trigger.GenericWebHook != nil:
return hooks.Suffix("<secret>", "generic").URL(), nil
case trigger.GitHubWebHook != nil:
return hooks.Suffix("<secret>", "github").URL(), nil
case trigger.GitLabWebHook != nil:
return hooks.Suffix("<secret>", "gitlab").URL(), nil
case trigger.BitbucketWebHook != nil:
return hooks.Suffix("<secret>", "bitbucket").URL(), nil
default:
return nil, ErrTriggerIsNotAWebHook
}
}