1
1
Fork 1
mirror of https://github.com/go-gitea/gitea.git synced 2024-05-08 17:06:09 +02:00

PR feedback

This commit is contained in:
Kemal Zebari 2024-04-26 19:19:51 -07:00
parent c89d78dfa1
commit a3915c90bd
3 changed files with 10 additions and 22 deletions

View File

@ -4,6 +4,7 @@
package repo
import (
"errors"
"fmt"
"net/http"
"strings"
@ -372,7 +373,7 @@ func CreatePullReview(ctx *context.APIContext) {
// create review and associate all pending review comments
review, _, err := pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
if err != nil {
if pull_service.IsErrSubmitReviewOnClosedPR(err) {
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
@ -464,7 +465,7 @@ func SubmitPullReview(ctx *context.APIContext) {
// create review and associate all pending review comments
review, _, err = pull_service.SubmitReview(ctx, ctx.Doer, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
if err != nil {
if pull_service.IsErrSubmitReviewOnClosedPR(err) {
if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
} else {
ctx.Error(http.StatusInternalServerError, "SubmitReview", err)

View File

@ -264,7 +264,7 @@ func SubmitReview(ctx *context.Context) {
if issues_model.IsContentEmptyErr(err) {
ctx.Flash.Error(ctx.Tr("repo.issues.review.content.empty"))
ctx.JSONRedirect(fmt.Sprintf("%s/pulls/%d/files", ctx.Repo.RepoLink, issue.Index))
} else if pull_service.IsErrSubmitReviewOnClosedPR(err) {
} else if errors.Is(err, pull_service.ErrSubmitReviewOnClosedPR) {
ctx.Status(http.StatusUnprocessableEntity)
} else {
ctx.ServerError("SubmitReview", err)

View File

@ -6,6 +6,7 @@ package pull
import (
"context"
"errors"
"fmt"
"io"
"regexp"
@ -44,21 +45,7 @@ func (err ErrDismissRequestOnClosedPR) Unwrap() error {
}
// ErrSubmitReviewOnClosedPR represents an error when an user tries to submit an approve or reject review associated to a closed or merged PR.
type ErrSubmitReviewOnClosedPR struct{}
// IsErrSubmitReviewOnClosedPR checks if an error is an ErrSubmitReviewOnClosedPR.
func IsErrSubmitReviewOnClosedPR(err error) bool {
_, ok := err.(ErrSubmitReviewOnClosedPR)
return ok
}
func (err ErrSubmitReviewOnClosedPR) Error() string {
return "can't submit review for a closed or merged PR"
}
func (err ErrSubmitReviewOnClosedPR) Unwrap() error {
return util.ErrPermissionDenied
}
var ErrSubmitReviewOnClosedPR = errors.New("can't submit review for a closed or merged PR")
// checkInvalidation checks if the line of code comment got changed by another commit.
// If the line got changed the comment is going to be invalidated.
@ -301,6 +288,10 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue, reviewType issues_model.ReviewType, content, commitID string, attachmentUUIDs []string) (*issues_model.Review, *issues_model.Comment, error) {
if issue.IsClosed {
return nil, nil, ErrSubmitReviewOnClosedPR
}
if err := issue.LoadPullRequest(ctx); err != nil {
return nil, nil, err
}
@ -310,10 +301,6 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
if reviewType != issues_model.ReviewTypeApprove && reviewType != issues_model.ReviewTypeReject {
stale = false
} else {
if issue.IsClosed || pr.HasMerged {
return nil, nil, ErrSubmitReviewOnClosedPR{}
}
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
return nil, nil, err