X Tutup
Skip to content

Add --editor flag to gh issue edit and gh pr edit#12942

Open
maxbeizer wants to merge 1 commit intocli:trunkfrom
maxbeizer:issue-edit-editor-flag
Open

Add --editor flag to gh issue edit and gh pr edit#12942
maxbeizer wants to merge 1 commit intocli:trunkfrom
maxbeizer:issue-edit-editor-flag

Conversation

@maxbeizer
Copy link
Contributor

@maxbeizer maxbeizer commented Mar 15, 2026

Fixes #11108

Motivation

gh issue create and gh pr create both support an -e/--editor flag that opens the system editor for writing the title and body. However, the corresponding edit commands 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 --body option

Approach

Adds a -e/--editor flag to both gh issue edit and gh pr edit that:

  • Fetches the current title and body from the issue/PR
  • Opens the system editor pre-filled with the content (first line = title, remaining = body)
  • Updates the issue/PR with the skipping all interactive field-selection promptsresult
  • Respects GH_EDITOR, the editor config key, and the prefer_editor_prompt config setting (via the existing InitEditorMode helper)

The implementation reuses prShared.TitledEditSurvey and prShared. the same infrastructure that powers the create --editor so the UX is consistent.flow InitEditorMode

Flag validation:

  • --editor is mutually exclusive with --body and --body-file
  • --editor does not support multiple issues (same restriction as interactive mode)

Tests added:

  • Flag parsing: --editor alone, --editor + --body (error), --editor + --body-file (error), --editor with multiple issues (error)
  • Integration: editor mode calls TitledEditSurvey, skips FieldsToEditSurvey/EditFieldsSurvey, and sends correct values to the API

@github-actions github-actions bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed labels Mar 15, 2026
@maxbeizer maxbeizer marked this pull request as ready for review March 15, 2026 18:25
@maxbeizer maxbeizer requested a review from a team as a code owner March 15, 2026 18:25
@maxbeizer maxbeizer requested review from BagToad and Copilot March 15, 2026 18:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 --editor flag and editor-mode execution path for both gh pr edit and gh issue edit using TitledEditSurvey.
  • Add mutual-exclusion validation between --editor and --body/--body-file, and disallow multi-issue editor mode for issue 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-file vs --editor mutual-exclusion check uses opts.EditorMode, which may be turned on by prefer_editor_prompt config. That can make gh pr edit ... --body ... error with an --editor conflict even when the user did not specify --editor. Suggest basing this conflict check on whether the --editor flag 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=enabled config path in InitEditorMode to ensure flag-based edits like --body (and metadata edits like --add-label) don’t start failing editor-mode validation unless --editor was 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.EditorMode can 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=enabled to ensure flag-based edits like --body / --add-label still 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.

@maxbeizer maxbeizer marked this pull request as draft March 16, 2026 21:58
@maxbeizer maxbeizer force-pushed the issue-edit-editor-flag branch from bd36ee1 to 81f678f Compare March 16, 2026 22:08
@maxbeizer maxbeizer marked this pull request as ready for review March 17, 2026 00:51
@BagToad
Copy link
Member

BagToad commented Mar 25, 2026

@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>
@maxbeizer maxbeizer force-pushed the issue-edit-editor-flag branch from 81f678f to 7ea57f9 Compare March 25, 2026 21:51
@maxbeizer
Copy link
Contributor Author

rebased @BagToad 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team needs-triage needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pr edit --editor

3 participants

X Tutup