From 471b382b20a759c20ad831972ff2e091cd3570c7 Mon Sep 17 00:00:00 2001 From: willie-yao Date: Tue, 5 Sep 2023 22:49:21 +0000 Subject: [PATCH] Consolidate into one file --- hack/tools/release/notes.go | 134 +++++++++++++++++++++++++++++++++--- 1 file changed, 123 insertions(+), 11 deletions(-) diff --git a/hack/tools/release/notes.go b/hack/tools/release/notes.go index 70b2d28a770f..a789e4338228 100644 --- a/hack/tools/release/notes.go +++ b/hack/tools/release/notes.go @@ -43,13 +43,13 @@ Use these as the base of your release notes. */ const ( - features = ":sparkles: New Features" - bugs = ":bug: Bug Fixes" - documentation = ":book: Documentation" - proposals = ":memo: Proposals" - warning = ":warning: Breaking Changes" - other = ":seedling: Others" - unknown = ":question: Sort these by hand" + features = "New Features" + bugs = "Bug Fixes" + documentation = "Documentation" + proposals = "Proposals" + warning = "Breaking Changes" + other = "Others" + unknown = "Sort these by hand" ) var ( @@ -63,6 +63,16 @@ var ( unknown, } + emoteMap = map[string]string{ + features: ":sparkles:", + bugs: ":bug:", + documentation: ":book:", + proposals: ":memo:", + warning: ":warning:", + other: ":seedling:", + unknown: ":question:", + } + repo = flag.String("repository", "kubernetes-sigs/cluster-api", "The repo to run the tool from.") fromTag = flag.String("from", "", "The tag or commit to start from.") @@ -102,6 +112,8 @@ var ( } releaseBackportMarker = regexp.MustCompile(`(?m)^\[release-\d\.\d\]\s*`) + + milestone = flag.String("milestone", "v1.4", "Milestone. Accepts format: v1.4") ) func main() { @@ -212,11 +224,26 @@ func run() int { var commitRange string var cmd *exec.Cmd + var lastDay string + var err error + subcommand := os.Args[1] + weeklyCmd := flag.NewFlagSet("weekly", flag.ExitOnError) + weeklyCmd.StringVar(since, "since", "", "Include commits starting from and including this date. Accepts format: YYYY-MM-DD") + weeklyCmd.StringVar(until, "until", "", "Include commits up to and including this date. Accepts format: YYYY-MM-DD") + weeklyCmd.StringVar(milestone, "milestone", "v1.4", "Milestone. Accepts format: v1.4") + + if subcommand == "weekly" { + weeklyCmd.Parse(os.Args[2:]) + } if *since != "" && *until != "" { - commitRange = fmt.Sprintf("%s - %s", *since, *until) + if subcommand == "weekly" { + commitRange = fmt.Sprintf("%s to %s", *since, *until) + } else { + commitRange = fmt.Sprintf("%s - %s", *since, *until) + } - lastDay, err := increaseDateByOneDay(*until) + lastDay, err = increaseDateByOneDay(*until) if err != nil { fmt.Println(err) return 1 @@ -262,6 +289,17 @@ func run() int { } } + switch os.Args[1] { + case "weekly": + parseWeeklyUpdate(commits, merges, commitRange, lastDay) + default: + parseReleaseNotes(commits, merges, commitRange) + } + + return 0 +} + +func parseReleaseNotes(commits []*commit, merges map[string][]string, commitRange string) { results := make(chan releaseNoteEntryResult) commitCh := make(chan *commit) var wg sync.WaitGroup @@ -366,7 +404,7 @@ func run() int { ) } default: - fmt.Println("## " + key) + fmt.Println("## " + emoteMap[key] + " " + key) sort.Slice(mergeslice, func(i int, j int) bool { str1 := strings.ToLower(mergeslice[i]) str2 := strings.ToLower(mergeslice[j]) @@ -382,8 +420,82 @@ func run() int { fmt.Println("") fmt.Println("_Thanks to all our contributors!_ 😊") +} - return 0 +func parseWeeklyUpdate(commits []*commit, merges map[string][]string, commitRange string, lastDay string) { + for _, c := range commits { + body := trimTitle(c.body) + var key, prNumber, fork string + switch { + case strings.HasPrefix(body, ":sparkles:"), strings.HasPrefix(body, "✨"): + key = features + body = strings.TrimPrefix(body, ":sparkles:") + body = strings.TrimPrefix(body, "✨") + case strings.HasPrefix(body, ":bug:"), strings.HasPrefix(body, "🐛"): + key = bugs + body = strings.TrimPrefix(body, ":bug:") + body = strings.TrimPrefix(body, "🐛") + case strings.HasPrefix(body, ":book:"), strings.HasPrefix(body, "📖"): + key = documentation + body = strings.TrimPrefix(body, ":book:") + body = strings.TrimPrefix(body, "📖") + if strings.Contains(body, "CAEP") || strings.Contains(body, "proposal") { + key = proposals + } + case strings.HasPrefix(body, ":seedling:"), strings.HasPrefix(body, "🌱"): + key = other + body = strings.TrimPrefix(body, ":seedling:") + body = strings.TrimPrefix(body, "🌱") + case strings.HasPrefix(body, ":warning:"), strings.HasPrefix(body, "⚠️"): + key = warning + body = strings.TrimPrefix(body, ":warning:") + body = strings.TrimPrefix(body, "⚠️") + default: + key = unknown + } + + body = strings.TrimSpace(body) + if body == "" { + continue + } + body = fmt.Sprintf("\t - %s", body) + _, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &prNumber, &fork) + if key == documentation { + merges[key] = append(merges[key], prNumber) + continue + } + merges[key] = append(merges[key], formatMerge(body, prNumber)) + } + + // TODO Turn this into a link (requires knowing the project name + organization) + fmt.Println("Weekly update :rotating_light:") + fmt.Printf("Changes from %v a total of %d new commits where merged into main.\n\n", commitRange, len(commits)) + + for _, key := range outputOrder { + mergeslice := merges[key] + if len(mergeslice) == 0 { + continue + } + + switch key { + case documentation: + fmt.Printf("- %d Documentation and book contributions :book: \n\n", len(mergeslice)) + case other: + fmt.Printf("- %d Other changes :seedling:\n\n", len(merges[other])) + default: + fmt.Printf("- %d %s %s\n", len(merges[key]), key, emoteMap[key]) + for _, merge := range mergeslice { + fmt.Println(merge) + } + fmt.Println() + } + } + + fmt.Println("All merged PRs can be viewed in GitHub:") + fmt.Println("https://github.com/kubernetes-sigs/cluster-api/pulls?q=is%3Apr+closed%3A" + *since + ".." + lastDay + "+is%3Amerged+milestone%3A" + *milestone + "+\n") + + fmt.Println("_Thanks to all our contributors!_ 😊") + fmt.Println("/Your friendly comms release team") } func trimTitle(title string) string {