From 023ae3c48cded84dee6bdcbcf7bba8cc92a4a408 Mon Sep 17 00:00:00 2001 From: guillep2k <18600385+guillep2k@users.noreply.github.com> Date: Wed, 13 Nov 2019 21:38:12 -0300 Subject: [PATCH] Hotfix for review actions and notifications (#8965) --- models/issue_comment.go | 21 ++++++++++++++++----- models/review.go | 1 + routers/repo/pull_review.go | 10 ++++++---- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/models/issue_comment.go b/models/issue_comment.go index 2d5f2839bf..f3921b80c5 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -538,6 +538,10 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen switch opts.Type { case CommentTypeCode: if comment.ReviewID != 0 { + // Hotfix for 1.10.0 as the Review object has not yet been committed in the other session + if opts.Review != nil { + comment.Review = opts.Review + } if comment.Review == nil { if err := comment.loadReview(e); err != nil { return err @@ -596,6 +600,12 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen if err = opts.Issue.updateClosedNum(e); err != nil { return err } + case CommentTypeReview: + // Hotfix for 1.10.0; make sure a dashboard entry is created + if opts.Content == "" { + return nil + } + act.OpType = ActionCommentIssue } // update the issue's updated_unix column if err = updateIssueCols(e, opts.Issue, "updated_unix"); err != nil { @@ -751,11 +761,12 @@ func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dep // CreateCommentOptions defines options for creating comment type CreateCommentOptions struct { - Type CommentType - Doer *User - Repo *Repository - Issue *Issue - Label *Label + Type CommentType + Doer *User + Repo *Repository + Issue *Issue + Label *Label + Review *Review DependentIssueID int64 OldMilestoneID int64 diff --git a/models/review.go b/models/review.go index 454d16ee88..5c1449c18a 100644 --- a/models/review.go +++ b/models/review.go @@ -135,6 +135,7 @@ func (r *Review) publish(e *xorm.Engine) error { Repo: review.Issue.Repo, Type: comm.Type, Content: comm.Content, + Review: r, }, comm); err != nil { log.Warn("sendCreateCommentAction: %v", err) } diff --git a/routers/repo/pull_review.go b/routers/repo/pull_review.go index 5eb0dfe9a7..4c17537071 100644 --- a/routers/repo/pull_review.go +++ b/routers/repo/pull_review.go @@ -174,6 +174,12 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) { return } } + + // Hotfix 1.10.0: make sure the review exists before creating the head comment + if err = review.Publish(); err != nil { + ctx.ServerError("Publish", err) + return + } comm, err := models.CreateComment(&models.CreateCommentOptions{ Type: models.CommentTypeReview, Doer: ctx.User, @@ -186,10 +192,6 @@ func SubmitReview(ctx *context.Context, form auth.SubmitReviewForm) { ctx.ServerError("CreateComment", err) return } - if err = review.Publish(); err != nil { - ctx.ServerError("Publish", err) - return - } pr, err := issue.GetPullRequest() if err != nil {