Skip to content

Commit 61ea01d

Browse files
committed
feat: support requested_reviewers data in comment webhook events
1 parent 79995a8 commit 61ea01d

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

modules/structs/hook.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ const (
216216

217217
// IssueCommentPayload represents a payload information of issue comment event.
218218
type IssueCommentPayload struct {
219-
Action HookIssueCommentAction `json:"action"`
220-
Issue *Issue `json:"issue"`
221-
Comment *Comment `json:"comment"`
222-
Changes *ChangesPayload `json:"changes,omitempty"`
223-
Repository *Repository `json:"repository"`
224-
Sender *User `json:"sender"`
225-
IsPull bool `json:"is_pull"`
219+
Action HookIssueCommentAction `json:"action"`
220+
Issue *Issue `json:"issue"`
221+
PullRequest *PullRequest `json:"pull_request"`
222+
Comment *Comment `json:"comment"`
223+
Changes *ChangesPayload `json:"changes,omitempty"`
224+
Repository *Repository `json:"repository"`
225+
Sender *User `json:"sender"`
226+
IsPull bool `json:"is_pull"`
226227
}
227228

228229
// JSONPayload implements Payload

services/webhook/notifier.go

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -376,17 +376,19 @@ func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo
376376
}
377377

378378
var eventType webhook_module.HookEventType
379+
var pullRequest *api.PullRequest
379380
if c.Issue.IsPull {
380381
eventType = webhook_module.HookEventPullRequestComment
382+
pullRequest = convert.ToAPIPullRequest(ctx, c.Issue.PullRequest, nil)
381383
} else {
382384
eventType = webhook_module.HookEventIssueComment
383385
}
384-
385386
permission, _ := access_model.GetUserRepoPermission(ctx, c.Issue.Repo, doer)
386-
if err := PrepareWebhooks(ctx, EventSource{Repository: c.Issue.Repo}, eventType, &api.IssueCommentPayload{
387-
Action: api.HookIssueCommentEdited,
388-
Issue: convert.ToAPIIssue(ctx, c.Issue),
389-
Comment: convert.ToAPIComment(ctx, c.Issue.Repo, c),
387+
issueCommentPayload := &api.IssueCommentPayload{
388+
Action: api.HookIssueCommentEdited,
389+
Issue: convert.ToAPIIssue(ctx, c.Issue),
390+
PullRequest: pullRequest,
391+
Comment: convert.ToAPIComment(ctx, c.Issue.Repo, c),
390392
Changes: &api.ChangesPayload{
391393
Body: &api.ChangesFromPayload{
392394
From: oldContent,
@@ -395,7 +397,8 @@ func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo
395397
Repository: convert.ToRepo(ctx, c.Issue.Repo, permission),
396398
Sender: convert.ToUser(ctx, doer, nil),
397399
IsPull: c.Issue.IsPull,
398-
}); err != nil {
400+
}
401+
if err := PrepareWebhooks(ctx, EventSource{Repository: c.Issue.Repo}, eventType, issueCommentPayload); err != nil {
399402
log.Error("PrepareWebhooks [comment_id: %d]: %v", c.ID, err)
400403
}
401404
}
@@ -404,21 +407,24 @@ func (m *webhookNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
404407
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
405408
) {
406409
var eventType webhook_module.HookEventType
410+
var pullRequest *api.PullRequest
407411
if issue.IsPull {
408412
eventType = webhook_module.HookEventPullRequestComment
413+
pullRequest = convert.ToAPIPullRequest(ctx, issue.PullRequest, nil)
409414
} else {
410415
eventType = webhook_module.HookEventIssueComment
411416
}
412-
413417
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
414-
if err := PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, eventType, &api.IssueCommentPayload{
415-
Action: api.HookIssueCommentCreated,
416-
Issue: convert.ToAPIIssue(ctx, issue),
417-
Comment: convert.ToAPIComment(ctx, repo, comment),
418-
Repository: convert.ToRepo(ctx, repo, permission),
419-
Sender: convert.ToUser(ctx, doer, nil),
420-
IsPull: issue.IsPull,
421-
}); err != nil {
418+
issueCommentPayload := &api.IssueCommentPayload{
419+
Action: api.HookIssueCommentCreated,
420+
Issue: convert.ToAPIIssue(ctx, issue),
421+
PullRequest: pullRequest,
422+
Comment: convert.ToAPIComment(ctx, repo, comment),
423+
Repository: convert.ToRepo(ctx, repo, permission),
424+
Sender: convert.ToUser(ctx, doer, nil),
425+
IsPull: issue.IsPull,
426+
}
427+
if err := PrepareWebhooks(ctx, EventSource{Repository: issue.Repo}, eventType, issueCommentPayload); err != nil {
422428
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
423429
}
424430
}
@@ -441,21 +447,25 @@ func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo
441447
}
442448

443449
var eventType webhook_module.HookEventType
450+
var pullRequest *api.PullRequest
444451
if comment.Issue.IsPull {
445452
eventType = webhook_module.HookEventPullRequestComment
453+
pullRequest = convert.ToAPIPullRequest(ctx, comment.Issue.PullRequest, nil)
446454
} else {
447455
eventType = webhook_module.HookEventIssueComment
448456
}
449-
450457
permission, _ := access_model.GetUserRepoPermission(ctx, comment.Issue.Repo, doer)
451-
if err := PrepareWebhooks(ctx, EventSource{Repository: comment.Issue.Repo}, eventType, &api.IssueCommentPayload{
452-
Action: api.HookIssueCommentDeleted,
453-
Issue: convert.ToAPIIssue(ctx, comment.Issue),
454-
Comment: convert.ToAPIComment(ctx, comment.Issue.Repo, comment),
455-
Repository: convert.ToRepo(ctx, comment.Issue.Repo, permission),
456-
Sender: convert.ToUser(ctx, doer, nil),
457-
IsPull: comment.Issue.IsPull,
458-
}); err != nil {
458+
issueCommentPayload := &api.IssueCommentPayload{
459+
Action: api.HookIssueCommentDeleted,
460+
Issue: convert.ToAPIIssue(ctx, comment.Issue),
461+
PullRequest: pullRequest,
462+
Comment: convert.ToAPIComment(ctx, comment.Issue.Repo, comment),
463+
Repository: convert.ToRepo(ctx, comment.Issue.Repo, permission),
464+
Sender: convert.ToUser(ctx, doer, nil),
465+
IsPull: comment.Issue.IsPull,
466+
}
467+
468+
if err := PrepareWebhooks(ctx, EventSource{Repository: comment.Issue.Repo}, eventType, issueCommentPayload); err != nil {
459469
log.Error("PrepareWebhooks [comment_id: %d]: %v", comment.ID, err)
460470
}
461471
}

0 commit comments

Comments
 (0)