Fix review webhooks (#8570)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
d44053eeda
commit
7c4c01c0fd
3 changed files with 40 additions and 16 deletions
|
@ -413,7 +413,17 @@ func getDiscordPullRequestApprovalPayload(p *api.PullRequestPayload, meta *Disco
|
||||||
|
|
||||||
title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
|
title = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
|
||||||
text = p.PullRequest.Body
|
text = p.PullRequest.Body
|
||||||
color = warnColor
|
|
||||||
|
switch event {
|
||||||
|
case HookEventPullRequestApproved:
|
||||||
|
color = successColor
|
||||||
|
case HookEventPullRequestRejected:
|
||||||
|
color = failedColor
|
||||||
|
case HookEventPullRequestComment:
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
color = warnColor
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &DiscordPayload{
|
return &DiscordPayload{
|
||||||
|
|
|
@ -157,7 +157,7 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// No current review. Create a new one!
|
// No current review. Create a new one!
|
||||||
if review, err = models.CreateReview(models.CreateReviewOptions{
|
if review, err = pull_service.CreateReview(models.CreateReviewOptions{
|
||||||
Type: reviewType,
|
Type: reviewType,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
Reviewer: ctx.User,
|
Reviewer: ctx.User,
|
||||||
|
@ -169,7 +169,7 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) {
|
||||||
} else {
|
} else {
|
||||||
review.Content = form.Content
|
review.Content = form.Content
|
||||||
review.Type = reviewType
|
review.Type = reviewType
|
||||||
if err = models.UpdateReview(review); err != nil {
|
if err = pull_service.UpdateReview(review); err != nil {
|
||||||
ctx.ServerError("UpdateReview", err)
|
ctx.ServerError("UpdateReview", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,23 @@ func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return review, reviewHook(review)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateReview updates a review
|
||||||
|
func UpdateReview(review *models.Review) error {
|
||||||
|
err := models.UpdateReview(review)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return reviewHook(review)
|
||||||
|
}
|
||||||
|
|
||||||
|
func reviewHook(review *models.Review) error {
|
||||||
var reviewHookType models.HookEventType
|
var reviewHookType models.HookEventType
|
||||||
|
|
||||||
switch opts.Type {
|
switch review.Type {
|
||||||
case models.ReviewTypeApprove:
|
case models.ReviewTypeApprove:
|
||||||
reviewHookType = models.HookEventPullRequestApproved
|
reviewHookType = models.HookEventPullRequestApproved
|
||||||
case models.ReviewTypeComment:
|
case models.ReviewTypeComment:
|
||||||
|
@ -28,30 +42,30 @@ func CreateReview(opts models.CreateReviewOptions) (*models.Review, error) {
|
||||||
reviewHookType = models.HookEventPullRequestRejected
|
reviewHookType = models.HookEventPullRequestRejected
|
||||||
default:
|
default:
|
||||||
// unsupported review webhook type here
|
// unsupported review webhook type here
|
||||||
return review, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pr := opts.Issue.PullRequest
|
pr := review.Issue.PullRequest
|
||||||
|
|
||||||
if err := pr.LoadIssue(); err != nil {
|
if err := pr.LoadIssue(); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
mode, err := models.AccessLevel(opts.Issue.Poster, opts.Issue.Repo)
|
mode, err := models.AccessLevel(review.Issue.Poster, review.Issue.Repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.PrepareWebhooks(opts.Issue.Repo, reviewHookType, &api.PullRequestPayload{
|
if err := models.PrepareWebhooks(review.Issue.Repo, reviewHookType, &api.PullRequestPayload{
|
||||||
Action: api.HookIssueSynchronized,
|
Action: api.HookIssueSynchronized,
|
||||||
Index: opts.Issue.Index,
|
Index: review.Issue.Index,
|
||||||
PullRequest: pr.APIFormat(),
|
PullRequest: pr.APIFormat(),
|
||||||
Repository: opts.Issue.Repo.APIFormat(mode),
|
Repository: review.Issue.Repo.APIFormat(mode),
|
||||||
Sender: opts.Reviewer.APIFormat(),
|
Sender: review.Reviewer.APIFormat(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
go models.HookQueue.Add(opts.Issue.Repo.ID)
|
go models.HookQueue.Add(review.Issue.Repo.ID)
|
||||||
|
|
||||||
return review, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue