Add gh aw checks command for deterministic PR CI state classification#18164
Add gh aw checks command for deterministic PR CI state classification#18164
gh aw checks command for deterministic PR CI state classification#18164Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
gh aw checks command for deterministic PR CI state classification
|
@copilot handle the case where the pr does not exist or invalid token (403) Ensure proper use of console helpers. |
There was a problem hiding this comment.
Pull request overview
This PR adds a new gh aw checks command to provide deterministic PR CI state classification, addressing false-green triage issues caused by inconsistent gh pr checks output.
Changes:
- Introduces a new
checkscommand that queries GitHub's Checks API and legacy Status API to return one of five normalized states:success,failed,pending,no_checks, orpolicy_blocked - Supports both machine-readable JSON output and human-readable text output with the normalized state written to stdout
- Includes comprehensive unit tests covering all state classifications, API interactions, and policy pattern matching
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/cli/checks_command.go | Implements the checks command with GitHub API integration, state classification logic, and output formatting |
| pkg/cli/checks_command_test.go | Provides 23 unit tests covering all five check states, policy detection patterns, and command structure validation |
| cmd/gh-aw/main.go | Registers the checks command in the analysis command group |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| func TestClassifyCheckState_NoChecks(t *testing.T) { | ||
| state := classifyCheckState([]PRCheckRun{}, []PRCommitStatus{}) | ||
| assert.Equal(t, CheckStateNoChecks, state, "empty check runs and statuses should yield no_checks") |
There was a problem hiding this comment.
Corrected spelling of 'yield' context: changed 'should yield no_checks' to 'should return no_checks' for consistency with error message conventions.
| assert.Equal(t, CheckStateNoChecks, state, "empty check runs and statuses should yield no_checks") | |
| assert.Equal(t, CheckStateNoChecks, state, "empty check runs and statuses should return no_checks") |
|
|
||
| for _, cr := range checkRuns { | ||
| switch cr.Status { | ||
| case "queued", "in_progress", "waiting", "requested", "pending": |
There was a problem hiding this comment.
The status value 'waiting' is not documented in GitHub's Check Runs API. The valid status values are 'queued', 'in_progress', and 'completed'. Consider verifying if 'waiting' and 'requested' are valid status values or if they should be removed.
| case "queued", "in_progress", "waiting", "requested", "pending": | |
| case "queued", "in_progress": |
| hasPending = true | ||
| case "completed": | ||
| switch cr.Conclusion { | ||
| case "failure", "timed_out", "startup_failure": |
There was a problem hiding this comment.
The conclusion value 'startup_failure' is not a standard GitHub Check Run conclusion. Valid conclusions include 'success', 'failure', 'neutral', 'cancelled', 'skipped', 'timed_out', 'action_required', 'stale'. Consider verifying this value or documenting its source.
| case "failure", "timed_out", "startup_failure": | |
| case "failure", "timed_out": |
|
@copilot avoid legacy APIs |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in 3c80679. Added
All three fetch functions ( |
Cross-repo automation was blocked on inconsistent
gh pr checksoutput—human-oriented text that causes false-green triage when "no checks" is silently treated as success.New command:
gh aw checks <pr-number>Queries the GitHub Checks API for a PR's head SHA, then emits a single normalized state:
successfailedpendingno_checkspolicy_blockedJSON output shape (
--json):{ "state": "failed", "pr_number": "42", "head_sha": "abc123", "check_runs": [{ "name": "test", "status": "completed", "conclusion": "failure", "html_url": "..." }], "total_count": 1 }Changes
pkg/cli/checks_command.go— Command implementation: resolves PR head SHA, fetches check runs from the GitHub Checks API, classifies state viaclassifyCheckState(), routes normalized state to stdout and formatted message to stderr.policy_blockedis detected via name-pattern matching against known GitHub branch-protection check names. IncludesclassifyGHAPIError()for user-friendly 404 (PR not found) and 403/401 (authentication) error messages usingconsole.FormatErrorWithSuggestions.pkg/cli/checks_command_test.go— 25 fixture-based unit tests covering all five states, policy pattern matching, command argument arity, and API error classification.cmd/gh-aw/main.go— Registerschecksin theanalysiscommand group alongsidelogs,audit, andhealth.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.