Skip to content

Commit

Permalink
[webhook] Apply more comments to 'NotifyPullRequestReview'.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhoang1107 committed Aug 19, 2023
1 parent 7772610 commit dd6d94b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
17 changes: 4 additions & 13 deletions services/actions/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
}
}

func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, _ []*user_model.User) {
func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) {
ctx = withMethod(ctx, "NotifyPullRequestReview")

var reviewHookType webhook_module.HookEventType
Expand Down Expand Up @@ -290,14 +290,7 @@ func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
log.Error("models.GetUserRepoPermission: %v", err)
return
}
var comments = make([]*api.Comment, 0, len(review.CodeComments))
for _, lineCommendsMap := range review.CodeComments {
for _, lineComments := range lineCommendsMap {
for _, cmt := range lineComments {
comments = append(comments, convert.ToComment(ctx, cmt))
}
}
}

newNotifyInput(review.Issue.Repo, review.Reviewer, reviewHookType).
WithRef(review.CommitID).
WithPayload(&api.PullRequestPayload{
Expand All @@ -307,10 +300,8 @@ func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
Repository: convert.ToRepo(ctx, review.Issue.Repo, permission),
Sender: convert.ToUser(ctx, review.Reviewer, nil),
Review: &api.ReviewPayload{
Type: string(reviewHookType),
Content: review.Content,
OverallComment: convert.ToComment(ctx, comment),
Comments: comments,
Type: string(reviewHookType),
Content: review.Content,
},
}).Notify(ctx)
}
Expand Down
15 changes: 13 additions & 2 deletions services/webhook/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex

func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
var reviewHookType webhook_module.HookEventType

switch review.Type {
case issues_model.ReviewTypeApprove:
reviewHookType = webhook_module.HookEventPullRequestReviewApproved
Expand All @@ -702,15 +703,25 @@ func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
log.Error("models.GetUserRepoPermission: %v", err)
return
}
var comments = make([]*api.Comment, 0, len(review.CodeComments))
for _, lineCommendsMap := range review.CodeComments {
for _, lineComments := range lineCommendsMap {
for _, cmt := range lineComments {
comments = append(comments, convert.ToComment(ctx, cmt))
}
}
}
if err := PrepareWebhooks(ctx, EventSource{Repository: review.Issue.Repo}, reviewHookType, &api.PullRequestPayload{
Action: api.HookIssueReviewed,
Index: review.Issue.Index,
PullRequest: convert.ToAPIPullRequest(ctx, pr, nil),
Repository: convert.ToRepo(ctx, review.Issue.Repo, permission),
Sender: convert.ToUser(ctx, review.Reviewer, nil),
Review: &api.ReviewPayload{
Type: string(reviewHookType),
Content: review.Content,
Type: string(reviewHookType),
Content: review.Content,
OverallComment: convert.ToComment(ctx, comment),
Comments: comments,
},
}); err != nil {
log.Error("PrepareWebhooks: %v", err)
Expand Down

0 comments on commit dd6d94b

Please sign in to comment.