Skip to content
Merged
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
12 changes: 11 additions & 1 deletion cmd/wait-for-github/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,22 @@ func parsePRArguments(ctx context.Context, cmd *cli.Command, logger *slog.Logger
}
logger.InfoContext(ctx, "waiting for PR to be merged/closed", "owner", owner, "repo", repo, "pr", n)

// Filter out empty strings from excludes. When GITHUB_CI_EXCLUDE is set to
// an empty string, urfave/cli splits it into a slice containing one empty
// string. Remove these so that an empty env var is treated the same as unset.
var excludes []string
for _, e := range cmd.StringSlice("exclude") {
if e != "" {
excludes = append(excludes, e)
}
}

return prConfig{
owner: owner,
repo: repo,
pr: n,
commitInfoFile: cmd.String("commit-info-file"),
excludes: cmd.StringSlice("exclude"),
excludes: excludes,
actionRetries: int(cmd.Int("action-retries")),
writer: osFileWriter{},
}, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ func (c GHClient) GetCIStatus(ctx context.Context, owner, repoName, ref string,

for _, node := range nodes {
isCheckFailure := strings.ToLower(node.CheckRun.Conclusion) == RunConclusionFailure
isStatusFailure := strings.ToLower(node.StatusContext.State) == StatusStateFailure
isStatusFailure := strings.ToLower(node.StatusContext.State) == StatusStateFailure ||
strings.ToLower(node.StatusContext.State) == StatusStateError

checkRunName := node.CheckRun.Name
statusContextName := node.StatusContext.Context
Expand Down
65 changes: 65 additions & 0 deletions internal/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,71 @@ func TestGetCIStatus(t *testing.T) {
excludedChecks: []string{"deployment", "workflow"},
expectedStatus: CIStatusFailed,
},
{
name: "status context with error state treated as failure",
mockGraphQL: `
{
"data": {
"repository": {
"object": {
"statusCheckRollup": {
"state": "FAILURE",
"contexts": {
"checkRunCount": 0,
"statusContextCount": 1,
"nodes": [
{
"__typename": "StatusContext",
"context": "dev-policy-bot: master",
"state": "ERROR"
}
],
"pageInfo": {
"hasNextPage": false,
"endCursor": null
}
}
}
}
}
}
}
`,
expectedStatus: CIStatusFailed,
},
{
name: "excluded status context with error state",
mockGraphQL: `
{
"data": {
"repository": {
"object": {
"statusCheckRollup": {
"state": "FAILURE",
"contexts": {
"checkRunCount": 0,
"statusContextCount": 1,
"nodes": [
{
"__typename": "StatusContext",
"context": "dev-policy-bot: master",
"state": "ERROR"
}
],
"pageInfo": {
"hasNextPage": false,
"endCursor": null
}
}
}
}
}
}
}
`,
excludedChecks: []string{"dev-policy-bot: master"},
expectedStatus: CIStatusPassed,
},
}

for _, tt := range tests {
Expand Down
Loading