diff --git a/server/events/vcs/github_client.go b/server/events/vcs/github_client.go index 608deda5d7..4286a1f671 100644 --- a/server/events/vcs/github_client.go +++ b/server/events/vcs/github_client.go @@ -402,16 +402,6 @@ func (g *GithubClient) GetCombinedStatusMinusApply(repo models.Repo, pull *githu return false, errors.Wrap(err, "getting combined status") } - //iterate over statuses - return false if we find one that isn't "apply" and doesn't have state = "success" - for _, r := range status.Statuses { - if strings.HasPrefix(*r.Context, fmt.Sprintf("%s/%s", vcstatusname, command.Apply.String())) { - continue - } - if *r.State != "success" { - return false, nil - } - } - //get required status checks required, _, err := g.client.Repositories.GetBranchProtection(context.Background(), repo.Owner, repo.Name, *pull.Base.Ref) if err != nil { @@ -422,6 +412,16 @@ func (g *GithubClient) GetCombinedStatusMinusApply(repo models.Repo, pull *githu return true, nil } + //iterate over statuses - return false if we find one that isn't "apply", is a required status and doesn't have state = "success" + for _, r := range status.Statuses { + if strings.HasPrefix(*r.Context, fmt.Sprintf("%s/%s", vcstatusname, command.Apply.String())) { + continue + } + if isRequiredCheck(*r.Context, required.RequiredStatusChecks.Contexts) && *r.State != "success" { + return false, nil + } + } + //check check suite/check run api checksuites, _, err := g.client.Checks.ListCheckSuitesForRef(context.Background(), *pull.Head.Repo.Owner.Login, repo.Name, *pull.Head.Ref, nil) if err != nil { diff --git a/server/events/vcs/testdata/github-branch-protection-required-checks.json b/server/events/vcs/testdata/github-branch-protection-required-checks.json index 9f422db9ea..873f3ca655 100644 --- a/server/events/vcs/testdata/github-branch-protection-required-checks.json +++ b/server/events/vcs/testdata/github-branch-protection-required-checks.json @@ -4,13 +4,18 @@ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks", "strict": true, "contexts": [ - "atlantis/apply" + "atlantis/apply", + "atlantis/plan" ], "contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts", "checks": [ { "context": "atlantis/apply", "app_id": 123456 + }, + { + "context": "atlantis/plan", + "app_id": 123456 } ] } diff --git a/server/events/vcs/testdata/github-commit-status-full.json b/server/events/vcs/testdata/github-commit-status-full.json index a042101c40..63c880507d 100644 --- a/server/events/vcs/testdata/github-commit-status-full.json +++ b/server/events/vcs/testdata/github-commit-status-full.json @@ -72,6 +72,18 @@ "context": "atlantis/apply", "created_at": "2022-02-10T15:26:28Z", "updated_at": "2022-02-10T15:26:28Z" + }, + { + "url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e", + "avatar_url": "https://avatars.githubusercontent.com/u/583231?v=4", + "id": 16230308153, + "node_id": "SC_kwDOFRFvL88AAAADx2bAWS", + "state": "failure", + "description": "Failed to report metrics.", + "target_url": "https://localhost/jobs/octocat/Hello-World/1/project2", + "context": "report-metrics", + "created_at": "2022-02-10T15:26:27Z", + "updated_at": "2022-02-10T15:26:27Z" } ], "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",