diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2020-01-11 08:29:34 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2020-01-11 02:29:34 -0500 |
commit | 32fb813133c74ddc3af1964e81fff72fea4f24f1 (patch) | |
tree | 31eec446f12e448d7cf398db43620606e9704ff1 /routers/api/v1/repo/pull.go | |
parent | 4d06d10dbafe7cfd404889b636d8e243058ee96f (diff) | |
download | gitea-32fb813133c74ddc3af1964e81fff72fea4f24f1.tar.gz gitea-32fb813133c74ddc3af1964e81fff72fea4f24f1.zip |
Allow repo admin to merge PR regardless of review status (#9611)
* Allow repo admin to merge even if review is not ok.
Diffstat (limited to 'routers/api/v1/repo/pull.go')
-rw-r--r-- | routers/api/v1/repo/pull.go | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 8e6677116d..6b643371e5 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -600,22 +600,45 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { return } - if !pr.CanAutoMerge() || pr.HasMerged || pr.IsWorkInProgress() { - ctx.Status(http.StatusMethodNotAllowed) + perm, err := models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User) + if err != nil { + ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err) return } - isPass, err := pull_service.IsPullCommitStatusPass(pr) + allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, perm, ctx.User) if err != nil { - ctx.Error(http.StatusInternalServerError, "IsPullCommitStatusPass", err) + ctx.Error(http.StatusInternalServerError, "IsUSerAllowedToMerge", err) + return + } + if !allowedMerge { + ctx.Error(http.StatusMethodNotAllowed, "Merge", "User not allowed to merge PR") return } - if !isPass && !ctx.IsUserRepoAdmin() { + if !pr.CanAutoMerge() || pr.HasMerged || pr.IsWorkInProgress() { ctx.Status(http.StatusMethodNotAllowed) return } + if err := pull_service.CheckPRReadyToMerge(pr); err != nil { + if !models.IsErrNotAllowedToMerge(err) { + ctx.Error(http.StatusInternalServerError, "CheckPRReadyToMerge", err) + return + } + if form.ForceMerge != nil && *form.ForceMerge { + if isRepoAdmin, err := models.IsUserRepoAdmin(pr.BaseRepo, ctx.User); err != nil { + ctx.Error(http.StatusInternalServerError, "IsUserRepoAdmin", err) + return + } else if !isRepoAdmin { + ctx.Error(http.StatusMethodNotAllowed, "Merge", "Only repository admin can merge if not all checks are ok (force merge)") + } + } else { + ctx.Error(http.StatusMethodNotAllowed, "PR is not ready to be merged", err) + return + } + } + if len(form.Do) == 0 { form.Do = string(models.MergeStyleMerge) } |