Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Deduplicating area in pr title in release notes #9186

Merged
merged 1 commit into from
Aug 28, 2023
Merged
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
12 changes: 12 additions & 0 deletions hack/tools/release/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ type releaseNoteEntry struct {
prNumber string
}

// modifyEntryTitle removes the specified prefixes from the title.
func modifyEntryTitle(title string, prefixes []string) string {
entryWithoutTag := title
for _, prefix := range prefixes {
Expand All @@ -444,6 +445,16 @@ func modifyEntryTitle(title string, prefixes []string) string {
return strings.ToUpper(string(entryWithoutTag[0])) + entryWithoutTag[1:]
}

// trimAreaFromTitle removes the prefixed area from title to avoid duplication.
func trimAreaFromTitle(title, area string) string {
Dhairya-Arora01 marked this conversation as resolved.
Show resolved Hide resolved
titleWithoutArea := title
pattern := `(?i)^` + regexp.QuoteMeta(area+":")
re := regexp.MustCompile(pattern)
titleWithoutArea = re.ReplaceAllString(titleWithoutArea, "")
titleWithoutArea = strings.TrimSpace(titleWithoutArea)
return titleWithoutArea
}

// generateReleaseNoteEntry processes a commit into a PR line item for the release notes.
func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
entry := &releaseNoteEntry{}
Expand Down Expand Up @@ -501,6 +512,7 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
}

if *prefixAreaLabel {
entry.title = trimAreaFromTitle(entry.title, area)
entry.title = fmt.Sprintf("- %s: %s", area, entry.title)
} else {
entry.title = fmt.Sprintf("- %s", entry.title)
Expand Down
42 changes: 42 additions & 0 deletions hack/tools/release/notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,45 @@ func Test_trimTitle(t *testing.T) {
})
}
}

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",
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",
},
{
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",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := trimAreaFromTitle(tt.title, tt.area); got != tt.want {
t.Errorf("trimAreaFromTitle() = %v, want %v", got, tt.want)
}
})
}
}
Loading