forked from lunny/changelog
Title-case PR title (#76)
Resolves #60 Extracts the previous trim into a new func as well to keep any title munging consistent. Reviewed-on: https://gitea.com/gitea/changelog/pulls/76 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.io> Co-authored-by: jolheiser <john.olheiser@gmail.com> Co-committed-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
cbd80881bc
commit
70c955ae17
@ -6,7 +6,6 @@ package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -93,7 +92,7 @@ func getGiteaTagURL(c *gitea.Client, baseURL, owner, repo, mileName, gitTag, fro
|
||||
func convertToEntry(issue gitea.Issue) Entry {
|
||||
entry := Entry{
|
||||
Index: issue.Index,
|
||||
Title: strings.TrimSpace(issue.Title),
|
||||
Title: CleanTitle(issue.Title),
|
||||
}
|
||||
|
||||
labels := make([]Label, len(issue.Labels))
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-github/v50/github"
|
||||
@ -59,7 +58,7 @@ func (gh *GitHub) Generate() (string, []Entry, error) {
|
||||
for _, pr := range result.Issues {
|
||||
if pr.IsPullRequest() == isPull {
|
||||
p := Entry{
|
||||
Title: strings.TrimSpace(pr.GetTitle()),
|
||||
Title: CleanTitle(pr.GetTitle()),
|
||||
Index: int64(pr.GetNumber()),
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ package service
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
const defaultGitea = "https://gitea.com"
|
||||
@ -86,3 +87,15 @@ func (cl ContributorList) Less(i, j int) bool {
|
||||
func (cl ContributorList) Swap(i, j int) {
|
||||
cl[i], cl[j] = cl[j], cl[i]
|
||||
}
|
||||
|
||||
// CleanTitle returns the string with spaces trimmed and the first rune title-cased
|
||||
func CleanTitle(s string) string {
|
||||
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
r := []rune(s)
|
||||
r[0] = unicode.ToUpper(r[0])
|
||||
s = string(r)
|
||||
|
||||
return s
|
||||
}
|
||||
|
@ -12,3 +12,27 @@ import (
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestCleanTitle(t *testing.T) {
|
||||
tt := []struct {
|
||||
Title string
|
||||
Expected string
|
||||
}{
|
||||
{Title: "foo", Expected: "Foo"},
|
||||
{Title: " foo", Expected: "Foo"},
|
||||
{Title: "foo bar", Expected: "Foo bar"},
|
||||
{Title: "Foo bar", Expected: "Foo bar"},
|
||||
{Title: " Foo bar ", Expected: "Foo bar"},
|
||||
{Title: "1234", Expected: "1234"},
|
||||
}
|
||||
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.Title, func(t *testing.T) {
|
||||
s := CleanTitle(tc.Title)
|
||||
if s != tc.Expected {
|
||||
t.Logf("got %q | expected %q", s, tc.Expected)
|
||||
t.Fail()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user