Skip to content

Commit

Permalink
Consolidate into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Sep 5, 2023
1 parent 9017bba commit 8a2a340
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 242 deletions.
141 changes: 129 additions & 12 deletions hack/tools/release/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ 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"
weeklySubCommand = "weekly"
)

var (
Expand All @@ -63,6 +64,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.")
Expand Down Expand Up @@ -104,10 +115,11 @@ var (
}

releaseBackportMarker = regexp.MustCompile(`(?m)^\[release-\d\.\d\]\s*`)

milestone = flag.String("milestone", "v1.4", "Milestone. Accepts format: v1.4")
)

func main() {
flag.Parse()
os.Exit(run())
}

Expand Down Expand Up @@ -214,11 +226,32 @@ func run() int {

var commitRange string
var cmd *exec.Cmd
var lastDay string
var err error

subcommand := os.Args[1]
weeklyCmd := flag.NewFlagSet(weeklySubCommand, 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 == weeklySubCommand {
err = weeklyCmd.Parse(os.Args[2:])
if err != nil {
fmt.Println(err)
return 1
}
} else {
flag.Parse()
}
if *since != "" && *until != "" {
commitRange = fmt.Sprintf("%s - %s", *since, *until)
if subcommand == weeklySubCommand {
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
Expand Down Expand Up @@ -264,6 +297,16 @@ func run() int {
}
}

if subcommand == weeklySubCommand {
parseWeeklyUpdate(commits, merges, commitRange, lastDay)
} else {
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
Expand Down Expand Up @@ -387,7 +430,7 @@ REPLACE ME: A couple sentences describing the deprecation, including links to do
)
}
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])
Expand All @@ -403,8 +446,82 @@ REPLACE ME: A couple sentences describing the deprecation, including links to do

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 {
Expand Down
Loading

0 comments on commit 8a2a340

Please sign in to comment.