-
Notifications
You must be signed in to change notification settings - Fork 13
/
webhook.go
73 lines (63 loc) · 1.84 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: Apache-2.0
package types
import (
"strings"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
)
var (
skipDirectiveMsg = "skip ci directive found in commit title/message"
)
// PullRequest defines the data pulled from PRs while
// processing a webhook.
//
// Deprecated: use PullRequest from github.com/go-vela/server/internal instead.
type PullRequest struct {
Comment string
Number int
IsFromFork bool
Labels []string
}
// Webhook defines a struct that is used to return
// the required data when processing webhook event
// a for a source provider event.
//
// Deprecated: use Webhook from github.com/go-vela/server/internal instead.
type Webhook struct {
Hook *library.Hook
Repo *library.Repo
Build *library.Build
PullRequest PullRequest
Deployment *library.Deployment
}
// ShouldSkip uses the build information
// associated with the given hook to determine
// whether the hook should be skipped.
func (w *Webhook) ShouldSkip() (bool, string) {
// push or tag event
if strings.EqualFold(constants.EventPush, w.Build.GetEvent()) || strings.EqualFold(constants.EventTag, w.Build.GetEvent()) {
// check for skip ci directive in message or title
if hasSkipDirective(w.Build.GetMessage()) ||
hasSkipDirective(w.Build.GetTitle()) {
return true, skipDirectiveMsg
}
}
return false, ""
}
// hasSkipDirective is a small helper function
// to check a string for a number of patterns
// that signal to vela that the hook should
// be skipped from processing.
func hasSkipDirective(s string) bool {
sl := strings.ToLower(s)
switch {
case strings.Contains(sl, "[skip ci]"),
strings.Contains(sl, "[ci skip]"),
strings.Contains(sl, "[skip vela]"),
strings.Contains(sl, "[vela skip]"),
strings.Contains(sl, "***no_ci***"):
return true
default:
return false
}
}