Merge pull request '[gitea] week 2024-34 cherry pick (gitea/main -> forgejo)' (#4998) from earl-warren/wcp/2024-34 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4998
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
This commit is contained in:
Earl Warren 2024-08-20 06:32:09 +00:00
commit c76a73ad35
20 changed files with 273 additions and 38 deletions

View file

@ -1524,13 +1524,12 @@ func CompareAndPullRequestPost(ctx *context.Context) {
// instead of 500.
if err := pull_service.NewPullRequest(ctx, repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil {
if errors.Is(err, user_model.ErrBlockedByUser) {
switch {
case errors.Is(err, user_model.ErrBlockedByUser):
ctx.JSONError(ctx.Tr("repo.pulls.blocked_by_user"))
return
} else if repo_model.IsErrUserDoesNotHaveAccessToRepo(err) {
case repo_model.IsErrUserDoesNotHaveAccessToRepo(err):
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
return
} else if git.IsErrPushRejected(err) {
case git.IsErrPushRejected(err):
pushrejErr := err.(*git.ErrPushRejected)
message := pushrejErr.Message
if len(message) == 0 {
@ -1547,7 +1546,11 @@ func CompareAndPullRequestPost(ctx *context.Context) {
return
}
ctx.JSONError(flashError)
return
default:
// It's an unexpected error.
// If it happens, we should add another case to handle it.
log.Error("Unexpected error of NewPullRequest: %T %s", err, err)
ctx.ServerError("CompareAndPullRequest", err)
}
ctx.ServerError("NewPullRequest", err)
return