Skip to content

Commit acf4d88

Browse files
henriklundstromkvanzuijlen
authored andcommitted
fix: Ignore apply check(s) even if missing from rollup when determining mergeability for GitHub (runatlantis#4974)
Signed-off-by: Henrik Lundström <[email protected]> Signed-off-by: kvanzuijlen <[email protected]>
1 parent 5d55eaa commit acf4d88

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

server/events/vcs/github_client.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,7 @@ func CheckRunPassed(checkRun CheckRun) bool {
714714
}
715715

716716
func StatusContextPassed(statusContext StatusContext, vcsstatusname string) bool {
717-
return strings.HasPrefix(string(statusContext.Context), fmt.Sprintf("%s/%s", vcsstatusname, command.Apply.String())) ||
718-
statusContext.State == "SUCCESS"
717+
return statusContext.State == "SUCCESS"
719718
}
720719

721720
func ExpectedCheckPassed(expectedContext githubv4.String, checkRuns []CheckRun, statusContexts []StatusContext, vcsstatusname string) bool {
@@ -775,6 +774,10 @@ func (g *GithubClient) IsMergeableMinusApply(logger logging.SimpleLogging, repo
775774
// Go through all checks and workflows required by branch protection or rulesets
776775
// Make sure that they can all be found in the statusCheckRollup and that they all pass
777776
for _, requiredCheck := range requiredChecks {
777+
if strings.HasPrefix(string(requiredCheck), fmt.Sprintf("%s/%s", vcsstatusname, command.Apply.String())) {
778+
// Ignore atlantis apply check(s)
779+
continue
780+
}
778781
if !ExpectedCheckPassed(requiredCheck, checkRuns, statusContexts, vcsstatusname) {
779782
logger.Debug("%s: Expected Required Check: %s", notMergeablePrefix, requiredCheck)
780783
return false, nil

server/events/vcs/github_client_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,12 @@ func TestGithubClient_PullIsMergeableWithAllowMergeableBypassApply(t *testing.T)
691691
`"APPROVED"`,
692692
false,
693693
},
694+
{
695+
"blocked",
696+
"ruleset-atlantis-apply-expected.json",
697+
`"APPROVED"`,
698+
true,
699+
},
694700
{
695701
"blocked",
696702
"ruleset-optional-check-failed.json",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequest": {
5+
"reviewDecision": null,
6+
"baseRef": {
7+
"branchProtectionRule": {
8+
"requiredStatusChecks": []
9+
},
10+
"rules": {
11+
"pageInfo": {
12+
"endCursor": "QWERTY",
13+
"hasNextPage": false
14+
},
15+
"nodes": [
16+
{
17+
"type": "REQUIRED_STATUS_CHECKS",
18+
"repositoryRuleset": {
19+
"enforcement": "ACTIVE"
20+
},
21+
"parameters": {
22+
"requiredStatusChecks": [
23+
{
24+
"context": "atlantis/apply"
25+
}
26+
]
27+
}
28+
}
29+
]
30+
}
31+
},
32+
"commits": {
33+
"nodes": [
34+
{
35+
"commit": {
36+
"statusCheckRollup": {
37+
"contexts": {
38+
"pageInfo": {
39+
"endCursor": "QWERTY",
40+
"hasNextPage": false
41+
},
42+
"nodes": []
43+
}
44+
}
45+
}
46+
}
47+
]
48+
}
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)