Repository navigation
--attach stack 1/8: Report what kind of token is active - #14177
Merged
Merged
Conversation
--attach stack 1/8: Report what kind of token is active
BagToad
marked this pull request as ready for review
August 18, 2026 05:56
Contributor
There was a problem hiding this comment.
Pull request overview
Adds authentication and repository metadata prerequisites for a future attach workflow.
Changes:
- Classifies active tokens by credential prefix.
- Exposes repository database IDs and viewer permissions for issues and pull requests.
- Extends GraphQL selections and tests for the new metadata.
Show a summary per file
| File | Description |
|---|---|
internal/gh/gh.go |
Defines token types and authentication interface support. |
internal/config/config.go |
Implements active-token classification. |
internal/config/auth_config_test.go |
Tests token classification. |
api/query_builder.go |
Selects repository metadata in issue/PR queries. |
api/query_builder_test.go |
Tests repository query fragments. |
api/queries_repo.go |
Adds repository database IDs to API queries. |
api/queries_repo_test.go |
Verifies database ID querying and decoding. |
api/queries_pr.go |
Exposes PR repository metadata. |
api/queries_pr_test.go |
Tests PR repository decoding and accessors. |
api/queries_issue.go |
Exposes issue repository metadata. |
api/queries_issue_test.go |
Tests issue repository decoding and accessors. |
api/export_pr_test.go |
Guards existing head-repository JSON output. |
Review details
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 12/12 changed files
- Comments generated: 2
- Review effort level: Balanced
Closed
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
BagToad
force-pushed
the
bagtoad/attach-prerequisites
branch
from
August 18, 2026 14:55
5cab41b to
8fb0321
Compare
Closed
4 of 9 tasks
babakks
reviewed
Aug 19, 2026
babakks
left a comment
Member
There was a problem hiding this comment.
Thanks for putting this together! 🙏
Overall this looks good to me. The token type reporting is clean, and the repository id and viewer permission additions are well covered by tests. I left a few small inline notes (mostly nitpicks and a couple of questions), but nothing blocking.
babakks
approved these changes
Aug 19, 2026
Closed
2 tasks
1 task
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.
Part of the pull request stack tracked in #14186.
Description
This is the first layer of an eight part stack. The full stack adds an
--attachflag to six issue and pull request commands. The flag uploads a local media file to GitHub and puts it into the markdown body. If the text already references the local path,ghrewrites that path to point at the uploaded asset. Otherwiseghappends the file at the end.This pull request does not change anything a user can see. It adds two things the upper layers need.
The upload endpoint only accepts some kinds of credential. The first commit adds a token type to the
ghpackage and a method on the auth config that reports what kind of credential is active for a host, told by the token prefix. A caller can decide whether a credential will work without ever reading the token into memory or passing it around.The upload endpoint also needs the repository's numeric REST id, and
ghchecks the user's role on the repository before uploading anything. Neither was selected before. The second commit selects both on issues, on pull requests, and on a plain repository lookup, and adds accessors that return zero values when the caller did not request the repository field.How did you test this change?
The whole stack was built and exercised by hand. For this layer specifically,
gh pr view --json headRepositorywas run against the built binary and against a build of trunk, and the output was byte identical.That is the regression this shape is designed to avoid. The pull request type reuses one Go struct for both the repository and the head repository.
Key points
Asking the config for a token kind rather than for the token keeps credentials out of command code. No command in this stack ever handles a token in order to attach a file.
The accessors return zero values rather than an error when the repository field was not requested, because that field is optional in the queries.
The new fields on the shared struct are omitted when empty, and a test row fails if the head repository output ever starts carrying them.
Notes for reviewers
A note in the code records three other places in
ghthat read a token and match its prefix by hand. Those aregh auth status, the check for whether an auth token is writeable, and agent-task. Moving them is not part of this stack.Authorship and follow-up
Who wrote this:
Who answers review comments: