Skip to content

Commit 368d436

Browse files
authored
Fix actions workflow branches match bug (#22724)
caused by #22680 `pushPayload.Ref` and `prPayload.PullRequest.Base.Ref` have the format like `refs/heads/<branch_name>`, so we need to trim the prefix before comparing.
1 parent 98770d3 commit 368d436

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

modules/actions/workflows.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
7575
if evt.Name != triggedEvent.Event() {
7676
continue
7777
}
78-
7978
if detectMatched(commit, triggedEvent, payload, evt) {
8079
workflows[entry.Name()] = content
8180
}
@@ -105,8 +104,9 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
105104
for cond, vals := range evt.Acts {
106105
switch cond {
107106
case "branches", "tags":
107+
refShortName := git.RefName(pushPayload.Ref).ShortName()
108108
for _, val := range vals {
109-
if glob.MustCompile(val, '/').Match(pushPayload.Ref) {
109+
if glob.MustCompile(val, '/').Match(refShortName) {
110110
matchTimes++
111111
break
112112
}
@@ -160,8 +160,9 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
160160
}
161161
}
162162
case "branches":
163+
refShortName := git.RefName(prPayload.PullRequest.Base.Ref).ShortName()
163164
for _, val := range vals {
164-
if glob.MustCompile(val, '/').Match(prPayload.PullRequest.Base.Ref) {
165+
if glob.MustCompile(val, '/').Match(refShortName) {
165166
matchTimes++
166167
break
167168
}

0 commit comments

Comments
 (0)