Skip to content

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

Open
maxbeizer wants to merge 9 commits into
cli:trunkfrom
maxbeizer:issue-edit-editor-flag
Open

maxbeizer wants to merge 9 commits into
cli:trunkfrom
maxbeizer:issue-edit-editor-flag

Conversation

@maxbeizer

@maxbeizer maxbeizer commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11108

Motivation

gh issue create and gh pr create support -e/--editor, which opens the user's configured editor for writing the title and body. The corresponding edit commands 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 --body or --body-file.

Approach

This adds -e/--editor to both gh issue edit and gh pr edit.

When editor mode is enabled, the command:

  • fetches the current title and body for the issue or pull request
  • opens the configured editor with the current title on the first line and body below it
  • updates the title and body from the edited content
  • skips the interactive field-selection prompts
  • uses the same InitEditorMode and TitledEditSurvey flow used by create commands

The flag also respects the existing prefer_editor_prompt configuration, so config-enabled editor mode behaves consistently with gh issue create and gh pr create.

Validation and constraints

  • --editor is mutually exclusive with --body and --body-file
  • gh issue edit --editor does not support editing multiple issues at once
  • editor mode does not fetch shared metadata options that are only needed by field-selection prompts

Tests added

  • flag parsing for --editor
  • validation for --editor with --body and --body-file
  • validation for gh issue edit --editor with multiple issues
  • prefer_editor_prompt behavior for edit commands
  • editor-mode integration paths for issue and pull request edits

@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

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

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.

Comment thread pkg/cmd/pr/edit/edit.go Resolved
Comment thread pkg/cmd/issue/edit/edit.go Resolved
Comment thread pkg/cmd/pr/edit/edit.go Resolved
Comment thread pkg/cmd/issue/edit/edit.go Resolved
@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

BagToad commented Mar 25, 2026

Copy link
Copy Markdown
Member

@maxbeizer sorry there's some merge conflicts now - we had a larger refactor go through in these commands.

@maxbeizer
maxbeizer force-pushed the issue-edit-editor-flag branch from 81f678f to 7ea57f9 Compare March 25, 2026 21:51
@maxbeizer

Copy link
Copy Markdown
Contributor Author

rebased @BagToad 🙇

@maxbeizer
maxbeizer force-pushed the issue-edit-editor-flag branch from 67aa049 to 8a84586 Compare April 8, 2026 20:08
Comment thread pkg/cmd/issue/edit/edit.go Outdated
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.")

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.

💅 I think this should be one line like the gh pr create one.

Comment thread pkg/cmd/issue/edit/edit.go Outdated
Comment on lines +160 to +166
// 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
}

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.

💭 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?

Comment thread pkg/cmd/issue/edit/edit.go Resolved
Comment thread pkg/cmd/pr/edit/edit.go Resolved

@maxbeizer maxbeizer left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

maxbeizer and others added 3 commits June 30, 2026 15:23
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]>
@maxbeizer
maxbeizer force-pushed the issue-edit-editor-flag branch from 54e2af5 to 3ce19db Compare June 30, 2026 20:25
@BagToad

BagToad commented Jul 2, 2026

Copy link
Copy Markdown
Member

@maxbeizer Sorry for the delays.

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?

I think we should align both commands here please 🙏 I think we should remove the additional condition here and align it with gh pr create. That logic there is probably worth its own PR if you'd like it changed.

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.

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]>
@maxbeizer

Copy link
Copy Markdown
Contributor Author

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
Copilot AI balanced review requested due to automatic review settings October 23, 2026 15:12

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.

Comment thread pkg/cmd/pr/edit/edit.go

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)
Comment thread pkg/cmd/pr/edit/edit.go
}
editable.Title.Edited = true
editable.Body.Edited = true
editable.Title.Value, editable.Body.Value, err = opts.TitledEditSurvey(initialTitle, pr.Body)

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pr edit --editor

4 participants