diff --git a/pipeline/container.go b/pipeline/container.go index 3d427cb0..8e2e55f1 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -152,32 +152,21 @@ func (c *Container) Execute(r *RuleData) (bool, error) { if c == nil { return false, nil } - // skip evaluating path in ruleset - // - // the compiler is the component responsible for - // choosing whether a container will run based - // off the files changed for a build + + // Skip evaluating path, comment, and label in ruleset, + // as the worker lacks necessary rule data. // - // the worker doesn't have any record of - // what files changed for a build so we - // should "skip" evaluating what the - // user provided for the path element + // The compiler determines whether a container will run based on + // these rules. c.Ruleset.If.Path = []string{} c.Ruleset.Unless.Path = []string{} - // skip evaluating comment in ruleset - // - // the compiler is the component responsible for - // choosing whether a container will run based - // off the PR comment matching the pipeline comment - // - // the worker doesn't have any record of - // the PR comment so we - // should "skip" evaluating what the - // user provided for the PR comment c.Ruleset.If.Comment = []string{} c.Ruleset.Unless.Comment = []string{} + c.Ruleset.If.Label = []string{} + c.Ruleset.Unless.Label = []string{} + // check if the build is in a running state if strings.EqualFold(r.Status, constants.StatusRunning) { // treat the ruleset status as success diff --git a/pipeline/container_test.go b/pipeline/container_test.go index 3f5e3a45..a7ae573c 100644 --- a/pipeline/container_test.go +++ b/pipeline/container_test.go @@ -749,6 +749,92 @@ func TestPipeline_Container_Execute(t *testing.T) { }, want: true, }, + { // pull request labeled success container with build success + container: &Container{ + Name: "pull-request-labeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + If: Rules{ + Branch: []string{"fix/1234"}, + Event: []string{constants.EventPull + constants.ActionLabeled}, + Label: []string{"enhancement", "documentation"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:labeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request unlabeled success container with build success + container: &Container{ + Name: "pull-request-unlabeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + If: Rules{ + Event: []string{constants.EventPull + constants.ActionUnlabeled}, + Label: []string{"enhancement"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:unlabeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request labeled unless ruleset, success container with build success + container: &Container{ + Name: "pull-request-labeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + Unless: Rules{ + Branch: []string{"fix/1234"}, + Event: []string{constants.EventPull + constants.ActionLabeled}, + Label: []string{"enhancement", "documentation"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:labeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, + { // pull request unlabeled unless ruleset, success container with build success + container: &Container{ + Name: "pull-request-unlabeled", + Image: "alpine:latest", + Commands: []string{"echo \"Hey Vela\""}, + Ruleset: Ruleset{ + Unless: Rules{ + Event: []string{constants.EventPull + constants.ActionUnlabeled}, + Label: []string{"enhancement"}, + }, + Operator: "and", + }, + }, + ruleData: &RuleData{ + Branch: "fix/1234", + Event: "pull_request:unlabeled", + Repo: "foo/bar", + Status: "success", + }, + want: true, + }, } // run tests