-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathskip.go
More file actions
58 lines (48 loc) · 1.61 KB
/
skip.go
File metadata and controls
58 lines (48 loc) · 1.61 KB
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
// Copyright (c) 2022 Target Brands, Inc. All rights reserved.
//
// Use of this source code is governed by the LICENSE file in this repository.
package step
import (
"strings"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
)
// Skip creates the ruledata from the build and repository
// information and returns true if the data does not match
// the ruleset for the given container.
func Skip(c *pipeline.Container, b *library.Build, r *library.Repo) bool {
// check if the container provided is empty
if c == nil {
return true
}
event := b.GetEvent()
action := b.GetEventAction()
// if the build has an event action, concatenate event and event action for matching
if !strings.EqualFold(action, "") {
event = event + ":" + action
}
// create ruledata from build and repository information
//
// https://pkg.go.dev/github.com/go-vela/types/pipeline#RuleData
ruledata := &pipeline.RuleData{
Branch: b.GetBranch(),
Event: event,
Repo: r.GetFullName(),
Status: b.GetStatus(),
}
// check if the build event is tag
if strings.EqualFold(b.GetEvent(), constants.EventTag) {
// add tag information to ruledata with refs/tags prefix removed
ruledata.Tag = strings.TrimPrefix(b.GetRef(), "refs/tags/")
}
// check if the build event is deployment
if strings.EqualFold(b.GetEvent(), constants.EventDeploy) {
// add deployment target information to ruledata
ruledata.Target = b.GetDeploy()
}
// return the inverse of container execute
//
// https://pkg.go.dev/github.com/go-vela/types/pipeline#Container.Execute
return !c.Execute(ruledata)
}