Skip to content

Commit cc2a6c1

Browse files
authored
Fix merge dialog on protected branch with missing required statuses (#11074) (#11084)
It is possible for misconfigured protected branches to have required status checks that are not in any of the current statuses: Pending, Success, Error, Failure, or Warning - presumably because the CI has not contacted us as yet. Fix #10636 by adding case: missing StatusChecks when these are missing
1 parent b5fd55d commit cc2a6c1

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ pulls.data_broken = This pull request is broken due to missing fork information.
10621062
pulls.files_conflicted = This pull request has changes conflicting with the target branch.
10631063
pulls.is_checking = "Merge conflict checking is in progress. Try again in few moments."
10641064
pulls.required_status_check_failed = Some required checks were not successful.
1065+
pulls.required_status_check_missing = Some required checks are missing.
10651066
pulls.required_status_check_administrator = As an administrator, you may still merge this pull request.
10661067
pulls.blocked_by_approvals = "This Pull Request doesn't have enough approvals yet. %d of %d approvals granted."
10671068
pulls.blocked_by_rejection = "This Pull Request has changes requested by an official reviewer."

routers/repo/pull.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
413413
}
414414
return false
415415
}
416-
state := pull_service.MergeRequiredContextsCommitStatus(commitStatuses, pull.ProtectedBranch.StatusCheckContexts)
417-
ctx.Data["RequiredStatusCheckState"] = state
418-
ctx.Data["IsRequiredStatusCheckSuccess"] = state.IsSuccess()
416+
ctx.Data["RequiredStatusCheckState"] = pull_service.MergeRequiredContextsCommitStatus(commitStatuses, pull.ProtectedBranch.StatusCheckContexts)
419417
}
420418

421419
ctx.Data["HeadBranchMovedOn"] = headBranchSha != sha

templates/repo/issue/view_content/pull.tmpl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
{{else if .IsBlockedByApprovals}}red
4444
{{else if .IsBlockedByRejection}}red
4545
{{else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsFailure .RequiredStatusCheckState.IsError)}}red
46-
{{else if and .EnableStatusCheck (or .RequiredStatusCheckState.IsPending .RequiredStatusCheckState.IsWarning)}}yellow
46+
{{else if and .EnableStatusCheck (or (not $.LatestCommitStatus) .RequiredStatusCheckState.IsPending .RequiredStatusCheckState.IsWarning)}}yellow
4747
{{else if .Issue.PullRequest.IsChecking}}yellow
4848
{{else if .Issue.PullRequest.CanAutoMerge}}green
4949
{{else}}red{{end}}"><span class="mega-octicon octicon-git-merge"></span></a>
@@ -112,7 +112,7 @@
112112
<span class="octicon octicon-sync"></span>
113113
{{$.i18n.Tr "repo.pulls.is_checking"}}
114114
</div>
115-
{{else if and (not .Issue.PullRequest.CanAutoMerge) .EnableStatusCheck (not .IsRequiredStatusCheckSuccess)}}
115+
{{else if and (not .Issue.PullRequest.CanAutoMerge) .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}}
116116
<div class="item text red">
117117
<span class="octicon octicon-x"></span>
118118
{{$.i18n.Tr "repo.pulls.required_status_check_failed"}}
@@ -123,9 +123,14 @@
123123
<span class="octicon octicon-x"></span>
124124
{{$.i18n.Tr "repo.pulls.required_status_check_failed"}}
125125
</div>
126+
{{else if and .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}}
127+
<div class="item text red">
128+
<span class="octicon octicon-x"></span>
129+
{{$.i18n.Tr "repo.pulls.required_status_check_missing"}}
130+
</div>
126131
{{end}}
127-
{{if or $.IsRepoAdmin (not .EnableStatusCheck) .IsRequiredStatusCheckSuccess}}
128-
{{if and $.IsRepoAdmin .EnableStatusCheck (not .IsRequiredStatusCheckSuccess)}}
132+
{{if or $.IsRepoAdmin (not .EnableStatusCheck) .RequiredStatusCheckState.IsSuccess}}
133+
{{if and $.IsRepoAdmin .EnableStatusCheck (not .RequiredStatusCheckState.IsSuccess)}}
129134
<div class="item text yellow">
130135
<span class="octicon octicon-primitive-dot"></span>
131136
{{$.i18n.Tr "repo.pulls.required_status_check_administrator"}}

0 commit comments

Comments
 (0)