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/repo | |
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/repo')
-rw-r--r-- | routers/repo/issue.go | 24 | ||||
-rw-r--r-- | routers/repo/pull.go | 32 |
2 files changed, 38 insertions, 18 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 0a78e06b41..ce3eb5bd2c 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -903,6 +903,7 @@ func ViewIssue(ctx *context.Context) { pull := issue.PullRequest pull.Issue = issue canDelete := false + ctx.Data["AllowMerge"] = false if ctx.IsSigned { if err := pull.GetHeadRepo(); err != nil { @@ -923,6 +924,20 @@ func ViewIssue(ctx *context.Context) { } } } + + if err := pull.GetBaseRepo(); err != nil { + log.Error("GetBaseRepo: %v", err) + } + perm, err := models.GetUserRepoPermission(pull.BaseRepo, ctx.User) + if err != nil { + ctx.ServerError("GetUserRepoPermission", err) + return + } + ctx.Data["AllowMerge"], err = pull_service.IsUserAllowedToMerge(pull, perm, ctx.User) + if err != nil { + ctx.ServerError("IsUserAllowedToMerge", err) + return + } } prUnit, err := repo.GetUnit(models.UnitTypePullRequests) @@ -932,15 +947,6 @@ func ViewIssue(ctx *context.Context) { } prConfig := prUnit.PullRequestsConfig() - ctx.Data["AllowMerge"] = ctx.Repo.CanWrite(models.UnitTypeCode) - if err := pull.CheckUserAllowedToMerge(ctx.User); err != nil { - if !models.IsErrNotAllowedToMerge(err) { - ctx.ServerError("CheckUserAllowedToMerge", err) - return - } - ctx.Data["AllowMerge"] = false - } - // Check correct values and select default if ms, ok := ctx.Data["MergeStyle"].(models.MergeStyle); !ok || !prConfig.IsMergeStyleAllowed(ms) { diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 93e98e0c33..901ab48856 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -600,6 +600,16 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { pr := issue.PullRequest + allowedMerge, err := pull_service.IsUserAllowedToMerge(pr, ctx.Repo.Permission, ctx.User) + if err != nil { + ctx.ServerError("IsUserAllowedToMerge", err) + return + } + if !allowedMerge { + ctx.NotFound("MergePullRequest", nil) + return + } + if !pr.CanAutoMerge() || pr.HasMerged { ctx.NotFound("MergePullRequest", nil) return @@ -611,15 +621,19 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) { return } - isPass, err := pull_service.IsPullCommitStatusPass(pr) - if err != nil { - ctx.ServerError("IsPullCommitStatusPass", err) - return - } - if !isPass && !ctx.IsUserRepoAdmin() { - ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_status_check")) - ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index)) - return + if err := pull_service.CheckPRReadyToMerge(pr); err != nil { + if !models.IsErrNotAllowedToMerge(err) { + ctx.ServerError("Merge PR status", err) + return + } + if isRepoAdmin, err := models.IsUserRepoAdmin(pr.BaseRepo, ctx.User); err != nil { + ctx.ServerError("IsUserRepoAdmin", err) + return + } else if !isRepoAdmin { + ctx.Flash.Error(ctx.Tr("repo.pulls.no_merge_not_ready")) + ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index)) + return + } } if ctx.HasError() { |