Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Validate empty title in editor mode for issue/pr edit
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 <223556219+Copilot@users.noreply.github.com>
  • Loading branch information
maxbeizer and Copilot committed Apr 8, 2026
commit 8a845868781a57e3ad6bd72005cc722915c191dc
3 changes: 3 additions & 0 deletions pkg/cmd/issue/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ func editRun(opts *EditOptions) error {
if err != nil {
return err
}
Comment thread
maxbeizer marked this conversation as resolved.
if editable.Title.Value == "" {
return fmt.Errorf("title can't be blank")
}
} else if opts.Interactive {
editorCommand, err := opts.DetermineEditor()
if err != nil {
Expand Down
31 changes: 26 additions & 5 deletions pkg/cmd/issue/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func Test_editRun(t *testing.T) {
httpStubs func(*testing.T, *httpmock.Registry)
stdout string
stderr string
wantErr bool
wantErr string
}{
{
name: "non-interactive",
Expand Down Expand Up @@ -574,7 +574,7 @@ func Test_editRun(t *testing.T) {
] }`),
)
},
wantErr: true,
wantErr: "*",
},
{
name: "non-interactive multiple issues with update failures",
Expand Down Expand Up @@ -644,7 +644,7 @@ func Test_editRun(t *testing.T) {
https://github.com/OWNER/REPO/issue/123
`),
stderr: `failed to update https://github.com/OWNER/REPO/issue/456:.*test error`,
wantErr: true,
wantErr: "*",
},
{
name: "interactive",
Expand Down Expand Up @@ -721,6 +721,24 @@ func Test_editRun(t *testing.T) {
},
stdout: "https://github.com/OWNER/REPO/issue/123\n",
},
{
name: "editor mode empty title",
input: &EditOptions{
Detector: &fd.EnabledDetectorMock{},
IssueNumbers: []int{123},
EditorMode: true,
TitledEditSurvey: func(title, body string) (string, string, error) {
return "", "", nil
},
FetchOptions: func(client *api.Client, repo ghrepo.Interface, editable *prShared.Editable, v1 gh.ProjectsV1Support) error {
return nil
},
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
mockIssueGet(t, reg)
},
wantErr: "title can't be blank",
},
{
name: "interactive prompts with actor assignee display names when actors available",
input: &EditOptions{
Expand Down Expand Up @@ -847,8 +865,11 @@ func Test_editRun(t *testing.T) {
tt.input.BaseRepo = baseRepo

err := editRun(tt.input)
if tt.wantErr {
assert.Error(t, err)
if tt.wantErr != "" {
require.Error(t, err)
if tt.wantErr != "*" {
assert.Contains(t, err.Error(), tt.wantErr)
}
} else {
assert.NoError(t, err)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/pr/edit/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ func editRun(opts *EditOptions) error {
if err != nil {
return err
}
Comment thread
maxbeizer marked this conversation as resolved.
if editable.Title.Value == "" {
return fmt.Errorf("title can't be blank")
}
} else if opts.Interactive {
err = opts.Surveyor.FieldsToEdit(&editable)
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions pkg/cmd/pr/edit/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ func Test_editRun(t *testing.T) {
httpStubs func(*testing.T, *httpmock.Registry)
stdout string
stderr string
wantsErr string
}{
{
name: "non-interactive",
Expand Down Expand Up @@ -1234,6 +1235,26 @@ func Test_editRun(t *testing.T) {
},
stdout: "https://github.com/OWNER/REPO/pull/123\n",
},
{
name: "editor mode empty title",
input: &EditOptions{
Detector: &fd.EnabledDetectorMock{},
SelectorArg: "123",
Finder: shared.NewMockFinder("123", &api.PullRequest{
URL: "https://github.com/OWNER/REPO/pull/123",
Title: "pr title",
Body: "pr body",
}, ghrepo.New("OWNER", "REPO")),
EditorMode: true,
TitledEditSurvey: func(title, body string) (string, string, error) {
return "", "", nil
},
Surveyor: testSurveyor{},
Fetcher: testFetcher{},
},
httpStubs: func(t *testing.T, reg *httpmock.Registry) {},
wantsErr: "title can't be blank",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -1254,6 +1275,10 @@ func Test_editRun(t *testing.T) {
tt.input.BaseRepo = baseRepo

err := editRun(tt.input)
if tt.wantsErr != "" {
require.EqualError(t, err, tt.wantsErr)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.stdout, stdout.String())
assert.Equal(t, tt.stderr, stderr.String())
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pr/shared/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (e *UserEditor) Edit(filename, initialValue string) (string, error) {
const editorHintMarker = "------------------------ >8 ------------------------"
const editorHint = `
Please Enter the title on the first line and the body on subsequent lines.
Lines below dotted lines will be ignored, and an empty title aborts the creation process.`
Lines below dotted lines will be ignored, and an empty title aborts the process.`

func TitledEditSurvey(editor Editor) func(string, string) (string, string, error) {
return func(initialTitle, initialBody string) (string, string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pr/shared/survey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ editedBody
------------------------ >8 ------------------------

Please Enter the title on the first line and the body on subsequent lines.
Lines below dotted lines will be ignored, and an empty title aborts the creation process.`, nil
Lines below dotted lines will be ignored, and an empty title aborts the process.`, nil
},
}

Expand All @@ -207,7 +207,7 @@ initialBody
------------------------ >8 ------------------------

Please Enter the title on the first line and the body on subsequent lines.
Lines below dotted lines will be ignored, and an empty title aborts the creation process.`, editorInitialText)
Lines below dotted lines will be ignored, and an empty title aborts the process.`, editorInitialText)
assert.Equal(t, "editedTitle", title)
assert.Equal(t, "editedBody", body)
}
Expand Down
Loading