Skip to content

Commit 6b8bd58

Browse files
Shivam Mukhadechmouel
authored andcommitted
Handle ref/heads/* for both base branch and target branch
if base branch has refs/heads but target annotation only has branch name, it use to fails for eg. target annotation is main and for push rerequested action the base branch would be refs/heads/main not this checks both ways if any of base branch or taget branch has refs/heads and then matches. Signed-off-by: Shivam Mukhade <[email protected]>
1 parent 21ce6b4 commit 6b8bd58

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

pkg/matcher/annotation_matcher.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ func branchMatch(prunBranch, baseBranch string) bool {
4040
}
4141
}
4242

43+
// if base is refs/heads/.. and target is without ref (for push rerequested action)
44+
if strings.HasPrefix(baseBranch, "refs/heads") && !strings.Contains(prunBranch, "/") {
45+
prunRef := "refs/heads/" + prunBranch
46+
g := glob.MustCompile(prunRef)
47+
if g.Match(baseBranch) {
48+
return true
49+
}
50+
}
51+
4352
// match globs like refs/tags/0.*
4453
g := glob.MustCompile(prunBranch)
4554
return g.Match(baseBranch)

pkg/matcher/annotation_matcher_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,14 @@ func TestMatchPipelinerunByAnnotation(t *testing.T) {
911911
},
912912
wantErr: true,
913913
},
914+
{
915+
name: "ref-heads-main-push-rerequested-case",
916+
args: args{
917+
pruns: []*tektonv1beta1.PipelineRun{pipelineGood},
918+
runevent: info.Event{TriggerTarget: "pull_request", EventType: "pull_request", BaseBranch: "refs/heads/main"},
919+
},
920+
wantErr: false,
921+
},
914922
}
915923

916924
for _, tt := range tests {

0 commit comments

Comments
 (0)