forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhooks.go
41 lines (33 loc) · 1.14 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 internalversion
import (
"errors"
"net/url"
"k8s.io/client-go/rest"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
)
var ErrTriggerIsNotAWebHook = errors.New("the specified trigger is not a webhook")
type WebHookURLInterface interface {
WebHookURL(name string, trigger *buildapi.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 *buildapi.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
}
}