diff options
Diffstat (limited to 'services/pull/review.go')
-rw-r--r-- | services/pull/review.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/services/pull/review.go b/services/pull/review.go index 8994a9e78a..4e77e11daa 100644 --- a/services/pull/review.go +++ b/services/pull/review.go @@ -253,3 +253,54 @@ func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issu return review, comm, nil } + +// DismissReview dismissing stale review by repo admin +func DismissReview(reviewID int64, message string, doer *models.User, isDismiss bool) (comment *models.Comment, err error) { + review, err := models.GetReviewByID(reviewID) + if err != nil { + return + } + + if review.Type != models.ReviewTypeApprove && review.Type != models.ReviewTypeReject { + return nil, fmt.Errorf("not need to dismiss this review because it's type is not Approve or change request") + } + + if err = models.DismissReview(review, isDismiss); err != nil { + return + } + + if !isDismiss { + return nil, nil + } + + // load data for notify + if err = review.LoadAttributes(); err != nil { + return + } + if err = review.Issue.LoadPullRequest(); err != nil { + return + } + if err = review.Issue.LoadAttributes(); err != nil { + return + } + + comment, err = models.CreateComment(&models.CreateCommentOptions{ + Doer: doer, + Content: message, + Type: models.CommentTypeDismissReview, + ReviewID: review.ID, + Issue: review.Issue, + Repo: review.Issue.Repo, + }) + if err != nil { + return + } + + comment.Review = review + comment.Poster = doer + comment.Issue = review.Issue + + notification.NotifyPullRevieweDismiss(doer, review, comment) + + return +} |