Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ignore apply check(s) even if missing from rollup when determining mergeability for GitHub #4974

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,7 @@ func CheckRunPassed(checkRun CheckRun) bool {
}

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

func ExpectedCheckPassed(expectedContext githubv4.String, checkRuns []CheckRun, statusContexts []StatusContext, vcsstatusname string) bool {
Expand Down Expand Up @@ -772,6 +771,10 @@ func (g *GithubClient) IsMergeableMinusApply(logger logging.SimpleLogging, repo
// Go through all checks and workflows required by branch protection or rulesets
// Make sure that they can all be found in the statusCheckRollup and that they all pass
for _, requiredCheck := range requiredChecks {
if strings.HasPrefix(string(requiredCheck), fmt.Sprintf("%s/%s", vcsstatusname, command.Apply.String())) {
// Ignore atlantis apply check(s)
continue
}
if !ExpectedCheckPassed(requiredCheck, checkRuns, statusContexts, vcsstatusname) {
logger.Debug("%s: Expected Required Check: %s", notMergeablePrefix, requiredCheck)
return false, nil
Expand Down
6 changes: 6 additions & 0 deletions server/events/vcs/github_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,12 @@ func TestGithubClient_PullIsMergeableWithAllowMergeableBypassApply(t *testing.T)
`"APPROVED"`,
false,
},
{
"blocked",
"ruleset-atlantis-apply-expected.json",
`"APPROVED"`,
true,
},
{
"blocked",
"ruleset-optional-check-failed.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"data": {
"repository": {
"pullRequest": {
"reviewDecision": null,
"baseRef": {
"branchProtectionRule": {
"requiredStatusChecks": []
},
"rules": {
"pageInfo": {
"endCursor": "QWERTY",
"hasNextPage": false
},
"nodes": [
{
"type": "REQUIRED_STATUS_CHECKS",
"repositoryRuleset": {
"enforcement": "ACTIVE"
},
"parameters": {
"requiredStatusChecks": [
{
"context": "atlantis/apply"
}
]
}
}
]
}
},
"commits": {
"nodes": [
{
"commit": {
"statusCheckRollup": {
"contexts": {
"pageInfo": {
"endCursor": "QWERTY",
"hasNextPage": false
},
"nodes": []
}
}
}
}
]
}
}
}
}
}
henriklundstrom marked this conversation as resolved.
Show resolved Hide resolved