diff --git a/command/pr_create.go b/command/pr_create.go index 441b9645d..dd747f41d 100644 --- a/command/pr_create.go +++ b/command/pr_create.go @@ -36,7 +36,7 @@ func computeDefaults(baseRef, headRef string) (defaults, error) { } out.Body = body } else { - out.Title = headRef // TODO format or something? + out.Title = utils.Humanize(headRef) body := "" for _, c := range commits { diff --git a/command/pr_create_test.go b/command/pr_create_test.go index 6fbf8d1b3..2bae80751 100644 --- a/command/pr_create_test.go +++ b/command/pr_create_test.go @@ -191,7 +191,7 @@ func TestPRCreate_cross_repo_same_branch(t *testing.T) { } func TestPRCreate_survey_defaults_multicommit(t *testing.T) { - initBlankContext("OWNER/REPO", "feature") + initBlankContext("OWNER/REPO", "cool_bug-fixes") http := initFakeHTTP() http.StubRepoResponse("OWNER", "REPO") http.StubResponse(200, bytes.NewBufferString(` @@ -248,10 +248,10 @@ func TestPRCreate_survey_defaults_multicommit(t *testing.T) { expectedBody := "- commit 0\n- commit 1\n" eq(t, reqBody.Variables.Input.RepositoryID, "REPOID") - eq(t, reqBody.Variables.Input.Title, "feature") + eq(t, reqBody.Variables.Input.Title, "cool bug fixes") eq(t, reqBody.Variables.Input.Body, expectedBody) eq(t, reqBody.Variables.Input.BaseRefName, "master") - eq(t, reqBody.Variables.Input.HeadRefName, "feature") + eq(t, reqBody.Variables.Input.HeadRefName, "cool_bug-fixes") eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n") } diff --git a/utils/utils.go b/utils/utils.go index 065c4988e..6217871b7 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,6 +2,7 @@ package utils import ( "fmt" + "strings" "time" "github.com/briandowns/spinner" @@ -54,6 +55,19 @@ func FuzzyAgo(ago time.Duration) string { return fmtDuration(int(ago.Hours()/24/365), "year") } +func Humanize(s string) string { + // Replaces - and _ with spaces. + replace := "_-" + h := func(r rune) rune { + if strings.ContainsRune(replace, r) { + return ' ' + } + return r + } + + return strings.Map(h, s) +} + func Spinner() *spinner.Spinner { return spinner.New(spinner.CharSets[11], 400*time.Millisecond) }