From 9f4411a91de45325d01488d623b7affde64aa6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Wed, 2 Oct 2024 11:42:35 +0200 Subject: [PATCH 1/2] fix: Ignore apply check(s) also if missing from rollup when determining mergeability minus apply --- server/events/vcs/github_client.go | 7 ++- server/events/vcs/github_client_test.go | 6 +++ .../ruleset-atlantis-apply-expected.json | 52 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 1129867064..ad409fd93d 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -710,8 +710,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 { @@ -771,6 +770,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 diff --git a/server/events/vcs/github_client_test.go b/server/events/vcs/github_client_test.go index ef97c64245..b676d8a0b0 100644 --- a/server/events/vcs/github_client_test.go +++ b/server/events/vcs/github_client_test.go @@ -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", diff --git a/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json b/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json new file mode 100644 index 0000000000..dda28256d8 --- /dev/null +++ b/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json @@ -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": [] + } + } + } + } + ] + } + } + } + } +} \ No newline at end of file From 787c82c804c62c23cf070d4f0be89c23d7fc8d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Lundstr=C3=B6m?= Date: Mon, 4 Nov 2024 11:29:36 +0100 Subject: [PATCH 2/2] Update server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon Heather <32168619+X-Guardian@users.noreply.github.com> Signed-off-by: Henrik Lundström --- .../ruleset-atlantis-apply-expected.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json b/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json index dda28256d8..f83b126d4e 100644 --- a/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json +++ b/server/events/vcs/testdata/github-pull-request-mergeability/ruleset-atlantis-apply-expected.json @@ -49,4 +49,4 @@ } } } -} \ No newline at end of file +}