Disallow merge when required checked are missing (#29143)

fixes #21892 

This PR disallows merging a PR when not all commit status contexts
configured in the branch protection are met.

Previously, the PR was happy to merge when one commit status was
successful and the other contexts weren't reported.

Any feedback is welcome, first time Go :-)
I'm also not sure if the changes in the template break something else

Given the following branch protection:


![branch_protection](f871b4e4-138b-435a-b496-f9ad432e3dec)

This was shown before the change:


![before](60424ff0-ee09-4fa0-856e-64e6e3fb0612)

With the change, it is now shown as this:


![after](4e464142-efb1-4889-8166-eb3be26c8f3d)

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Markus Amshove 2024-02-19 10:57:08 +01:00 committed by GitHub
parent 0ea8de2d07
commit a11ccc9fcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 44 additions and 1 deletions

View file

@ -51,6 +51,10 @@ func MergeRequiredContextsCommitStatus(commitStatuses []*git_model.CommitStatus,
}
}
if matchedCount != len(requiredContexts) {
return structs.CommitStatusPending
}
if matchedCount == 0 {
status := git_model.CalcCommitStatus(commitStatuses)
if status != nil {