feat: add gh models usage command for premium request billing#97
Open
marcelsafin wants to merge 2 commits into
Open
feat: add gh models usage command for premium request billing#97marcelsafin wants to merge 2 commits into
gh models usage command for premium request billing#97marcelsafin wants to merge 2 commits into
Conversation
f2262fc to
5f2d2a5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new gh models usage subcommand to fetch and display premium request usage/cost breakdown from the GitHub billing API, fitting into the CLI’s command suite alongside list, run, eval, etc.
Changes:
- Introduces
cmd/usagecommand to query/user+ premium request billing usage and render a table + totals/discount summary. - Adds a
Tokenfield tocommand.Configand plumbs it from the root command. - Adds initial unit tests for the new command and registers the subcommand in
cmd/root.go.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| pkg/command/config.go | Adds Token to shared command config; updates terminal-based constructor accordingly. |
| cmd/usage/usage.go | Implements gh models usage, including API calls, sorting, and output formatting. |
| cmd/usage/usage_test.go | Adds httptest-based coverage for common usage flows and output formatting. |
| cmd/root.go | Registers the new usage subcommand and passes auth token into config. |
Adds `gh models usage` command that shows premium request usage statistics from the GitHub billing API, with breakdown by model. Features: - Shows requests, gross cost, and net cost per model - Supports --today, --year, --month, --day flags - Sorted by gross amount descending - Color-coded discount/cost summary - Full test coverage with httptest mock server Closes github#81 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5f2d2a5 to
b7e4dd3
Compare
5ad684b to
b7e4dd3
Compare
…paths Addresses Copilot review feedback: - Validate --year/--month/--day before building API query (year >= 1, month 1-12, day 0-31) to fail fast with a clear message instead of letting the server return a confusing error. - Mark --today as mutually exclusive with --year/--month/--day so the effective query period is unambiguous (previously --today silently overrode user-supplied date flags). - Apply the GrossQuantity > 0 row filter to totals as well so the printed totals agree with the visible table rows. - Guard the (totalNet/totalGross)*100 division to avoid +Inf/NaN when totalGross is 0; emit a 'gross amount unavailable' note instead. - Make newTestServer match exact paths so tests fail loudly if the command starts hitting an unexpected endpoint. - Add explicit GreaterOrEqual checks before comparing sort indices so the assertion cannot pass when a substring is missing (-1 < 10). - Add tests for the NaN guard, mutual exclusion, and date validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
|
Addressed Copilot review feedback in 5ac332d: Behavior fixes
Test fixes
Already-addressed feedback (verified): @copilot review |
Author
|
All review threads are resolved and make check passes on 5ac332d. Ready for another maintainer pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
gh models usagecommand that displays premium request usage statistics from the GitHub billing API. This addresses #81.What it does
Features
--todayflag for daily usage--year,--month,--dayflags for specific periodsuserscope is missingAPI Used
GET /user— resolve usernameGET /users/{username}/settings/billing/premium_request/usage— premium request breakdownFiles Changed
cmd/usage/usage.go— new command implementationcmd/usage/usage_test.go— 7 test cases with httptest mock servercmd/root.go— register usage subcommandpkg/command/config.go— add Token field to Config for authTesting
All existing tests pass. New tests cover:
--todayflagCloses #81