Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 10 additions & 10 deletions server/events/vcs/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
Expand Down
12 changes: 12 additions & 0 deletions server/events/vcs/testdata/github-commit-status-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down