Skip to content

Commit ab58cf1

Browse files
committed
feat: Update release notes tool to handle multiples_areas and colons
Signed-off-by: chandankumar4 <[email protected]>
1 parent ee5af7b commit ab58cf1

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

hack/tools/release/notes/main_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,38 @@ func Test_trimAreaFromTitle(t *testing.T) {
7272
tests := []struct {
7373
name string
7474
title string
75-
area string
7675
want string
7776
}{
7877
{
7978
name: "PR title with area",
80-
title: "e2e: improve logging for a detected rollout",
81-
area: "e2e",
79+
title: "test: improve logging for a detected rollout",
8280
want: "improve logging for a detected rollout",
8381
},
8482
{
8583
name: "PR title without area",
8684
title: "improve logging for a detected rollout",
87-
area: "e2e",
8885
want: "improve logging for a detected rollout",
8986
},
9087
{
9188
name: "PR title without area being prefixed",
9289
title: "test/e2e: improve logging for a detected rollout",
93-
area: "e2e",
94-
want: "test/e2e: improve logging for a detected rollout",
90+
want: "improve logging for a detected rollout",
9591
},
9692
{
9793
name: "PR title without space between area and title",
9894
title: "e2e:improve logging for a detected rollout",
99-
area: "e2e",
95+
want: "improve logging for a detected rollout",
96+
},
97+
{
98+
name: "PR title with space between area and title",
99+
title: "e2e/test: improve logging for a detected rollout",
100100
want: "improve logging for a detected rollout",
101101
},
102102
}
103103

104104
for _, tt := range tests {
105105
t.Run(tt.name, func(t *testing.T) {
106-
if got := trimAreaFromTitle(tt.title, tt.area); got != tt.want {
106+
if got := trimAreaFromTitle(tt.title); got != tt.want {
107107
t.Errorf("trimAreaFromTitle() = %v, want %v", got, tt.want)
108108
}
109109
})

hack/tools/release/notes/process.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ import (
3131
)
3232

3333
const (
34-
missingAreaLabelPrefix = "MISSING_AREA"
35-
areaLabelPrefix = "area/"
36-
multipleAreaLabelsPrefix = "MULTIPLE_AREAS["
37-
documentationArea = "Documentation"
34+
missingAreaLabelPrefix = "MISSING_AREA"
35+
areaLabelPrefix = "area/"
36+
documentationArea = "Documentation"
3837
)
3938

4039
var (
@@ -192,7 +191,7 @@ func (g prEntriesProcessor) generateNoteEntry(p *pr) *notesEntry {
192191
}
193192

194193
if g.addAreaPrefix {
195-
entry.title = trimAreaFromTitle(entry.title, area)
194+
entry.title = trimAreaFromTitle(entry.title)
196195
entry.title = capitalize(entry.title)
197196
entry.title = fmt.Sprintf("- %s: %s", area, entry.title)
198197
} else {
@@ -227,7 +226,7 @@ func (g prEntriesProcessor) extractArea(pr *pr) string {
227226
case 1:
228227
return areaLabels[0]
229228
default:
230-
return multipleAreaLabelsPrefix + strings.Join(areaLabels, "/") + "]"
229+
return strings.Join(areaLabels, "/")
231230
}
232231
}
233232

@@ -281,11 +280,10 @@ func removePrefixes(title string, prefixes []string) string {
281280
}
282281

283282
// trimAreaFromTitle removes the prefixed area from title to avoid duplication.
284-
func trimAreaFromTitle(title, area string) string {
285-
titleWithoutArea := title
286-
pattern := `(?i)^` + regexp.QuoteMeta(area+":")
287-
re := regexp.MustCompile(pattern)
288-
titleWithoutArea = re.ReplaceAllString(titleWithoutArea, "")
283+
func trimAreaFromTitle(title string) string {
284+
re := regexp.MustCompile(`^[^:]*:\s*`)
285+
titleWithoutArea := re.ReplaceAllString(title, "")
289286
titleWithoutArea = strings.TrimSpace(titleWithoutArea)
287+
290288
return titleWithoutArea
291289
}

0 commit comments

Comments
 (0)