Skip to content

Make commands own attachment flag policy - #14255

Merged
BagToad merged 2 commits into
bagtoad/attach-review-feedbackfrom
bagtoad/attach-flag-wrapper
Aug 25, 2026
Merged

BagToad merged 2 commits into
bagtoad/attach-review-feedbackfrom
bagtoad/attach-flag-wrapper

Conversation

@BagToad

@BagToad BagToad commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Related review feedback:

Description

The attachment package currently registers and resolves --attach, but it also reads
command-owned flags such as --web, --dry-run, and --delete-last to enforce conflicts.
That spreads command policy into a package that should only own attachment values.

This introduces an attachment flag handle that owns registration, parsed values, changed state,
and conversion to validated assets. Each command stores that handle, resolves assets through it,
and owns its attachment conflicts using cmdutil.MutuallyExclusive.

The ownership and call flow change like this:

attach-flag-flow

Uploaded with gh pr edit --attach

How did you test this change?

Given --attach named a missing file while a command also used an incompatible mode,
I ran local gh commands for issue creation, pull request creation, and issue comments.
Each command returned its existing attachment conflict before attempting to read the file:

`--attach` is not supported when using `--web`

This verifies that moving conflict ownership did not change error precedence at the command
boundary.

Key points

  • The wrapper keeps the fixed attach name and no shorthand. It does not add unused name or
    shorthand configuration.
  • Commands own conflicts with their own flags. The attachment package no longer knows about
    web, dry-run, or delete-last.
  • Conflict checks remain ahead of filesystem validation and retain their existing messages.
  • Package-level conflict cases were removed only after the existing command tables were confirmed
    to cover every conflict pair.
  • This is a behavior-neutral refactor. Parsing, validation, duplicate detection, and upload
    behavior are unchanged.

Notes for reviewers

Review the commits in order:

  1. Add attachment flag wrapper introduces the handle and keeps every production call site on
    the old path.
  2. Move attachment policy into commands migrates call sites, moves conflicts, and removes the
    old command lookup API.

The main design question is whether Flag is the right boundary between command-owned policy and
attachment-owned values. The diff deliberately avoids storing the entire Cobra command on the
wrapper.

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 @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

BagToad and others added 2 commits August 24, 2026 23:06
@BagToad BagToad changed the title bagtoad/attach flag wrapper Make commands own attachment flag policy Aug 25, 2026
@BagToad
BagToad marked this pull request as ready for review August 25, 2026 05:23
@BagToad
BagToad requested a review from a team as a code owner August 25, 2026 05:23
@BagToad
BagToad requested review from babakks and sergiou87 and a balanced review from Copilot August 25, 2026 05:23

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

Refactors attachment handling so commands own flag-conflict policy while the attachment package owns registration and validation.

Changes:

  • Adds an attachment flag handle with changed-state and asset resolution.
  • Moves conflict checks into create/comment commands.
  • Updates call sites, documentation, and tests.
Show a summary per file
File Description
internal/attachments/flags.go Introduces the flag handle and removes command-specific policy.
internal/attachments/flags_test.go Updates attachment flag and validation tests.
internal/attachments/test.go Migrates the test helper to the flag handle.
internal/attachments/doc.go Updates package usage documentation.
pkg/cmd/pr/shared/commentable.go Owns comment attachment conflicts and resolution.
pkg/cmd/pr/shared/commentable_test.go Tests shared comment conflict handling.
pkg/cmd/pr/comment/comment.go Stores the registered attachment flag.
pkg/cmd/issue/comment/comment.go Stores the registered attachment flag.
pkg/cmd/pr/create/create.go Owns web and dry-run attachment conflicts.
pkg/cmd/pr/create/create_test.go Verifies conflict precedence.
pkg/cmd/issue/create/create.go Owns the web attachment conflict.
pkg/cmd/issue/create/create_test.go Verifies conflict precedence.
pkg/cmd/pr/edit/edit.go Resolves attachments through the flag handle.
pkg/cmd/issue/edit/edit.go Resolves attachments through the flag handle.

Review details

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 14/14 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@BagToad BagToad mentioned this pull request Aug 25, 2026
2 of 6 tasks

@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.

This is a really nice cleanup, @BagToad! ✨

Moving conflict policy back to the commands and letting the attachment package own only its own values is exactly the right boundary. It resolves the concern I raised earlier about the package reaching into command-owned flags like --web, and the fact that it lands as a net code reduction while staying behavior-neutral is a great sign. Splitting it into "add the wrapper" then "migrate call sites" also made it easy to follow.

No comments from me. Nice work! 🎉

@BagToad
BagToad merged commit cc83172 into trunk Aug 25, 2026
54 checks passed
@BagToad
BagToad deleted the bagtoad/attach-flag-wrapper branch August 25, 2026 21:30
@BagToad BagToad mentioned this pull request Aug 25, 2026
@BagToad BagToad mentioned this pull request Aug 28, 2026
2 of 6 tasks
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