Route gpg key requests through api.Client - #13997
#13997Open
williammartin wants to merge 1 commit into
williammartin-route-ssh-key-api-clientcli/cli:williammartin-route-ssh-key-api-clientfrom
williammartin-route-gpg-key-apicli/cli:williammartin-route-gpg-key-apiCopy head branch name to clipboard
Open
Route gpg key requests through api.Client#13997williammartin wants to merge 1 commit intowilliammartin-route-ssh-key-api-clientcli/cli:williammartin-route-ssh-key-api-clientfrom williammartin-route-gpg-key-apicli/cli:williammartin-route-gpg-key-apiCopy head branch name to clipboard
williammartin wants to merge 1 commit into
williammartin-route-ssh-key-api-clientcli/cli:williammartin-route-ssh-key-api-clientfrom
williammartin-route-gpg-key-apicli/cli:williammartin-route-gpg-key-apiCopy head branch name to clipboard
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 605ad5d5-43b6-4332-b94b-6ae9b69bb3ff
williammartin
marked this pull request as ready for review
July 28, 2026 15:45
williammartin
requested review from
Copilot and
tidy-dev
and removed request for
a team
July 28, 2026 15:45
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates the gh gpg-key subcommands’ REST interactions from direct http.Client request handling to the shared api.Client wrapper, aligning this command set with the ongoing effort to consolidate API behavior behind a common client.
Changes:
- Refactored
gpg-key add,gpg-key delete, andgpg-key listHTTP helpers to useapi.NewClientFromHTTP(...).REST(...). - Added/expanded unit tests to validate error mapping (notably 404 -> insufficient scopes, and ordered handling of 422 cases for add).
- Updated test stubs to return JSON bodies where the API client expects JSON unmarshalling.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmd/gpg-key/add/http.go | Switch upload request to api.Client REST call and preserve prior sentinel error mapping behavior. |
| pkg/cmd/gpg-key/add/add_test.go | Add coverage for sentinel error mapping/order and adjust REST payload stubs to return JSON. |
| pkg/cmd/gpg-key/delete/http.go | Switch delete/list helpers to api.Client REST calls. |
| pkg/cmd/gpg-key/delete/delete_test.go | Add coverage for HTTP error surfacing from API client and fix go-gh HTTPError typing in stubs. |
| pkg/cmd/gpg-key/list/http.go | Switch list helper to api.Client REST call and preserve 404 -> scopes error mapping. |
| pkg/cmd/gpg-key/list/list_test.go | Add coverage for 404 mapping, generic HTTP error propagation, and user-scoped listing. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Low
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.
Description
Part of #13991
This PR migrates
gpg-key add,gpg-key deleteandgpg-key listto use theapi.Clientfor API interactions. There should be no user visible change.We add tests for three ordered sentinel errors:
404->errScopesMissing422mentioning a duplicatekey_id->errDuplicateKey422for an unarmored key ->errWrongFormat.This might be an overspecification of the tests, but it is behaviour that might be depended upon by someone out there, so at least worth knowing if it changed.
Two test stubs changed from
RESTPayload(200, "")toRESTPayload(200, "{}")because the api client expects to unmarshal json (where previously the body was just thrown away); The REST endpoints do return JSON. We also backfill tests for other error paths.Acceptance Test