aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/mailer/mail.go2
-rw-r--r--services/pull/review.go51
2 files changed, 53 insertions, 0 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index b4217c0466..e87d34ab29 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -304,6 +304,8 @@ func actionToTemplate(issue *models.Issue, actionType models.ActionType,
name = "reopen"
case models.ActionMergePullRequest:
name = "merge"
+ case models.ActionPullReviewDismissed:
+ name = "review_dismissed"
default:
switch commentType {
case models.CommentTypeReview:
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
+}