Skip to content

Commit 73ef4af

Browse files
committed
feat: Exclude tag push events from skip-pr-commits logic
When the skip-pr-commits setting is enabled, the system skips push events for commits that are part of an open pull request to avoid duplicate pipeline runs. However, this should not apply to tag push events, as tags represent important release points that should always trigger pipelines regardless of PR status. Changes: - Detect tag push events by checking if ref starts with "refs/tags/" - Exclude tag push events from skip logic even when skip-pr-commits setting is enabled - Add test case verifying tag push events are not skipped - Add test case verifying regular push events are still skipped when commit is part of a PR This ensures that tagging a commit (e.g., for releases) always triggers the associated pipeline runs, while still avoiding duplicate runs for regular branch commits that are part of pull requests. Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 96b7476 commit 73ef4af

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

docs/content/docs/install/settings.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ There are a few things you can configure through the ConfigMap
164164

165165
Default: `true`
166166

167+
**Note:** This setting does not apply to git tag push events. Tag push events will always trigger
168+
pipeline runs regardless of whether the tagged commit is part of an open pull request.
169+
167170
{{< support_matrix github_app="true" github_webhook="true" gitea="false" gitlab="false" bitbucket_cloud="false" bitbucket_datacenter="false" >}}
168171

169172
### Global Cancel In Progress Settings

pkg/provider/github/parse_payload.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,10 @@ func (v *Provider) processEvent(ctx context.Context, event *info.Event, eventInt
346346
v.Logger.Warnf("Error getting pull requests associated with the commit in this push event: %v", err)
347347
}
348348

349-
// Only check if the flag is enabled and there are pull requests associated with this commit.
350-
if v.pacInfo.SkipPushEventForPRCommits && len(prs) > 0 {
349+
isGitTagEvent := strings.HasPrefix(gitEvent.GetRef(), "refs/tags/")
350+
351+
// Only check if the flag is enabled, and there are pull requests associated with this commit, and it's not a tag push event.
352+
if v.pacInfo.SkipPushEventForPRCommits && len(prs) > 0 && !isGitTagEvent {
351353
isPartOfPR, prNumber := v.isCommitPartOfPullRequest(sha, org, repoName, prs)
352354

353355
// If the commit is part of a PR, skip processing the push event

pkg/provider/github/parse_payload_test.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,18 @@ func TestParsePayLoad(t *testing.T) {
356356
samplePRNoRepo.Repo = nil
357357
samplePrEventClosed := samplePRevent
358358
samplePrEventClosed.Action = github.Ptr("closed")
359+
360+
sampleGhPRs := []*github.PullRequest{
361+
{
362+
Number: github.Ptr(41),
363+
State: github.Ptr("closed"),
364+
},
365+
{
366+
Number: github.Ptr(42),
367+
State: github.Ptr("open"),
368+
},
369+
}
370+
359371
tests := []struct {
360372
name string
361373
wantErrString string
@@ -371,6 +383,7 @@ func TestParsePayLoad(t *testing.T) {
371383
wantedBranchName string
372384
wantedTagName string
373385
isCancelPipelineRunEnabled bool
386+
skipPushEventForPRCommits bool
374387
}{
375388
{
376389
name: "bad/unknown event",
@@ -897,6 +910,41 @@ func TestParsePayLoad(t *testing.T) {
897910
wantedBranchName: "main",
898911
wantErrString: "provided SHA samplePRshanew is not the HEAD commit of the branch main",
899912
},
913+
{
914+
name: "good/skip push event for skip-pr-commits setting",
915+
eventType: "push",
916+
triggerTarget: "push",
917+
githubClient: true,
918+
payloadEventStruct: github.PushEvent{
919+
Ref: github.Ptr("refs/heads/main"),
920+
Repo: &github.PushEventRepository{
921+
Owner: &github.User{Login: github.Ptr("owner")},
922+
Name: github.Ptr("pushRepo"),
923+
},
924+
HeadCommit: &github.HeadCommit{ID: github.Ptr("SHAPush")},
925+
},
926+
shaRet: "SHAPush",
927+
skipPushEventForPRCommits: true,
928+
muxReplies: map[string]any{"/repos/owner/pushRepo/commits/SHAPush/pulls": sampleGhPRs},
929+
wantErrString: "commit SHAPush is part of pull request #42, skipping push event",
930+
},
931+
{
932+
name: "good/skip tag push event for skip-pr-commits setting",
933+
eventType: "push",
934+
triggerTarget: "push",
935+
githubClient: true,
936+
payloadEventStruct: github.PushEvent{
937+
Ref: github.Ptr("refs/tags/v1.0.0"),
938+
Repo: &github.PushEventRepository{
939+
Owner: &github.User{Login: github.Ptr("owner")},
940+
Name: github.Ptr("pushRepo"),
941+
},
942+
HeadCommit: &github.HeadCommit{ID: github.Ptr("SHAPush")},
943+
},
944+
shaRet: "SHAPush",
945+
skipPushEventForPRCommits: true,
946+
muxReplies: map[string]any{"/repos/owner/pushRepo/commits/SHAPush/pulls": sampleGhPRs},
947+
},
900948
}
901949
for _, tt := range tests {
902950
t.Run(tt.name, func(t *testing.T) {
@@ -969,7 +1017,7 @@ func TestParsePayLoad(t *testing.T) {
9691017
ghClient: ghClient,
9701018
Logger: logger,
9711019
pacInfo: &info.PacOpts{
972-
Settings: settings.Settings{},
1020+
Settings: settings.Settings{SkipPushEventForPRCommits: tt.skipPushEventForPRCommits},
9731021
},
9741022
}
9751023
request := &http.Request{Header: map[string][]string{}}

0 commit comments

Comments
 (0)