Repository navigation
Make commands own attachment flag policy - #14255
Conversation
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
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
babakks
left a comment
There was a problem hiding this comment.
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! 🎉
Related review feedback:
--attachstack 5/8: Add the flag and upload behind it #14181 (comment)--attachstack 5/8: Add the flag and upload behind it #14181 (comment)--attachstack 5/8: Add the flag and upload behind it #14181 (comment)Description
The attachment package currently registers and resolves
--attach, but it also readscommand-owned flags such as
--web,--dry-run, and--delete-lastto 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:
Uploaded with
gh pr edit --attachHow did you test this change?
Given
--attachnamed a missing file while a command also used an incompatible mode,I ran local
ghcommands for issue creation, pull request creation, and issue comments.Each command returned its existing attachment conflict before attempting to read the file:
This verifies that moving conflict ownership did not change error precedence at the command
boundary.
Key points
attachname and no shorthand. It does not add unused name orshorthand configuration.
web,dry-run, ordelete-last.to cover every conflict pair.
behavior are unchanged.
Notes for reviewers
Review the commits in order:
Add attachment flag wrapperintroduces the handle and keeps every production call site onthe old path.
Move attachment policy into commandsmigrates call sites, moves conflicts, and removes theold command lookup API.
The main design question is whether
Flagis the right boundary between command-owned policy andattachment-owned values. The diff deliberately avoids storing the entire Cobra command on the
wrapper.
Authorship and follow-up
Who wrote this:
Who answers review comments: