mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 15:57:02 +00:00
This commit is contained in:
parent
2c93bd79f2
commit
e930d66a9c
|
@ -19,6 +19,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/structs"
|
"code.gitea.io/gitea/modules/structs"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
@ -474,6 +475,35 @@ func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, co
|
||||||
return review, comm, committer.Commit()
|
return review, comm, committer.Commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetReviewOptions represent filter options for GetReviews
|
||||||
|
type GetReviewOptions struct {
|
||||||
|
IssueID int64
|
||||||
|
ReviewerID int64
|
||||||
|
Dismissed util.OptionalBool
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetReviews return reviews based on GetReviewOptions
|
||||||
|
func GetReviews(ctx context.Context, opts *GetReviewOptions) ([]*Review, error) {
|
||||||
|
if opts == nil {
|
||||||
|
return nil, fmt.Errorf("opts are nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
sess := db.GetEngine(ctx)
|
||||||
|
|
||||||
|
if opts.IssueID != 0 {
|
||||||
|
sess = sess.Where("issue_id=?", opts.IssueID)
|
||||||
|
}
|
||||||
|
if opts.ReviewerID != 0 {
|
||||||
|
sess = sess.Where("reviewer_id=?", opts.ReviewerID)
|
||||||
|
}
|
||||||
|
if !opts.Dismissed.IsNone() {
|
||||||
|
sess = sess.Where("dismissed=?", opts.Dismissed.IsTrue())
|
||||||
|
}
|
||||||
|
|
||||||
|
reviews := make([]*Review, 0, 4)
|
||||||
|
return reviews, sess.Find(&reviews)
|
||||||
|
}
|
||||||
|
|
||||||
// GetReviewersByIssueID gets the latest review of each reviewer for a pull request
|
// GetReviewersByIssueID gets the latest review of each reviewer for a pull request
|
||||||
func GetReviewersByIssueID(issueID int64) ([]*Review, error) {
|
func GetReviewersByIssueID(issueID int64) ([]*Review, error) {
|
||||||
reviews := make([]*Review, 0, 10)
|
reviews := make([]*Review, 0, 10)
|
||||||
|
|
|
@ -97,6 +97,7 @@ type SubmitPullReviewOptions struct {
|
||||||
// DismissPullReviewOptions are options to dismiss a pull review
|
// DismissPullReviewOptions are options to dismiss a pull review
|
||||||
type DismissPullReviewOptions struct {
|
type DismissPullReviewOptions struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
Priors bool `json:"priors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PullReviewRequestOptions are options to add or remove pull review requests
|
// PullReviewRequestOptions are options to add or remove pull review requests
|
||||||
|
|
|
@ -823,7 +823,7 @@ func DismissPullReview(ctx *context.APIContext) {
|
||||||
// "422":
|
// "422":
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
opts := web.GetForm(ctx).(*api.DismissPullReviewOptions)
|
opts := web.GetForm(ctx).(*api.DismissPullReviewOptions)
|
||||||
dismissReview(ctx, opts.Message, true)
|
dismissReview(ctx, opts.Message, true, opts.Priors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnDismissPullReview cancel to dismiss a review for a pull request
|
// UnDismissPullReview cancel to dismiss a review for a pull request
|
||||||
|
@ -863,10 +863,10 @@ func UnDismissPullReview(ctx *context.APIContext) {
|
||||||
// "$ref": "#/responses/forbidden"
|
// "$ref": "#/responses/forbidden"
|
||||||
// "422":
|
// "422":
|
||||||
// "$ref": "#/responses/validationError"
|
// "$ref": "#/responses/validationError"
|
||||||
dismissReview(ctx, "", false)
|
dismissReview(ctx, "", false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
func dismissReview(ctx *context.APIContext, msg string, isDismiss, dismissPriors bool) {
|
||||||
if !ctx.Repo.IsAdmin() {
|
if !ctx.Repo.IsAdmin() {
|
||||||
ctx.Error(http.StatusForbidden, "", "Must be repo admin")
|
ctx.Error(http.StatusForbidden, "", "Must be repo admin")
|
||||||
return
|
return
|
||||||
|
@ -886,7 +886,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := pull_service.DismissReview(ctx, review.ID, ctx.Repo.Repository.ID, msg, ctx.Doer, isDismiss)
|
_, err := pull_service.DismissReview(ctx, review.ID, ctx.Repo.Repository.ID, msg, ctx.Doer, isDismiss, dismissPriors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -242,7 +242,7 @@ func SubmitReview(ctx *context.Context) {
|
||||||
// DismissReview dismissing stale review by repo admin
|
// DismissReview dismissing stale review by repo admin
|
||||||
func DismissReview(ctx *context.Context) {
|
func DismissReview(ctx *context.Context) {
|
||||||
form := web.GetForm(ctx).(*forms.DismissReviewForm)
|
form := web.GetForm(ctx).(*forms.DismissReviewForm)
|
||||||
comm, err := pull_service.DismissReview(ctx, form.ReviewID, ctx.Repo.Repository.ID, form.Message, ctx.Doer, true)
|
comm, err := pull_service.DismissReview(ctx, form.ReviewID, ctx.Repo.Repository.ID, form.Message, ctx.Doer, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("pull_service.DismissReview", err)
|
ctx.ServerError("pull_service.DismissReview", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/notification"
|
"code.gitea.io/gitea/modules/notification"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateCodeComment creates a comment on the code line
|
// CreateCodeComment creates a comment on the code line
|
||||||
|
@ -271,7 +272,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||||
}
|
}
|
||||||
|
|
||||||
// DismissReview dismissing stale review by repo admin
|
// DismissReview dismissing stale review by repo admin
|
||||||
func DismissReview(ctx context.Context, reviewID, repoID int64, message string, doer *user_model.User, isDismiss bool) (comment *issues_model.Comment, err error) {
|
func DismissReview(ctx context.Context, reviewID, repoID int64, message string, doer *user_model.User, isDismiss, dismissPriors bool) (comment *issues_model.Comment, err error) {
|
||||||
review, err := issues_model.GetReviewByID(ctx, reviewID)
|
review, err := issues_model.GetReviewByID(ctx, reviewID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -295,6 +296,22 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dismissPriors {
|
||||||
|
reviews, err := issues_model.GetReviews(ctx, &issues_model.GetReviewOptions{
|
||||||
|
IssueID: review.IssueID,
|
||||||
|
ReviewerID: review.ReviewerID,
|
||||||
|
Dismissed: util.OptionalBoolFalse,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, oldReview := range reviews {
|
||||||
|
if err = issues_model.DismissReview(oldReview, true); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !isDismiss {
|
if !isDismiss {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -14803,6 +14803,10 @@
|
||||||
"message": {
|
"message": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"x-go-name": "Message"
|
"x-go-name": "Message"
|
||||||
|
},
|
||||||
|
"priors": {
|
||||||
|
"type": "boolean",
|
||||||
|
"x-go-name": "Priors"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
"x-go-package": "code.gitea.io/gitea/modules/structs"
|
||||||
|
|
Loading…
Reference in a new issue