X Tutup
Skip to content

Commit 0344e95

Browse files
committed
humanize branch name for title
1 parent 98a2281 commit 0344e95

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

command/pr_create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func computeDefaults(baseRef, headRef string) (defaults, error) {
3636
}
3737
out.Body = body
3838
} else {
39-
out.Title = headRef // TODO format or something?
39+
out.Title = utils.Humanize(headRef)
4040

4141
body := ""
4242
for _, c := range commits {

command/pr_create_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func TestPRCreate_cross_repo_same_branch(t *testing.T) {
191191
}
192192

193193
func TestPRCreate_survey_defaults_multicommit(t *testing.T) {
194-
initBlankContext("OWNER/REPO", "feature")
194+
initBlankContext("OWNER/REPO", "cool_bug-fixes")
195195
http := initFakeHTTP()
196196
http.StubRepoResponse("OWNER", "REPO")
197197
http.StubResponse(200, bytes.NewBufferString(`
@@ -248,10 +248,10 @@ func TestPRCreate_survey_defaults_multicommit(t *testing.T) {
248248
expectedBody := "- commit 0\n- commit 1\n"
249249

250250
eq(t, reqBody.Variables.Input.RepositoryID, "REPOID")
251-
eq(t, reqBody.Variables.Input.Title, "feature")
251+
eq(t, reqBody.Variables.Input.Title, "cool bug fixes")
252252
eq(t, reqBody.Variables.Input.Body, expectedBody)
253253
eq(t, reqBody.Variables.Input.BaseRefName, "master")
254-
eq(t, reqBody.Variables.Input.HeadRefName, "feature")
254+
eq(t, reqBody.Variables.Input.HeadRefName, "cool_bug-fixes")
255255

256256
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
257257
}

utils/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"fmt"
5+
"strings"
56
"time"
67

78
"github.com/briandowns/spinner"
@@ -54,6 +55,19 @@ func FuzzyAgo(ago time.Duration) string {
5455
return fmtDuration(int(ago.Hours()/24/365), "year")
5556
}
5657

58+
func Humanize(s string) string {
59+
// Replaces - and _ with spaces.
60+
replace := "_-"
61+
h := func(r rune) rune {
62+
if strings.ContainsRune(replace, r) {
63+
return ' '
64+
}
65+
return r
66+
}
67+
68+
return strings.Map(h, s)
69+
}
70+
5771
func Spinner() *spinner.Spinner {
5872
return spinner.New(spinner.CharSets[11], 400*time.Millisecond)
5973
}

0 commit comments

Comments
 (0)
X Tutup