Skip to content

Commit 410cf44

Browse files
committed
Improve release notes formatting
* Capitalize/shorten some area labels into more legible prefixes * Remove backport PR prefixes "[release-x.x]" * Omit "num of change of type x" lines when there are no changes of that kind (eg. no breaking changes) * Handle unsync emoji and documentation area
1 parent 7b64459 commit 410cf44

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

hack/tools/release/notes.go

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ var (
7070
numWorkers = flag.Int("workers", 10, "Number of concurrent routines to process PR entries. If running into GitHub rate limiting, use 1.")
7171

7272
tagRegex = regexp.MustCompile(`^\[release-[\w-\.]*\]`)
73+
74+
userFriendlyAreas = map[string]string{
75+
"e2e-testing": "e2e",
76+
"provider/control-plane-kubeadm": "KCP",
77+
"provider/infrastructure-docker": "CAPD",
78+
"dependency": "Dependency",
79+
"devtools": "Devtools",
80+
"machine": "Machine",
81+
"api": "API",
82+
}
83+
84+
releaseBackportMarker = regexp.MustCompile(`(?m)^\[release-\d\.\d\]\s*`)
7385
)
7486

7587
func main() {
@@ -113,6 +125,7 @@ const (
113125
missingAreaLabelPrefix = "MISSING_AREA"
114126
areaLabelPrefix = "area/"
115127
multipleAreaLabelsPrefix = "MULTIPLE_AREAS["
128+
documentationAreaLabel = "documentation"
116129
)
117130

118131
type githubPullRequest struct {
@@ -150,7 +163,11 @@ func getAreaLabel(merge string) (string, error) {
150163
case 0:
151164
return missingAreaLabelPrefix, nil
152165
case 1:
153-
return areaLabels[0], nil
166+
area := areaLabels[0]
167+
if userFriendlyArea, ok := userFriendlyAreas[area]; ok {
168+
area = userFriendlyArea
169+
}
170+
return area, nil
154171
default:
155172
return multipleAreaLabelsPrefix + strings.Join(areaLabels, "|") + "]", nil
156173
}
@@ -274,10 +291,18 @@ func run() int {
274291
fmt.Printf("Changes since %v\n---\n", commitRange)
275292

276293
fmt.Printf("## :chart_with_upwards_trend: Overview\n")
277-
fmt.Printf("- %d new commits merged\n", len(commits))
278-
fmt.Printf("- %d breaking changes :warning:\n", len(merges[warning]))
279-
fmt.Printf("- %d feature additions ✨\n", len(merges[features]))
280-
fmt.Printf("- %d bugs fixed 🐛\n", len(merges[bugs]))
294+
if count := len(commits); count > 0 {
295+
fmt.Printf("- %d new commits merged\n", count)
296+
}
297+
if count := len(merges[warning]); count > 0 {
298+
fmt.Printf("- %d breaking changes :warning:\n", count)
299+
}
300+
if count := len(merges[features]); count > 0 {
301+
fmt.Printf("- %d feature additions ✨\n", count)
302+
}
303+
if count := len(merges[bugs]); count > 0 {
304+
fmt.Printf("- %d bugs fixed 🐛\n", count)
305+
}
281306
fmt.Println()
282307

283308
for _, key := range outputOrder {
@@ -364,7 +389,7 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
364389
entry := &releaseNoteEntry{}
365390
entry.title = trimTitle(c.body)
366391
var fork string
367-
prefix, err := getAreaLabel(c.merge)
392+
area, err := getAreaLabel(c.merge)
368393
if err != nil {
369394
return nil, err
370395
}
@@ -397,13 +422,29 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
397422
entry.section = unknown
398423
}
399424

425+
// If the area label indicates documentation, use documentation as the section
426+
// no matter what was the emoji used. This takes into account that the area label
427+
// tends to be more accurate than the emoji (data point observed by the release team).
428+
// We handle this after the switch statement to make sure we remove all emoji prefixes.
429+
if area == documentationAreaLabel {
430+
entry.section = documentation
431+
}
432+
400433
entry.title = strings.TrimSpace(entry.title)
434+
entry.title = trimReleaseBackportMarker(entry.title)
435+
401436
if entry.title == "" {
402437
return entry, nil
403438
}
404-
entry.title = fmt.Sprintf("- %s: %s", prefix, entry.title)
439+
entry.title = fmt.Sprintf("- %s: %s", area, entry.title)
405440
_, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &entry.prNumber, &fork)
406441
entry.title = formatMerge(entry.title, entry.prNumber)
407442

408443
return entry, nil
409444
}
445+
446+
// trimReleaseBackportMarker removes the `[release-x.x]` prefix from a PR title if present.
447+
// These are mostly used for back-ported PRs in release branches.
448+
func trimReleaseBackportMarker(title string) string {
449+
return releaseBackportMarker.ReplaceAllString(title, "${1}")
450+
}

0 commit comments

Comments
 (0)