-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.go
34 lines (29 loc) · 930 Bytes
/
webhook.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
package webhook
import (
"fmt"
"strings"
"github.com/openshift/origin/pkg/build/api"
)
var (
ErrSecretMismatch = fmt.Errorf("the provided secret does not match")
ErrHookNotEnabled = fmt.Errorf("the specified hook is not enabled")
)
// GitRefMatches determines if the ref from a webhook event matches a build configuration
func GitRefMatches(eventRef, configRef string) bool {
const RefPrefix = "refs/heads/"
eventRef = strings.TrimPrefix(eventRef, RefPrefix)
configRef = strings.TrimPrefix(configRef, RefPrefix)
if configRef == "" {
configRef = "master"
}
return configRef == eventRef
}
// FindTriggerPolicy retrieves the BuildTrigger of a given type from a build configuration
func FindTriggerPolicy(triggerType api.BuildTriggerType, config *api.BuildConfig) (*api.BuildTriggerPolicy, bool) {
for _, p := range config.Spec.Triggers {
if p.Type == triggerType {
return &p, true
}
}
return nil, false
}