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.
(cherry picked from commit 58e3c1fbdb
)
This commit is contained in:
parent
7ec30b6ee9
commit
11f71dcb09
2 changed files with 19 additions and 5 deletions
|
@ -362,6 +362,7 @@ type IssuePayload struct {
|
||||||
Repository *Repository `json:"repository"`
|
Repository *Repository `json:"repository"`
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
CommitID string `json:"commit_id"`
|
CommitID string `json:"commit_id"`
|
||||||
|
Label *Label `json:"label,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
|
// JSONPayload encodes the IssuePayload to JSON, with an indentation of two spaces.
|
||||||
|
@ -399,6 +400,7 @@ type PullRequestPayload struct {
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
CommitID string `json:"commit_id"`
|
CommitID string `json:"commit_id"`
|
||||||
Review *ReviewPayload `json:"review"`
|
Review *ReviewPayload `json:"review"`
|
||||||
|
Label *Label `json:"label,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JSONPayload FIXME
|
// JSONPayload FIXME
|
||||||
|
|
|
@ -168,7 +168,7 @@ func (n *actionsNotifier) IssueChangeAssignee(ctx context.Context, doer *user_mo
|
||||||
hookEvent = webhook_module.HookEventPullRequestAssign
|
hookEvent = webhook_module.HookEventPullRequestAssign
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyIssueChange(ctx, doer, issue, hookEvent, action)
|
notifyIssueChange(ctx, doer, issue, hookEvent, action, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssueChangeMilestone notifies assignee to notifiers
|
// IssueChangeMilestone notifies assignee to notifiers
|
||||||
|
@ -187,11 +187,11 @@ func (n *actionsNotifier) IssueChangeMilestone(ctx context.Context, doer *user_m
|
||||||
hookEvent = webhook_module.HookEventPullRequestMilestone
|
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,
|
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")
|
||||||
|
|
||||||
|
@ -200,10 +200,15 @@ func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_mode
|
||||||
hookEvent = webhook_module.HookEventPullRequestLabel
|
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
|
var err error
|
||||||
if err = issue.LoadRepo(ctx); err != nil {
|
if err = issue.LoadRepo(ctx); err != nil {
|
||||||
log.Error("LoadRepo: %v", err)
|
log.Error("LoadRepo: %v", err)
|
||||||
|
@ -215,6 +220,11 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var apiLabel *api.Label
|
||||||
|
if action == api.HookIssueLabelUpdated || action == api.HookIssueLabelCleared {
|
||||||
|
apiLabel = convert.ToLabel(label, issue.Repo, nil)
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -228,6 +238,7 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
|
||||||
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),
|
||||||
|
Label: apiLabel,
|
||||||
}).
|
}).
|
||||||
WithPullRequest(issue.PullRequest).
|
WithPullRequest(issue.PullRequest).
|
||||||
Notify(ctx)
|
Notify(ctx)
|
||||||
|
@ -242,6 +253,7 @@ func notifyIssueChange(ctx context.Context, doer *user_model.User, issue *issues
|
||||||
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),
|
||||||
|
Label: apiLabel,
|
||||||
}).
|
}).
|
||||||
Notify(ctx)
|
Notify(ctx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue