mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 05:54:38 +02:00
Add support for removed labels in issue and pull request notifications
This commit is contained in:
parent
56314f605a
commit
84b684eba4
@ -342,6 +342,7 @@ type PullRequestPayload struct {
|
|||||||
Action HookIssueAction `json:"action"`
|
Action HookIssueAction `json:"action"`
|
||||||
Index int64 `json:"number"`
|
Index int64 `json:"number"`
|
||||||
Changes *ChangesPayload `json:"changes,omitempty"`
|
Changes *ChangesPayload `json:"changes,omitempty"`
|
||||||
|
RemovedLabels []*Label `json:"removed_labels"`
|
||||||
PullRequest *PullRequest `json:"pull_request"`
|
PullRequest *PullRequest `json:"pull_request"`
|
||||||
RequestedReviewer *User `json:"requested_reviewer"`
|
RequestedReviewer *User `json:"requested_reviewer"`
|
||||||
Repository *Repository `json:"repository"`
|
Repository *Repository `json:"repository"`
|
||||||
|
@ -26,6 +26,12 @@ type actionsNotifier struct {
|
|||||||
notify_service.NullNotifier
|
notify_service.NullNotifier
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type contextKey string
|
||||||
|
|
||||||
|
const (
|
||||||
|
removedLabelsKey contextKey = "GiteaRemovedLabels"
|
||||||
|
)
|
||||||
|
|
||||||
var _ notify_service.Notifier = &actionsNotifier{}
|
var _ notify_service.Notifier = &actionsNotifier{}
|
||||||
|
|
||||||
// NewNotifier create a new actionsNotifier notifier
|
// NewNotifier create a new actionsNotifier notifier
|
||||||
@ -189,7 +195,7 @@ func (n *actionsNotifier) IssueChangeMilestone(ctx context.Context, doer *user_m
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
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")
|
ctx = withMethod(ctx, "IssueChangeLabels")
|
||||||
|
|
||||||
@ -198,6 +204,22 @@ func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_mode
|
|||||||
hookEvent = webhook_module.HookEventPullRequestLabel
|
hookEvent = webhook_module.HookEventPullRequestLabel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Track removedLabels for the webhook payload
|
||||||
|
var removedAPILabels []*api.Label
|
||||||
|
if len(removedLabels) > 0 {
|
||||||
|
if err := issue.LoadRepo(ctx); err != nil {
|
||||||
|
log.Error("LoadRepo: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
removedAPILabels = make([]*api.Label, 0, len(removedLabels))
|
||||||
|
for _, label := range removedLabels {
|
||||||
|
removedAPILabels = append(removedAPILabels, convert.ToLabel(label, issue.Repo, doer))
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = context.WithValue(ctx, removedLabelsKey, removedAPILabels)
|
||||||
|
}
|
||||||
|
|
||||||
notifyIssueChange(ctx, doer, issue, hookEvent, api.HookIssueLabelUpdated)
|
notifyIssueChange(ctx, doer, issue, hookEvent, api.HookIssueLabelUpdated)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,34 +235,50 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get removed labels from context if present
|
||||||
|
var removedAPILabels []*api.Label
|
||||||
|
if removedLabelsValue := ctx.Value(removedLabelsKey); removedLabelsValue != nil {
|
||||||
|
if labels, ok := removedLabelsValue.([]*api.Label); ok {
|
||||||
|
removedAPILabels = labels
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
if err = issue.LoadPullRequest(ctx); err != nil {
|
if err = issue.LoadPullRequest(ctx); err != nil {
|
||||||
log.Error("loadPullRequest: %v", err)
|
log.Error("loadPullRequest: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newNotifyInputFromIssue(issue, event).
|
|
||||||
WithDoer(doer).
|
payload := &api.PullRequestPayload{
|
||||||
WithPayload(&api.PullRequestPayload{
|
|
||||||
Action: action,
|
Action: action,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
PullRequest: convert.ToAPIPullRequest(ctx, issue.PullRequest, nil),
|
||||||
Repository: convert.ToRepo(ctx, issue.Repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}),
|
Repository: convert.ToRepo(ctx, issue.Repo, access_model.Permission{AccessMode: perm_model.AccessModeNone}),
|
||||||
Sender: convert.ToUser(ctx, doer, nil),
|
Sender: convert.ToUser(ctx, doer, nil),
|
||||||
}).
|
RemovedLabels: removedAPILabels,
|
||||||
|
}
|
||||||
|
|
||||||
|
newNotifyInputFromIssue(issue, event).
|
||||||
|
WithDoer(doer).
|
||||||
|
WithPayload(payload).
|
||||||
WithPullRequest(issue.PullRequest).
|
WithPullRequest(issue.PullRequest).
|
||||||
Notify(ctx)
|
Notify(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
|
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
|
||||||
newNotifyInputFromIssue(issue, event).
|
payload := &api.IssuePayload{
|
||||||
WithDoer(doer).
|
|
||||||
WithPayload(&api.IssuePayload{
|
|
||||||
Action: action,
|
Action: action,
|
||||||
Index: issue.Index,
|
Index: issue.Index,
|
||||||
Issue: convert.ToAPIIssue(ctx, doer, issue),
|
Issue: convert.ToAPIIssue(ctx, doer, issue),
|
||||||
Repository: convert.ToRepo(ctx, issue.Repo, permission),
|
Repository: convert.ToRepo(ctx, issue.Repo, permission),
|
||||||
Sender: convert.ToUser(ctx, doer, nil),
|
Sender: convert.ToUser(ctx, doer, nil),
|
||||||
}).
|
RemovedLabels: removedAPILabels,
|
||||||
|
}
|
||||||
|
|
||||||
|
newNotifyInputFromIssue(issue, event).
|
||||||
|
WithDoer(doer).
|
||||||
|
WithPayload(payload).
|
||||||
Notify(ctx)
|
Notify(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user