more nuanced error handling
This commit is contained in:
parent
af46fcb1ff
commit
98a2281f45
2 changed files with 88 additions and 4 deletions
|
|
@ -101,10 +101,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
|
|||
return fmt.Errorf("could not parse body: %w", err)
|
||||
}
|
||||
|
||||
defs, err := computeDefaults(baseBranch, headBranch)
|
||||
if err != nil {
|
||||
fmt.Fprintf(colorableErr(cmd), "%s warning: could not compute title or body defaults: %w\n", utils.Yellow("!"), err)
|
||||
}
|
||||
defs, defaultsErr := computeDefaults(baseBranch, headBranch)
|
||||
|
||||
isWeb, err := cmd.Flags().GetBool("web")
|
||||
if err != nil {
|
||||
|
|
@ -119,7 +116,13 @@ func prCreate(cmd *cobra.Command, _ []string) error {
|
|||
action := SubmitAction
|
||||
if isWeb {
|
||||
action = PreviewAction
|
||||
if (title == "" || body == "") && defaultsErr != nil {
|
||||
return fmt.Errorf("could not compute title or body defaults: %w", defaultsErr)
|
||||
}
|
||||
} else if autofill {
|
||||
if defaultsErr != nil {
|
||||
return fmt.Errorf("could not compute title or body defaults: %w", defaultsErr)
|
||||
}
|
||||
action = SubmitAction
|
||||
title = defs.Title
|
||||
body = defs.Body
|
||||
|
|
@ -128,6 +131,9 @@ func prCreate(cmd *cobra.Command, _ []string) error {
|
|||
utils.Cyan(headBranch),
|
||||
utils.Cyan(baseBranch),
|
||||
ghrepo.FullName(baseRepo))
|
||||
if (title == "" || body == "") && defaultsErr != nil {
|
||||
fmt.Fprintf(colorableErr(cmd), "%s warning: could not compute title or body defaults: %s\n", utils.Yellow("!"), defaultsErr)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: only drop into interactive mode if stdin & stdout are a tty
|
||||
|
|
|
|||
|
|
@ -370,3 +370,81 @@ func TestPRCreate_survey_autofill(t *testing.T) {
|
|||
|
||||
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
|
||||
}
|
||||
|
||||
func TestPRCreate_defaults_error_autofill(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "feature")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
cs, cmdTeardown := initCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git status
|
||||
cs.Stub("") // git log
|
||||
|
||||
_, err := RunCommand(prCreateCmd, "pr create -f")
|
||||
|
||||
eq(t, err.Error(), "could not compute title or body defaults: could not find any commits between master and feature")
|
||||
}
|
||||
|
||||
func TestPRCreate_defaults_error_web(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "feature")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
cs, cmdTeardown := initCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git status
|
||||
cs.Stub("") // git log
|
||||
|
||||
_, err := RunCommand(prCreateCmd, "pr create -w")
|
||||
|
||||
eq(t, err.Error(), "could not compute title or body defaults: could not find any commits between master and feature")
|
||||
}
|
||||
|
||||
func TestPRCreate_defaults_error_interactive(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "feature")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
http.StubResponse(200, bytes.NewBufferString(`
|
||||
{ "data": { "createPullRequest": { "pullRequest": {
|
||||
"URL": "https://github.com/OWNER/REPO/pull/12"
|
||||
} } } }
|
||||
`))
|
||||
|
||||
cs, cmdTeardown := initCmdStubber()
|
||||
defer cmdTeardown()
|
||||
|
||||
cs.Stub("") // git status
|
||||
cs.Stub("") // git log
|
||||
cs.Stub("") // git rev-parse
|
||||
cs.Stub("") // git push
|
||||
cs.Stub("") // browser open
|
||||
|
||||
as, surveyTeardown := initAskStubber()
|
||||
defer surveyTeardown()
|
||||
|
||||
as.Stub([]*QuestionStub{
|
||||
&QuestionStub{
|
||||
Name: "title",
|
||||
Default: true,
|
||||
},
|
||||
&QuestionStub{
|
||||
Name: "body",
|
||||
Value: "social distancing",
|
||||
},
|
||||
})
|
||||
as.Stub([]*QuestionStub{
|
||||
&QuestionStub{
|
||||
Name: "confirmation",
|
||||
Value: 0,
|
||||
},
|
||||
})
|
||||
|
||||
output, err := RunCommand(prCreateCmd, `pr create`)
|
||||
eq(t, err, nil)
|
||||
|
||||
stderr := string(output.Stderr())
|
||||
eq(t, strings.Contains(stderr, "warning: could not compute title or body defaults: could not find any commits"), true)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue