add-wizard: detect org Copilot billing and pre-select/disable copilot-requests accordingly#39810
Conversation
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
…hen unavailable Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
|
✅ PR Code Quality Reviewer completed the code quality review. |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅ |
|
|
||
| // Detect org Copilot CLI billing status before building the form. | ||
| // c.RepoOverride is in "owner/repo" format; we need just the org login. | ||
| copilotRequestsLabel := "Use copilot-requests (org's Copilot billing, no PAT)" |
There was a problem hiding this comment.
@copilot refactor copilot-requests probing into separate file/helper with dedicated tests
There was a problem hiding this comment.
Done in the latest commit. copilot_billing_check.go now owns the full probe flow:
detectOrgCopilotCLIBillingWithClient— low-level HTTP call, returns raw"cli"stringorgCopilotBillingProbeResultstruct — carriesBillingStatus,LabelSuffix,Disabled,InfoNoteprobeCopilotBillingForOrgWithClient— testable core: calls the HTTP helper and maps the result to UI hintsprobeCopilotBillingForOrg— public entry point, creates a REST client and delegates
The inline switch in selectCopilotAuthMethod() is replaced by a single probeCopilotBillingForOrg call. As a side effect, unknown policy values (e.g. "unconfigured") now show the actual status in the label instead of always saying "is disabled". TestProbeCopilotBillingForOrgWithClient covers all 6 cases plus a network-error test.
|
✅ Test Quality Sentinel completed test quality analysis. |
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. |
There was a problem hiding this comment.
Pull request overview
This PR improves the gh aw add interactive wizard for the Copilot engine by preflighting an org’s Copilot CLI billing status via GET /orgs/{org}/copilot/billing and using the result to pre-select and/or block the copilot-requests auth path before rendering the form.
Changes:
- Added a REST-based billing detection helper with a 3-second timeout plus unit tests covering success, non-200, and network error cases.
- Updated the Copilot auth method prompt to preflight billing status, adjust option ordering/labels, and prevent submission when billing is confirmed unavailable.
- Stored the detected billing status on
AddInteractiveConfigduring the auth selection step.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/copilot_billing_check.go |
Introduces org Copilot CLI billing detection via the GitHub REST API with a timeout. |
pkg/cli/copilot_billing_check_test.go |
Adds unit tests for billing detection using httptest.Server + a redirecting transport. |
pkg/cli/add_interactive_engine.go |
Preflights billing status and updates the huh select options/validation accordingly. |
pkg/cli/add_interactive_orchestrator.go |
Adds a config field to retain the detected billing status. |
.github/workflows/example-failure-category-filter.lock.yml |
Updates a lockfile line comment placement. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 2
| default: // "disabled" or any other policy value | ||
| copilotRequestsLabel += " [not available — org Copilot CLI billing is disabled]" | ||
| copilotRequestsDisabled = true |
There was a problem hiding this comment.
Outdated — fixed in the refactor commit (c244b13): non-"enabled" values now display the actual policy string in the label, e.g. [not available — org Copilot CLI billing: unconfigured].
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (265 new lines in
📄 Draft ADR-39810 (copy into
|
🧪 Test Quality Sentinel Report✅ Test Quality Score: 81/100 — Excellent
📊 Metrics & Test Classification (7 tests analyzed)
Go: 2 Build tags:
|
|
@copilot run pr-finisher skill |
There was a problem hiding this comment.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer
There was a problem hiding this comment.
🔎 Code quality review by PR Code Quality Reviewer
…ling_check.go Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ed option ordering Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
The Copilot auth method prompt in the add-wizard showed copilot-requests and PAT as equally-selectable options regardless of whether the org's Copilot CLI billing was actually available. This adds a 3-second preflight call to
GET /orgs/{org}/copilot/billingthat adjusts the form before it renders.Behaviour by detection result
cli: "enabled"[recommended — org Copilot CLI billing enabled]cli: "disabled"[not available — org Copilot CLI billing: disabled]+ validation guard preventing submission"unconfigured")[not available — org Copilot CLI billing: unconfigured]+ validation guard preventing submission404 is treated as inconclusive (not disabled) because only org owners get a 200 — a 404 could simply mean the caller isn't an org owner.
New files
pkg/cli/copilot_billing_check.go— contains two layers:detectOrgCopilotCLIBillingWithClient(ctx, orgLogin, client)— low-level HTTP call; returns the raw"cli"field value or("", err)for any non-200/error.orgCopilotBillingProbeResultstruct — carriesBillingStatus,LabelSuffix,Disabled,InfoNotefor use by the form.probeCopilotBillingForOrg(ctx, orgLogin)— public entry point; creates a REST client and delegates toprobeCopilotBillingForOrgWithClient.probeCopilotBillingForOrgWithClient(ctx, orgLogin, client)— testable core; calls the HTTP helper and maps the result to UI hints.pkg/cli/copilot_billing_check_test.go— unit tests viahttptest.NewServer+ customhttp.RoundTrippercovering both the low-level detection and the full probe: 200+enabled, 200+disabled, 200+unknown value, 404, 403, missing field, network error.Modified files
pkg/cli/add_interactive_engine.go—selectCopilotAuthMethod()now callsprobeCopilotBillingForOrgbefore building thehuhform, usingstrings.Cutonc.RepoOverrideto extract the org login. The inline status-to-UI mapping logic has been removed in favour of the helper.pkg/cli/add_interactive_orchestrator.go—AddInteractiveConfiggains acopilotCLIBillingStatus stringfield ("enabled"/"disabled"/ other policy value /"") set during the auth method step.