Merge pull request #9701 from cli/jtmcg/9698
Add handling of empty titles for Issues and PRs
This commit is contained in:
commit
1313612245
6 changed files with 58 additions and 10 deletions
|
|
@ -222,7 +222,7 @@ func createRun(opts *CreateOptions) (err error) {
|
|||
defer prShared.PreserveInput(opts.IO, &tb, &err)()
|
||||
|
||||
if opts.Title == "" {
|
||||
err = prShared.TitleSurvey(opts.Prompter, &tb)
|
||||
err = prShared.TitleSurvey(opts.Prompter, opts.IO, &tb)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ func TestIssueCreate_recover(t *testing.T) {
|
|||
|
||||
pm := &prompter.PrompterMock{}
|
||||
pm.InputFunc = func(p, d string) (string, error) {
|
||||
if p == "Title" {
|
||||
if p == "Title (required)" {
|
||||
return d, nil
|
||||
} else {
|
||||
return "", prompter.NoSuchPromptErr(p)
|
||||
|
|
@ -736,7 +736,7 @@ func TestIssueCreate_continueInBrowser(t *testing.T) {
|
|||
|
||||
pm := &prompter.PrompterMock{}
|
||||
pm.InputFunc = func(p, d string) (string, error) {
|
||||
if p == "Title" {
|
||||
if p == "Title (required)" {
|
||||
return "hello", nil
|
||||
} else {
|
||||
return "", prompter.NoSuchPromptErr(p)
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ func createRun(opts *CreateOptions) (err error) {
|
|||
} else {
|
||||
|
||||
if !opts.TitleProvided {
|
||||
err = shared.TitleSurvey(opts.Prompter, state)
|
||||
err = shared.TitleSurvey(opts.Prompter, opts.IO, state)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1210,7 +1210,7 @@ func Test_createRun(t *testing.T) {
|
|||
},
|
||||
promptStubs: func(pm *prompter.PrompterMock) {
|
||||
pm.InputFunc = func(p, d string) (string, error) {
|
||||
if p == "Title" {
|
||||
if p == "Title (required)" {
|
||||
return d, nil
|
||||
} else {
|
||||
return "", prompter.NoSuchPromptErr(p)
|
||||
|
|
@ -1316,7 +1316,7 @@ func Test_createRun(t *testing.T) {
|
|||
}
|
||||
|
||||
pm.InputFunc = func(p, d string) (string, error) {
|
||||
if p == "Title" {
|
||||
if p == "Title (required)" {
|
||||
return d, nil
|
||||
} else if p == "Body" {
|
||||
return d, nil
|
||||
|
|
|
|||
|
|
@ -110,10 +110,17 @@ func BodySurvey(p Prompt, state *IssueMetadataState, templateContent string) err
|
|||
return nil
|
||||
}
|
||||
|
||||
func TitleSurvey(p Prompt, state *IssueMetadataState) error {
|
||||
result, err := p.Input("Title", state.Title)
|
||||
if err != nil {
|
||||
return err
|
||||
func TitleSurvey(p Prompt, io *iostreams.IOStreams, state *IssueMetadataState) error {
|
||||
var err error
|
||||
result := ""
|
||||
for result == "" {
|
||||
result, err = p.Input("Title (required)", state.Title)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if result == "" {
|
||||
fmt.Fprintf(io.ErrOut, "%s Title cannot be blank\n", io.ColorScheme().FailureIcon())
|
||||
}
|
||||
}
|
||||
|
||||
if result != state.Title {
|
||||
|
|
|
|||
|
|
@ -158,3 +158,44 @@ type testEditor struct {
|
|||
func (e testEditor) Edit(filename, text string) (string, error) {
|
||||
return e.edit(text)
|
||||
}
|
||||
|
||||
func TestTitleSurvey(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
prompterMockInputs []string
|
||||
expectedTitle string
|
||||
expectStderr bool
|
||||
}{
|
||||
{
|
||||
name: "title provided",
|
||||
prompterMockInputs: []string{"title"},
|
||||
expectedTitle: "title",
|
||||
},
|
||||
{
|
||||
name: "first input empty",
|
||||
prompterMockInputs: []string{"", "title"},
|
||||
expectedTitle: "title",
|
||||
expectStderr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
io, _, _, stderr := iostreams.Test()
|
||||
pm := prompter.NewMockPrompter(t)
|
||||
for _, input := range tt.prompterMockInputs {
|
||||
pm.RegisterInput("Title (required)", func(string, string) (string, error) {
|
||||
return input, nil
|
||||
})
|
||||
}
|
||||
|
||||
state := &IssueMetadataState{}
|
||||
err := TitleSurvey(pm, io, state)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.expectedTitle, state.Title)
|
||||
if tt.expectStderr {
|
||||
assert.Equal(t, "X Title cannot be blank\n", stderr.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue