mirror of
https://github.com/go-gitea/gitea
synced 2025-07-04 17:47:19 +00:00
Backport #34815 Fix #34504 Since one required context can match more than one commit statuses, we should not directly compare the lengths of `requiredCommitStatuses` and `requiredContexts`
This commit is contained in:
@ -35,15 +35,16 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, gp := range requiredContextsGlob {
|
for _, gp := range requiredContextsGlob {
|
||||||
var targetStatus structs.CommitStatusState
|
var targetStatuses []*git_model.CommitStatus
|
||||||
for _, commitStatus := range commitStatuses {
|
for _, commitStatus := range commitStatuses {
|
||||||
if gp.Match(commitStatus.Context) {
|
if gp.Match(commitStatus.Context) {
|
||||||
targetStatus = commitStatus.State
|
targetStatuses = append(targetStatuses, commitStatus)
|
||||||
matchedCount++
|
matchedCount++
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
targetStatus := git_model.CalcCommitStatus(targetStatuses).State
|
||||||
|
|
||||||
// If required rule not match any action, then it is pending
|
// If required rule not match any action, then it is pending
|
||||||
if targetStatus == "" {
|
if targetStatus == "" {
|
||||||
if structs.CommitStatusPending.NoBetterThan(returnedStatus) {
|
if structs.CommitStatusPending.NoBetterThan(returnedStatus) {
|
||||||
|
@ -30,6 +30,11 @@ func TestMergeRequiredContextsCommitStatus(t *testing.T) {
|
|||||||
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
||||||
{Context: "Build 2t", State: structs.CommitStatusFailure},
|
{Context: "Build 2t", State: structs.CommitStatusFailure},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
||||||
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
||||||
|
{Context: "Build 2t", State: structs.CommitStatusFailure},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
{Context: "Build 1", State: structs.CommitStatusSuccess},
|
||||||
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
{Context: "Build 2", State: structs.CommitStatusSuccess},
|
||||||
@ -45,6 +50,7 @@ func TestMergeRequiredContextsCommitStatus(t *testing.T) {
|
|||||||
{"Build*"},
|
{"Build*"},
|
||||||
{"Build*", "Build 2t*"},
|
{"Build*", "Build 2t*"},
|
||||||
{"Build*", "Build 2t*"},
|
{"Build*", "Build 2t*"},
|
||||||
|
{"Build*"},
|
||||||
{"Build*", "Build 2t*", "Build 3*"},
|
{"Build*", "Build 2t*", "Build 3*"},
|
||||||
{"Build*", "Build *", "Build 2t*", "Build 1*"},
|
{"Build*", "Build *", "Build 2t*", "Build 1*"},
|
||||||
}
|
}
|
||||||
@ -53,6 +59,7 @@ func TestMergeRequiredContextsCommitStatus(t *testing.T) {
|
|||||||
structs.CommitStatusSuccess,
|
structs.CommitStatusSuccess,
|
||||||
structs.CommitStatusPending,
|
structs.CommitStatusPending,
|
||||||
structs.CommitStatusFailure,
|
structs.CommitStatusFailure,
|
||||||
|
structs.CommitStatusFailure,
|
||||||
structs.CommitStatusPending,
|
structs.CommitStatusPending,
|
||||||
structs.CommitStatusSuccess,
|
structs.CommitStatusSuccess,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user