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

🌱 Improve release notes formatting #9337

Merged
Merged
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
23 changes: 15 additions & 8 deletions hack/tools/release/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func run() int {

switch key {
case documentation:
sort.Strings(mergeslice)
if len(mergeslice) == 1 {
fmt.Printf(
":book: Additionally, there has been 1 contribution to our documentation and book. (%s) \n\n",
Expand Down Expand Up @@ -435,14 +436,14 @@ type releaseNoteEntry struct {
prNumber string
}

// modifyEntryTitle removes the specified prefixes from the title.
func modifyEntryTitle(title string, prefixes []string) string {
// removePrefixes removes the specified prefixes from the title.
func removePrefixes(title string, prefixes []string) string {
entryWithoutTag := title
for _, prefix := range prefixes {
entryWithoutTag = strings.TrimLeft(strings.TrimPrefix(entryWithoutTag, prefix), " ")
}

return strings.ToUpper(string(entryWithoutTag[0])) + entryWithoutTag[1:]
return entryWithoutTag
}

// trimAreaFromTitle removes the prefixed area from title to avoid duplication.
Expand All @@ -455,6 +456,10 @@ func trimAreaFromTitle(title, area string) string {
return titleWithoutArea
}

func capitalize(str string) string {
return strings.ToUpper(string(str[0])) + str[1:]
}

// generateReleaseNoteEntry processes a commit into a PR line item for the release notes.
func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
entry := &releaseNoteEntry{}
Expand All @@ -476,22 +481,22 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
switch {
case strings.HasPrefix(entry.title, ":sparkles:"), strings.HasPrefix(entry.title, "✨"):
entry.section = features
entry.title = modifyEntryTitle(entry.title, []string{":sparkles:", "✨"})
entry.title = removePrefixes(entry.title, []string{":sparkles:", "✨"})
case strings.HasPrefix(entry.title, ":bug:"), strings.HasPrefix(entry.title, "🐛"):
entry.section = bugs
entry.title = modifyEntryTitle(entry.title, []string{":bug:", "🐛"})
entry.title = removePrefixes(entry.title, []string{":bug:", "🐛"})
case strings.HasPrefix(entry.title, ":book:"), strings.HasPrefix(entry.title, "📖"):
entry.section = documentation
entry.title = modifyEntryTitle(entry.title, []string{":book:", "📖"})
entry.title = removePrefixes(entry.title, []string{":book:", "📖"})
if strings.Contains(entry.title, "CAEP") || strings.Contains(entry.title, "proposal") {
entry.section = proposals
}
case strings.HasPrefix(entry.title, ":seedling:"), strings.HasPrefix(entry.title, "🌱"):
entry.section = other
entry.title = modifyEntryTitle(entry.title, []string{":seedling:", "🌱"})
entry.title = removePrefixes(entry.title, []string{":seedling:", "🌱"})
case strings.HasPrefix(entry.title, ":warning:"), strings.HasPrefix(entry.title, "⚠️"):
entry.section = warning
entry.title = modifyEntryTitle(entry.title, []string{":warning:", "⚠️"})
entry.title = removePrefixes(entry.title, []string{":warning:", "⚠️"})
default:
entry.section = unknown
}
Expand All @@ -513,8 +518,10 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {

if *prefixAreaLabel {
entry.title = trimAreaFromTitle(entry.title, area)
entry.title = capitalize(entry.title)
entry.title = fmt.Sprintf("- %s: %s", area, entry.title)
} else {
entry.title = capitalize(entry.title)
entry.title = fmt.Sprintf("- %s", entry.title)
}

Expand Down