Skip to content

Commit 668d3d0

Browse files
yzzyxlunny
authored andcommitted
If no specific context is required for status check, require an overall success (#8318)
Signed-off-by: Elias Norberg <[email protected]>
1 parent 0d2566b commit 668d3d0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

options/locale/locale_en-US.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ settings.protect_merge_whitelist_committers_desc = Allow only whitelisted users
13261326
settings.protect_merge_whitelist_users = Whitelisted users for merging:
13271327
settings.protect_merge_whitelist_teams = Whitelisted teams for merging:
13281328
settings.protect_check_status_contexts = Enable Status Check
1329-
settings.protect_check_status_contexts_desc = Require status checks to pass before merging Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed.
1329+
settings.protect_check_status_contexts_desc = Require status checks to pass before merging Choose which status checks must pass before branches can be merged into a branch that matches this rule. When enabled, commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed. If no contexts are selected, the last commit must be successful regardless of context.
13301330
settings.protect_check_status_contexts_list = Status checks found in the last week for this repository
13311331
settings.protect_required_approvals = Required approvals:
13321332
settings.protect_required_approvals_desc = Allow only to merge pull request with enough positive reviews of whitelisted users or teams.

services/pull/commit_status.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ package pull
88
import (
99
"code.gitea.io/gitea/models"
1010
"code.gitea.io/gitea/modules/git"
11-
1211
"github.com/pkg/errors"
1312
)
1413

1514
// IsCommitStatusContextSuccess returns true if all required status check contexts succeed.
1615
func IsCommitStatusContextSuccess(commitStatuses []*models.CommitStatus, requiredContexts []string) bool {
16+
// If no specific context is required, require that last commit status is a success
17+
if len(requiredContexts) == 0 {
18+
status := models.CalcCommitStatus(commitStatuses)
19+
if status == nil || status.State != models.CommitStatusSuccess {
20+
return false
21+
}
22+
return true
23+
}
24+
1725
for _, ctx := range requiredContexts {
1826
var found bool
1927
for _, commitStatus := range commitStatuses {

0 commit comments

Comments
 (0)