Skip to content

Commit

Permalink
Deduplicating area in title
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhairya-Arora01 committed Aug 19, 2023
1 parent a8356e4 commit 7691f8d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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 area from title to avoid duplication.
func trimAreaFromTitle(title, area string) string {
titleWithoutArea := title
position := strings.Index(title, area+":")
if position != -1 {
titleWithoutArea = strings.TrimSpace(titleWithoutArea[position+len(area+":"):])
}
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
44 changes: 44 additions & 0 deletions hack/tools/release/notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,47 @@ 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: "test/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: "improve logging for a detected rollout to improve e2e tests",
area: "e2e",
want: "improve logging for a detected rollout to improve e2e tests",
},
{
name: "PR title without space between area and title",
title: "test/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)
}
})
}

}

0 comments on commit 7691f8d

Please sign in to comment.