forked from argoproj/argo-events
/
hook_util.go
52 lines (41 loc) · 981 Bytes
/
hook_util.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
42
43
44
45
46
47
48
49
50
51
52
package github
import (
gh "github.com/google/go-github/github"
)
// sliceEqual returns true if the two provided string slices are equal.
func sliceEqual(first []string, second []string) bool {
if len(first) != len(second) {
return false
}
if first == nil && second == nil {
return true
}
if first == nil || second == nil {
return false
}
for index := range first {
if first[index] != second[index] {
return false
}
}
return true
}
// compareHook returns true if the hook matches the url and event.
func compareHook(hook *gh.Hook, url string, event []string) bool {
if hook == nil {
return false
}
if hook.Config["url"] != url {
return false
}
return sliceEqual(hook.Events, event)
}
// getHook returns the hook that matches the url and event, or nil if not found.
func getHook(hooks []*gh.Hook, url string, event []string) *gh.Hook {
for _, hook := range hooks {
if compareHook(hook, url, event) {
return hook
}
}
return nil
}