Skip to content

--attach stack 1/8: Report what kind of token is active - #14177

Merged
BagToad merged 2 commits into
trunkfrom
bagtoad/attach-prerequisites
Aug 25, 2026
Merged

BagToad merged 2 commits into
trunkfrom
bagtoad/attach-prerequisites

Conversation

@BagToad

@BagToad BagToad commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

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 --attach flag 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, gh rewrites that path to point at the uploaded asset. Otherwise gh appends 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 gh package 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 gh checks 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 headRepository was 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 gh that read a token and match its prefix by hand. Those are gh 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:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @BagToad will read and reply directly. Name the account.
  • An agent will draft replies and @BagToad will read them before they are posted.
  • Nobody has explicitly committed to replying.

Copilot AI balanced review requested due to automatic review settings August 18, 2026 05:53
@BagToad BagToad changed the title bagtoad/attach prerequisites --attach stack 1/8: Report what kind of token is active Aug 18, 2026
@BagToad
BagToad marked this pull request as ready for review August 18, 2026 05:56
@BagToad
BagToad requested a review from a team as a code owner August 18, 2026 05:56
@BagToad
BagToad requested a review from babakks August 18, 2026 05:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread api/queries_pr_test.go Resolved
Comment thread internal/gh/gh.go Resolved
@BagToad BagToad mentioned this pull request Aug 18, 2026

@babakks babakks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/gh/gh.go Resolved
Comment thread internal/config/config.go Resolved
Comment thread internal/config/config.go Resolved
Comment thread api/queries_pr.go Resolved
Comment thread api/queries_pr_test.go Resolved
Comment thread api/queries_issue_test.go Resolved
Comment thread api/query_builder.go Resolved
@BagToad
BagToad merged commit cc83172 into trunk Aug 25, 2026
11 checks passed
@BagToad
BagToad deleted the bagtoad/attach-prerequisites branch August 25, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants