Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions hack/tools/release/notes/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,38 @@ func Test_trimAreaFromTitle(t *testing.T) {
tests := []struct {
name string
title string
area string
want string
}{
{
name: "PR title with area",
title: "e2e: improve logging for a detected rollout",
area: "e2e",
title: "test: improve logging for a detected rollout",
want: "improve logging for a detected rollout",
},
{
name: "PR title without area",
title: "improve logging for a detected rollout",
area: "e2e",
want: "improve logging for a detected rollout",
},
{
name: "PR title without area being prefixed",
title: "test/e2e: improve logging for a detected rollout",
area: "e2e",
want: "test/e2e: improve logging for a detected rollout",
want: "improve logging for a detected rollout",
},
{
name: "PR title without space between area and title",
title: "e2e:improve logging for a detected rollout",
area: "e2e",
want: "improve logging for a detected rollout",
},
{
name: "PR title with space between area and title",
title: "e2e/test: improve logging for a detected rollout",
want: "improve logging for a detected rollout",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := trimAreaFromTitle(tt.title, tt.area); got != tt.want {
if got := trimAreaFromTitle(tt.title); got != tt.want {
t.Errorf("trimAreaFromTitle() = %v, want %v", got, tt.want)
}
})
Expand Down
20 changes: 9 additions & 11 deletions hack/tools/release/notes/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ import (
)

const (
missingAreaLabelPrefix = "MISSING_AREA"
areaLabelPrefix = "area/"
multipleAreaLabelsPrefix = "MULTIPLE_AREAS["
documentationArea = "Documentation"
missingAreaLabelPrefix = "MISSING_AREA"
areaLabelPrefix = "area/"
documentationArea = "Documentation"
)

var (
Expand Down Expand Up @@ -192,7 +191,7 @@ func (g prEntriesProcessor) generateNoteEntry(p *pr) *notesEntry {
}

if g.addAreaPrefix {
entry.title = trimAreaFromTitle(entry.title, area)
entry.title = trimAreaFromTitle(entry.title)
entry.title = capitalize(entry.title)
entry.title = fmt.Sprintf("- %s: %s", area, entry.title)
} else {
Expand Down Expand Up @@ -227,7 +226,7 @@ func (g prEntriesProcessor) extractArea(pr *pr) string {
case 1:
return areaLabels[0]
default:
return multipleAreaLabelsPrefix + strings.Join(areaLabels, "/") + "]"
return strings.Join(areaLabels, "/")
}
}

Expand Down Expand Up @@ -281,11 +280,10 @@ func removePrefixes(title string, prefixes []string) string {
}

// trimAreaFromTitle removes the prefixed area from title to avoid duplication.
func trimAreaFromTitle(title, area string) string {
titleWithoutArea := title
pattern := `(?i)^` + regexp.QuoteMeta(area+":")
re := regexp.MustCompile(pattern)
titleWithoutArea = re.ReplaceAllString(titleWithoutArea, "")
func trimAreaFromTitle(title string) string {
re := regexp.MustCompile(`^[^:]*:\s*`)
titleWithoutArea := re.ReplaceAllString(title, "")
titleWithoutArea = strings.TrimSpace(titleWithoutArea)

return titleWithoutArea
}
Loading