summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorEarl Warren <contact@earl-warren.org>2024-11-03 22:55:06 +0100
committerEarl Warren <contact@earl-warren.org>2024-11-04 10:41:11 +0100
commit58e3c1fbdba0832dc8cbe3f9adca3674f33f70c7 (patch)
tree9b1bd141cb5c513fd3250436fe24319654abdbfa /services
parentMerge pull request '[PORT] Fix a number of typescript issues (gitea#32308)' (... (diff)
downloadforgejo-58e3c1fbdba0832dc8cbe3f9adca3674f33f70c7.tar.xz
forgejo-58e3c1fbdba0832dc8cbe3f9adca3674f33f70c7.zip
fix: add label to issues and PR labeled/unlabeled events
When a workflow has on: pull_request: types: - labeled - unlabeled The payload misses the label field describing the added or removed label. The unlabeled event type was also incorrectly mapped to the labeled event type.
Diffstat (limited to 'services')
-rw-r--r--services/actions/notifier.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/services/actions/notifier.go b/services/actions/notifier.go
index e97afad990..2dd81158a7 100644
--- a/services/actions/notifier.go
+++ b/services/actions/notifier.go
@@ -168,7 +168,7 @@ func (n *actionsNotifier) IssueChangeAssignee(ctx context.Context, doer *user_mo
hookEvent = webhook_module.HookEventPullRequestAssign
}
- notifyIssueChange(ctx, doer, issue, hookEvent, action)
+ notifyIssueChange(ctx, doer, issue, hookEvent, action, nil)
}
// IssueChangeMilestone notifies assignee to notifiers
@@ -187,11 +187,11 @@ func (n *actionsNotifier) IssueChangeMilestone(ctx context.Context, doer *user_m
hookEvent = webhook_module.HookEventPullRequestMilestone
}
- notifyIssueChange(ctx, doer, issue, hookEvent, action)
+ notifyIssueChange(ctx, doer, issue, hookEvent, action, nil)
}
func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
- _, _ []*issues_model.Label,
+ addedLabels, removedLabels []*issues_model.Label,
) {
ctx = withMethod(ctx, "IssueChangeLabels")
@@ -200,10 +200,15 @@ func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_mode
hookEvent = webhook_module.HookEventPullRequestLabel
}
- notifyIssueChange(ctx, doer, issue, hookEvent, api.HookIssueLabelUpdated)
+ for _, added := range addedLabels {
+ notifyIssueChange(ctx, doer, issue, hookEvent, api.HookIssueLabelUpdated, added)
+ }
+ for _, removed := range removedLabels {
+ notifyIssueChange(ctx, doer, issue, hookEvent, api.HookIssueLabelCleared, removed)
+ }
}
-func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, event webhook_module.HookEventType, action api.HookIssueAction) {
+func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, event webhook_module.HookEventType, action api.HookIssueAction, label *issues_model.Label) {
var err error
if err = issue.LoadRepo(ctx); err != nil {
log.Error("LoadRepo: %v", err)
@@ -215,6 +220,11 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
return
}
+ var apiLabel *api.Label
+ if action == api.HookIssueLabelUpdated || action == api.HookIssueLabelCleared {
+ apiLabel = convert.ToLabel(label, issue.Repo, nil)
+ }
+
if issue.IsPull {
if err = issue.LoadPullRequest(ctx); err != nil {
log.Error("loadPullRequest: %v", err)
@@ -228,6 +238,7 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
Repository: convert.ToRepo(ctx, issue.Repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}),
Sender: convert.ToUser(ctx, doer, nil),
+ Label: apiLabel,
}).
WithPullRequest(issue.PullRequest).
Notify(ctx)
@@ -242,6 +253,7 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
Issue: convert.ToAPIIssue(ctx, doer, issue),
Repository: convert.ToRepo(ctx, issue.Repo, permission),
Sender: convert.ToUser(ctx, doer, nil),
+ Label: apiLabel,
}).
Notify(ctx)
}