Add --editor flag to gh issue edit and gh pr edit#12942
Open
Add --editor flag to gh issue edit and gh pr edit#12942
--editor flag to gh issue edit and gh pr edit#12942Conversation
Contributor
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
Member
|
@maxbeizer sorry there's some merge conflicts now - we had a larger refactor go through in these commands. |
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 <223556219+Copilot@users.noreply.github.com>
81f678f to
7ea57f9
Compare
Contributor
Author
|
rebased @BagToad 🙇 |
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.
Fixes #11108
Motivation
gh issue createandgh pr createboth support an-e/--editorflag that opens the system editor for writing the title and body. However, the correspondingeditcommands lack this users who want to edit an issue or PR body in their editor must go through the interactive "What would you like to edit?" prompt first, or pass the entire body inline via--bodyoptionApproach
Adds a
-e/--editorflag to bothgh issue editandgh pr editthat:GH_EDITOR, theeditorconfig key, and theprefer_editor_promptconfig setting (via the existingInitEditorModehelper)The implementation reuses
prShared.TitledEditSurveyandprShared. the same infrastructure that powers thecreate --editorso the UX is consistent.flow InitEditorModeFlag validation:
--editoris mutually exclusive with--bodyand--body-file--editordoes not support multiple issues (same restriction as interactive mode)Tests added:
--editoralone,--editor+--body(error),--editor+--body-file(error),--editorwith multiple issues (error)TitledEditSurvey, skipsFieldsToEditSurvey/EditFieldsSurvey, and sends correct values to the API