1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

Report error if API merge is not allowed (#12528)

#12496 demonstrated that the API merge needs to return some information as
to why a merge has been disallowed with a status code 422.

This PR ensures that a reason is always returned.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
zeripath 2020-08-19 22:35:06 +01:00 committed by GitHub
parent 1701d57fb2
commit a5440fcb1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -759,8 +759,18 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
return return
} }
if !pr.CanAutoMerge() || pr.HasMerged || pr.IsWorkInProgress() { if !pr.CanAutoMerge() {
ctx.Status(http.StatusMethodNotAllowed) ctx.Error(http.StatusMethodNotAllowed, "PR not in mergeable state", "Please try again later")
return
}
if pr.HasMerged {
ctx.Error(http.StatusMethodNotAllowed, "PR already merged", "")
return
}
if pr.IsWorkInProgress() {
ctx.Error(http.StatusMethodNotAllowed, "PR is a work in progress", "Work in progress PRs cannot be merged")
return return
} }
@ -812,7 +822,7 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) {
if err := pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil { if err := pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
if models.IsErrInvalidMergeStyle(err) { if models.IsErrInvalidMergeStyle(err) {
ctx.Status(http.StatusMethodNotAllowed) ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", models.MergeStyle(form.Do)))
return return
} else if models.IsErrMergeConflicts(err) { } else if models.IsErrMergeConflicts(err) {
conflictError := err.(models.ErrMergeConflicts) conflictError := err.(models.ErrMergeConflicts)