Repository: go-gitea/gitea
File: modules/actions/workflows.go (Go)

Code before:
	for cond, vals := range evt.Acts() {
		switch cond {
		case "types":
			// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues
			// Actions with the same name:
			// opened, edited, closed, reopened, assigned, unassigned, milestoned, demilestoned
			// Actions need to be converted:
			// label_updated -> labeled (when adding) or unlabeled (when removing)
			// label_cleared -> unlabeled
			// Unsupported activity types:
			// deleted, transferred, pinned, unpinned, locked, unlocked

			actions := []string{}
			switch issuePayload.Action {
			case api.HookIssueLabelUpdated:
				// Check if both labels were added and removed to determine events to fire
				if len(issuePayload.Issue.Labels) > 0 && len(issuePayload.RemovedLabels) > 0 {
					// Both labeled and unlabeled events should be triggered
					actions = append(actions, "labeled", "unlabeled")
				} else if len(issuePayload.RemovedLabels) > 0 {
					// Only labels were removed
					actions = append(actions, "unlabeled")
				} else {
					// Only labels were added
					actions = append(actions, "labeled")
				}
			case api.HookIssueLabelCleared:
				actions = append(actions, "unlabeled")
			default:
				actions = append(actions, string(issuePayload.Action))
			}

			for _, val := range vals {
				for _, action := range actions {
					if glob.MustCompile(val, '/').Match(action) {
						matchTimes++
						break
					}
				}
				// Once a match is found for this value, we can move to the next one
				if matchTimes > 0 {
					break
				}
			}
		default:
			log.Warn("issue event unsupported condition %q", cond)
		}
	}
	return matchTimes == len(evt.Acts())
}


Review comment (suggestion):
```suggestion
				if len(issuePayload.Issue.Labels) > 0 {
					actions = append(actions, "labeled")
				}
				if len(issuePayload.RemovedLabels) > 0 {
					actions = append(actions, "unlabeled")
				}
```

Code after:
	// if both branch and tag filter are defined in the workflow only one needs to match
	if hasBranchFilter && hasTagFilter {
		matchTimes++
	}
	return matchTimes == len(evt.Acts())
}

func matchIssuesEvent(issuePayload *api.IssuePayload, evt *jobparser.Event) bool {
	// with no special filter parameters
	if len(evt.Acts()) == 0 {
		return true
	}

	matchTimes := 0
	// all acts conditions should be satisfied
	for cond, vals := range evt.Acts() {
		switch cond {
		case "types":
			// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issues
			// Actions with the same name:
			// opened, edited, closed, reopened, assigned, unassigned, milestoned, demilestoned
			// Actions need to be converted:
			// label_updated -> labeled (when adding) or unlabeled (when removing)
			// label_cleared -> unlabeled
			// Unsupported activity types:
			// deleted, transferred, pinned, unpinned, locked, unlocked

			actions := []string{}
			switch issuePayload.Action {
			case api.HookIssueLabelUpdated:
				if len(issuePayload.Changes.AddedLabels) > 0 {
					actions = append(actions, "labeled")
				}
				if len(issuePayload.Changes.RemovedLabels) > 0 {
					actions = append(actions, "unlabeled")
				}
			case api.HookIssueLabelCleared:
				actions = append(actions, "unlabeled")
			default:
				actions = append(actions, string(issuePayload.Action))
			}

			for _, val := range vals {
				if slices.ContainsFunc(actions, glob.MustCompile(val, '/').Match) {
					matchTimes++
					break
				}
			}
		default:
			log.Warn("issue event unsupported condition %q", cond)
		}