Skip to content

Commit 5aca046

Browse files
lol3909dependabot[bot]mikesplainpasha-codefreshbennesp
authored
fix: oncePer condition only checked when when condition is true (#71) (#208)
* fix: oncePer condition only checked when ` when` condition is true Signed-off-by: Anthony Mikhail <[email protected]> * wip Signed-off-by: Anthony Mikhail <[email protected]> * wip Signed-off-by: Anthony Mikhail <[email protected]> * wip Signed-off-by: Anthony Mikhail <[email protected]> * add debuging Signed-off-by: Anthony Mikhail <[email protected]> * wip Signed-off-by: Anthony Mikhail <[email protected]> * Revert "wip" This reverts commit 6313312. Signed-off-by: Anthony Mikhail <[email protected]> * wip Signed-off-by: Anthony Mikhail <[email protected]> * chore(deps): bump github.com/gregdel/pushover from 1.1.0 to 1.2.1 (#210) Bumps [github.com/gregdel/pushover](https://github.com/gregdel/pushover) from 1.1.0 to 1.2.1. - [Commits](gregdel/pushover@v1.1.0...v1.2.1) --- updated-dependencies: - dependency-name: github.com/gregdel/pushover dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Anthony Mikhail <[email protected]> * GitHub Deployment - Allow Automerge configuration (#193) * Allow AutoMerge configuration Signed-off-by: Mike Splain <[email protected]> * Add docs and test Signed-off-by: Mike Splain <[email protected]> * Fix default and docs Signed-off-by: Mike Splain <[email protected]> --------- Signed-off-by: Mike Splain <[email protected]> Co-authored-by: pasha-codefresh <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * Add GitHub Pull Request comments integration (#211) * Add pull request comment to github service Signed-off-by: bennesp <[email protected]> * Add github pull request comment templater test Signed-off-by: bennesp <[email protected]> * Add github pull request comment docs Signed-off-by: bennesp <[email protected]> --------- Signed-off-by: bennesp <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * chore(deps): bump codecov/codecov-action from 3 to 4 (#216) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v3...v4) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Anthony Mikhail <[email protected]> * revert to v3 (#218) Signed-off-by: Anthony Mikhail <[email protected]> * Add CardsV2 Support to Google Chat (#201) Signed-off-by: Tom Paulus <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * chore(deps): bump expr version and golang as required by expr 1.15 (#221) * bump expr version Signed-off-by: zachaller <[email protected]> * upgrade go expr uses any Signed-off-by: zachaller <[email protected]> * use root go version Signed-off-by: zachaller <[email protected]> * add sum Signed-off-by: zachaller <[email protected]> * change for golang upgrade Signed-off-by: zachaller <[email protected]> --------- Signed-off-by: zachaller <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * wip Signed-off-by: Anthony Mikhail <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * fix duplicate when using self-service (#227) * fix duplicate when using self-service Signed-off-by: May Zhang <[email protected]> * fix duplicate when using self-service Signed-off-by: May Zhang <[email protected]> * fix tests Signed-off-by: May Zhang <[email protected]> * -s Signed-off-by: May Zhang <[email protected]> * add test cases Signed-off-by: May Zhang <[email protected]> * remove not used method Signed-off-by: May Zhang <[email protected]> --------- Signed-off-by: May Zhang <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * Spelling (#220) * spelling: available Signed-off-by: Josh Soref <[email protected]> * spelling: configuration Signed-off-by: Josh Soref <[email protected]> * spelling: emoji Signed-off-by: Josh Soref <[email protected]> * spelling: environment Signed-off-by: Josh Soref <[email protected]> * spelling: github Signed-off-by: Josh Soref <[email protected]> * spelling: notification Signed-off-by: Josh Soref <[email protected]> * spelling: overridden Signed-off-by: Josh Soref <[email protected]> * spelling: successfully Signed-off-by: Josh Soref <[email protected]> * spelling: unmarshal Signed-off-by: Josh Soref <[email protected]> * spelling: variable or Signed-off-by: Josh Soref <[email protected]> * spelling: variables are Signed-off-by: Josh Soref <[email protected]> * spelling: webhook Signed-off-by: Josh Soref <[email protected]> --------- Signed-off-by: Josh Soref <[email protected]> Co-authored-by: pasha-codefresh <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * Update documentation for Slack options (#209) * Clarify option types Signed-off-by: Andreas Lindhé <[email protected]> * Sort alphabetically Signed-off-by: Andreas Lindhé <[email protected]> * Add missing `channels` and `sigingSecret` options Signed-off-by: Andreas Lindhé <[email protected]> * Convert list to Markdown table Signed-off-by: Andreas Lindhé <[email protected]> * Clarify `token` description Signed-off-by: Andreas Lindhé <[email protected]> * Add example column Signed-off-by: Andreas Lindhé <[email protected]> * Populate rest of example fields Signed-off-by: Andreas Lindhé <[email protected]> * Fix typo Co-authored-by: Blake Pettersson <[email protected]> Signed-off-by: Andreas Lindhé <[email protected]> --------- Signed-off-by: Andreas Lindhé <[email protected]> Co-authored-by: Blake Pettersson <[email protected]> Co-authored-by: pasha-codefresh <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> * fix: avoid crashing in gitHubService.Send when repoURL has no / (#219) Signed-off-by: Josh Soref <[email protected]> Co-authored-by: pasha-codefresh <[email protected]> Signed-off-by: Anthony Mikhail <[email protected]> --------- Signed-off-by: Anthony Mikhail <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Mike Splain <[email protected]> Signed-off-by: bennesp <[email protected]> Signed-off-by: Tom Paulus <[email protected]> Signed-off-by: zachaller <[email protected]> Signed-off-by: May Zhang <[email protected]> Signed-off-by: Josh Soref <[email protected]> Signed-off-by: Andreas Lindhé <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Mike Splain <[email protected]> Co-authored-by: pasha-codefresh <[email protected]> Co-authored-by: Benedetto Nespoli <[email protected]> Co-authored-by: Tom Paulus <[email protected]> Co-authored-by: Zach Aller <[email protected]> Co-authored-by: May Zhang <[email protected]> Co-authored-by: Josh Soref <[email protected]> Co-authored-by: Andreas Lindhé <[email protected]> Co-authored-by: Blake Pettersson <[email protected]>
1 parent b3e6b6a commit 5aca046

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

pkg/triggers/service.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,27 @@ func (svc *service) Run(triggerName string, vars map[string]interface{}) ([]Cond
8181
Templates: condition.Send,
8282
Key: fmt.Sprintf("[%d].%s", i, hash(condition.When)),
8383
}
84-
84+
var whenResult bool
8585
if prog, ok := svc.compiledConditions[condition.When]; !ok {
8686
return nil, fmt.Errorf("trigger configuration has changed after initialization")
8787
} else if val, err := expr.Run(prog, vars); err == nil {
8888
boolRes, ok := val.(bool)
8989
conditionResult.Triggered = ok && boolRes
90+
whenResult = conditionResult.Triggered
9091
} else {
9192
log.Errorf("failed to execute when condition: %+v", err)
9293
}
9394

94-
if prog, ok := svc.compiledOncePer[condition.OncePer]; ok {
95-
if val, err := expr.Run(prog, vars); err == nil {
96-
conditionResult.OncePer = fmt.Sprintf("%v", val)
97-
} else {
98-
log.Errorf("failed to execute oncePer condition: %+v", err)
95+
if whenResult {
96+
if prog, ok := svc.compiledOncePer[condition.OncePer]; ok {
97+
if val, err := expr.Run(prog, vars); err == nil {
98+
conditionResult.OncePer = fmt.Sprintf("%v", val)
99+
} else {
100+
log.Errorf("failed to execute oncePer condition: %+v", err)
101+
}
99102
}
103+
} else {
104+
log.Debug("The OncePer condition will not be evaluated since the when condition evaluates to false")
100105
}
101106

102107
res = append(res, conditionResult)

pkg/triggers/service_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ func TestRun_OncePerSet(t *testing.T) {
7272
return
7373
}
7474

75-
conditionKey := fmt.Sprintf("%s:[0].%s", revision, hash("var1 == 'abc'"))
75+
conditionKey := fmt.Sprintf("[0].%s", hash("var1 == 'abc'"))
7676

7777
t.Run("Triggered", func(t *testing.T) {
7878
res, err := svc.Run("my-trigger", map[string]interface{}{"var1": "abc", "revision": "123"})
79-
if assert.NoError(t, err) {
80-
return
79+
if !assert.NoError(t, err) {
80+
t.FailNow()
8181
}
8282
assert.Equal(t, []ConditionResult{{
8383
Key: conditionKey,
@@ -89,16 +89,17 @@ func TestRun_OncePerSet(t *testing.T) {
8989

9090
t.Run("NotTriggered", func(t *testing.T) {
9191
res, err := svc.Run("my-trigger", map[string]interface{}{"var1": "bcd"})
92-
if assert.NoError(t, err) {
93-
return
92+
if !assert.NoError(t, err) {
93+
t.FailNow()
9494
}
9595
assert.Equal(t, []ConditionResult{{
9696
Key: conditionKey,
9797
Triggered: false,
9898
Templates: []string{"my-template"},
99-
OncePer: revision,
99+
OncePer: "",
100100
}}, res)
101101
})
102+
102103
}
103104

104105
func TestRun_OncePer_Evaluate(t *testing.T) {

0 commit comments

Comments
 (0)