mirror of
https://github.com/go-gitea/gitea.git
synced 2025-10-06 16:56:29 +00:00
[Fix] Trigger 'unlabeled' event when label is Deleted from PR (#34316)
This pull request updates the handling of issue label events in workflows to distinguish between label additions and deletions, introduces corresponding test cases, and extends the `IssuePayload` structure to support this functionality. ### Enhancements to issue label event handling: * Updated `matchIssuesEvent` in `modules/actions/workflows.go` to differentiate between "labeled" and "unlabeled" events based on whether labels were added or removed. * Added a new field, `RemovedLabels`, to the `IssuePayload` struct in `modules/structs/hook.go` to track labels that were removed during an issue event. ### Testing improvements: * Added `TestMatchIssuesEvent` in `modules/actions/workflows_test.go` to cover scenarios such as label addition, label deletion, and label clearing, ensuring the correct event type is triggered. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -377,20 +377,28 @@ func matchIssuesEvent(issuePayload *api.IssuePayload, evt *jobparser.Event) bool
|
||||
// Actions with the same name:
|
||||
// opened, edited, closed, reopened, assigned, unassigned, milestoned, demilestoned
|
||||
// Actions need to be converted:
|
||||
// label_updated -> labeled
|
||||
// label_updated -> labeled (when adding) or unlabeled (when removing)
|
||||
// label_cleared -> unlabeled
|
||||
// Unsupported activity types:
|
||||
// deleted, transferred, pinned, unpinned, locked, unlocked
|
||||
|
||||
action := issuePayload.Action
|
||||
switch action {
|
||||
actions := []string{}
|
||||
switch issuePayload.Action {
|
||||
case api.HookIssueLabelUpdated:
|
||||
action = "labeled"
|
||||
if len(issuePayload.Changes.AddedLabels) > 0 {
|
||||
actions = append(actions, "labeled")
|
||||
}
|
||||
if len(issuePayload.Changes.RemovedLabels) > 0 {
|
||||
actions = append(actions, "unlabeled")
|
||||
}
|
||||
case api.HookIssueLabelCleared:
|
||||
action = "unlabeled"
|
||||
actions = append(actions, "unlabeled")
|
||||
default:
|
||||
actions = append(actions, string(issuePayload.Action))
|
||||
}
|
||||
|
||||
for _, val := range vals {
|
||||
if glob.MustCompile(val, '/').Match(string(action)) {
|
||||
if slices.ContainsFunc(actions, glob.MustCompile(val, '/').Match) {
|
||||
matchTimes++
|
||||
break
|
||||
}
|
||||
|
Reference in New Issue
Block a user