summaryrefslogtreecommitdiffstats
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 14b8670a20..180d592e3d 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/pull"
+ pull_service "code.gitea.io/gitea/modules/pull"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
@@ -322,6 +323,12 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
setMergeTarget(ctx, pull)
+ if err = pull.LoadProtectedBranch(); err != nil {
+ ctx.ServerError("GetLatestCommitStatus", err)
+ return nil
+ }
+ ctx.Data["EnableStatusCheck"] = pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck
+
var headGitRepo *git.Repository
var headBranchExist bool
// HeadRepo may be missing
@@ -350,6 +357,18 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
ctx.Data["LatestCommitStatuses"] = commitStatuses
ctx.Data["LatestCommitStatus"] = models.CalcCommitStatus(commitStatuses)
}
+
+ if pull.ProtectedBranch != nil && pull.ProtectedBranch.EnableStatusCheck {
+ ctx.Data["is_context_required"] = func(context string) bool {
+ for _, c := range pull.ProtectedBranch.StatusCheckContexts {
+ if c == context {
+ return true
+ }
+ }
+ return false
+ }
+ ctx.Data["IsRequiredStatusCheckSuccess"] = pull_service.IsCommitStatusContextSuccess(commitStatuses, pull.ProtectedBranch.StatusCheckContexts)
+ }
}
}
@@ -608,6 +627,17 @@ 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 ctx.HasError() {
ctx.Flash.Error(ctx.Data["ErrorMsg"].(string))
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))