humanize branch name for title

This commit is contained in:
vilmibm 2020-03-17 16:18:32 -05:00
parent 98a2281f45
commit 0344e9543a
3 changed files with 18 additions and 4 deletions

View file

@ -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 {

View file

@ -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")
}

View file

@ -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)
}