Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds an -e/--editor workflow to gh pr edit and gh issue edit, aligning them with the existing editor-based UX used by the create commands and allowing editing title+body in a system editor without going through interactive field-selection prompts.
Changes:
- Add
--editorflag and editor-mode execution path for bothgh pr editandgh issue editusingTitledEditSurvey. - Add mutual-exclusion validation between
--editorand--body/--body-file, and disallow multi-issue editor mode forissue edit. - Extend command/unit tests to cover flag parsing and editor-mode behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/cmd/pr/edit/edit.go | Adds EditorMode, wires TitledEditSurvey, and routes editRun through editor mode when enabled. |
| pkg/cmd/pr/edit/edit_test.go | Adds parsing + run-path tests for --editor and ensures interactive surveys aren’t called in editor mode. |
| pkg/cmd/issue/edit/edit.go | Adds EditorMode, wires TitledEditSurvey, validation, and editor-mode loop behavior for editing an issue. |
| pkg/cmd/issue/edit/edit_test.go | Adds parsing + run-path tests for --editor, including “multiple issues” validation coverage. |
Comments suppressed due to low confidence (4)
pkg/cmd/pr/edit/edit.go:185
- The
--body/--body-filevs--editormutual-exclusion check usesopts.EditorMode, which may be turned on byprefer_editor_promptconfig. That can makegh pr edit ... --body ...error with an--editorconflict even when the user did not specify--editor. Suggest basing this conflict check on whether the--editorflag was actually set (or only when prompting would occur).
if opts.EditorMode && (bodyProvided || bodyFileProvided) {
return cmdutil.FlagErrorf("specify only one of `--body`, `--body-file`, or `--editor`")
}
pkg/cmd/pr/edit/edit.go:185
- Add a test covering the
prefer_editor_prompt=enabledconfig path inInitEditorModeto ensure flag-based edits like--body(and metadata edits like--add-label) don’t start failing editor-mode validation unless--editorwas explicitly provided.
if opts.EditorMode && (bodyProvided || bodyFileProvided) {
return cmdutil.FlagErrorf("specify only one of `--body`, `--body-file`, or `--editor`")
}
pkg/cmd/issue/edit/edit.go:178
- With
prefer_editor_prompt=enabled,opts.EditorModecan become true even without--editor, which would make this multi-issue check reject otherwise-valid non-interactive multi-issue edits (e.g.gh issue edit 1 2 --add-label bug). Consider ensuring the "multiple issues cannot be edited with --editor" restriction applies only when editor mode was explicitly requested (or when you’d otherwise prompt) so config doesn’t break scripted usage.
if opts.EditorMode && len(opts.IssueNumbers) > 1 {
return cmdutil.FlagErrorf("multiple issues cannot be edited with --editor")
}
pkg/cmd/issue/edit/edit.go:162
- Add tests that set
prefer_editor_prompt=enabledto ensure flag-based edits like--body/--add-labelstill work and multi-issue non-interactive edits don’t fail due to config implicitly enabling editor mode.
if opts.EditorMode && (bodyProvided || bodyFileProvided) {
return cmdutil.FlagErrorf("specify only one of `--body`, `--body-file`, or `--editor`")
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bd36ee1 to
81f678f
Compare
|
@maxbeizer sorry there's some merge conflicts now - we had a larger refactor go through in these commands. |
81f678f to
7ea57f9
Compare
|
rebased @BagToad 🙇 |
67aa049 to
8a84586
Compare
| cmd.Flags().StringSliceVar(&opts.Editable.Projects.Remove, "remove-project", nil, "Remove the issue from projects by `title`") | ||
| cmd.Flags().StringVarP(&opts.Editable.Milestone.Value, "milestone", "m", "", "Edit the milestone the issue belongs to by `name`") | ||
| cmd.Flags().BoolVar(&removeMilestone, "remove-milestone", false, "Remove the milestone association from the issue") | ||
| cmd.Flags().BoolVarP(&opts.EditorMode, "editor", "e", false, "Skip prompts and open the text editor to write the title and body in.\nThe first line is the title and the remaining text is the body.") |
There was a problem hiding this comment.
💅 I think this should be one line like the gh pr create one.
| // When editor mode was enabled via config (prefer_editor_prompt) | ||
| // rather than the --editor flag, silently disable it if the user | ||
| // provided flags that conflict, so scripted usage isn't broken. | ||
| editorFlagExplicit := flags.Changed("editor") | ||
| if opts.EditorMode && !editorFlagExplicit && (opts.Editable.Dirty() || len(opts.IssueNumbers) > 1) { | ||
| opts.EditorMode = false | ||
| } |
There was a problem hiding this comment.
💭 I think this is a new pattern that gh pr create doesn't have. I think I'm okay with it, but worry about deviating without also updating gh pr create - WDYT?
maxbeizer
left a comment
There was a problem hiding this comment.
Thanks for the thorough review!
Comments 1 & 4 (flag description): Fixed — collapsed to a single line matching gh pr create's style.
Comment 2 (editorFlagExplicit pattern): The deviation from gh pr create is intentional — create doesn't need this guard because it has no field-level flags that would conflict with --editor. For edit, if a user has prefer_editor_prompt set in config and also passes --assignee or edits multiple issues, silently falling back to the standard flow feels like the right UX. I don't think we need to add this to create. Does that reasoning hold for you?
Comment 3 (skipping FetchOptions): Agreed it's not strictly necessary since the downstream code is guarded by opts.Interactive. Kept it in because it felt cleaner to not initialise things we won't use, but happy to remove if you'd prefer.
Add a -e/--editor flag to both `gh issue edit` and `gh pr edit` that opens the system editor pre-filled with the current title and body. The first line is the title and the remaining text is the body, matching the UX of `gh issue create --editor` and `gh pr create --editor`. This flag: - Skips the interactive field-selection prompts and metadata fetch - Is mutually exclusive with --body and --body-file - Respects GH_EDITOR, config editor, and prefer_editor_prompt settings - Does not support multiple issues (same restriction as interactive mode) - When enabled via prefer_editor_prompt config, silently yields to explicit flags (--body, --add-label, etc.) so scripted usage works Closes cli#11108 Co-authored-by: Copilot <[email protected]>
After TitledEditSurvey returns, check that the title is not blank and abort with a clear error message, matching the behavior of the create commands. Also update the editor hint text to say 'aborts the process' instead of 'aborts the creation process' since the hint is shared by both create and edit flows. Co-authored-by: Copilot <[email protected]>
…e edit Co-authored-by: Copilot <[email protected]>
54e2af5 to
3ce19db
Compare
|
@maxbeizer Sorry for the delays.
I think we should align both commands here please 🙏 I think we should remove the additional condition here and align it with
Yeah let's leave it alone. Thanks. |
Remove the prefer_editor_prompt fallback so edit commands handle config-driven editor mode the same way as create commands. Co-authored-by: Copilot <[email protected]>
|
updated @BagToad |
…flag # Conflicts: # pkg/cmd/issue/edit/edit.go # pkg/cmd/issue/edit/edit_test.go # pkg/cmd/pr/edit/edit.go # pkg/cmd/pr/edit/edit_test.go
There was a problem hiding this comment.
🟡 Changes recommended
Attachment-only PR edits can incorrectly activate editor mode, and both new command flows lack regression coverage.
3 open issues
4 resolved since last review
InitEditorModecan enable editor mode due toprefer_editor_promptconfig even when--editor…InitEditorModeenables editor mode whenprefer_editor_promptis enabled in config, even if the… Editor mode usesTitledEditSurvey, whose on-screen hint says an empty title aborts (it’s written… Editor mode uses the sharedTitledEditSurveytemplate (which includes the hint "an empty title…
Review effort: Balanced
|
|
||
| editorFlagChanged := flags.Changed("editor") | ||
| editorModeExplicit := editorFlagChanged && opts.EditorMode | ||
| if editorModeExplicit || (!editorFlagChanged && !opts.Editable.Dirty() && f.Config != nil) { |
| } | ||
| editable.Title.Edited = true | ||
| editable.Body.Edited = true | ||
| editable.Title.Value, editable.Body.Value, err = opts.TitledEditSurvey(initialTitle, issues[0].Body) |
| } | ||
| editable.Title.Edited = true | ||
| editable.Body.Edited = true | ||
| editable.Title.Value, editable.Body.Value, err = opts.TitledEditSurvey(initialTitle, pr.Body) |



Fixes #11108
Motivation
gh issue createandgh pr createsupport-e/--editor, which opens the user's configured editor for writing the title and body. The correspondingeditcommands did not offer the same shortcut, so users who wanted to update an issue or pull request body in their editor had to either go through the interactive field-selection prompts first or provide the full body inline with--bodyor--body-file.Approach
This adds
-e/--editorto bothgh issue editandgh pr edit.When editor mode is enabled, the command:
InitEditorModeandTitledEditSurveyflow used by create commandsThe flag also respects the existing
prefer_editor_promptconfiguration, so config-enabled editor mode behaves consistently withgh issue createandgh pr create.Validation and constraints
--editoris mutually exclusive with--bodyand--body-filegh issue edit --editordoes not support editing multiple issues at onceTests added
--editor--editorwith--bodyand--body-filegh issue edit --editorwith multiple issuesprefer_editor_promptbehavior for edit commands