Add dismiss review feature (#12674)

* Add dismiss review feature

refs:
    https://github.blog/2016-10-12-dismissing-reviews-on-pull-requests/
    https://developer.github.com/v3/pulls/reviews/#dismiss-a-review-for-a-pull-request

* change modal ui and error message

* Add unDismissReview api

Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
a1012112796 2021-02-12 01:32:25 +08:00 committed by GitHub
parent c69c01d2b6
commit ac701637b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 593 additions and 39 deletions

View file

@ -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
}