Skip to content

Commit

Permalink
hack/release-notes: ensure relase notes tool can be used for external
Browse files Browse the repository at this point in the history
projects again

Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed Jul 20, 2023
1 parent 0cbde4a commit 94afcd4
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions hack/tools/release/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ var (
unknown,
}

repo = flag.String("repository", "kubernetes-sigs/cluster-api", "The tag or commit to start from.")

fromTag = flag.String("from", "", "The tag or commit to start from.")

since = flag.String("since", "", "Include commits starting from and including this date. Accepts format: YYYY-MM-DD")
until = flag.String("until", "", "Include commits up to and including this date. Accepts format: YYYY-MM-DD")
numWorkers = flag.Int("workers", 10, "Number of concurrent routines to process PR entries. If running into GitHub rate limiting, use 1.")

prefixAreaLabel = flag.Bool("prefix-area-label", true, "If enabled, will prefix the area label.")

addKubernetesVersionSupport = flag.Bool("add-kubernetes-version-support", true, "If enabled, will add the Kubernetes version support header.")

tagRegex = regexp.MustCompile(`^\[release-[\w-\.]*\]`)

userFriendlyAreas = map[string]string{
Expand Down Expand Up @@ -154,7 +160,7 @@ func getAreaLabel(merge string) (string, error) {
// Get pr id from merge commit
prID := strings.Replace(strings.TrimSpace(strings.Split(merge, " ")[3]), "#", "", -1)

cmd := exec.Command("gh", "api", "repos/kubernetes-sigs/cluster-api/pulls/"+prID) //nolint:gosec
cmd := exec.Command("gh", "api", fmt.Sprintf("repos/%s/pulls/%s", *repo, prID)) //nolint:gosec

out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -301,15 +307,18 @@ func run() int {
}
}

// TODO Turn this into a link (requires knowing the project name + organization)
fmt.Print(`## 👌 Kubernetes version support
if *addKubernetesVersionSupport {
// TODO Turn this into a link (requires knowing the project name + organization)
fmt.Print(`## 👌 Kubernetes version support
- Management Cluster: v1.**X**.x -> v1.**X**.x
- Workload Cluster: v1.**X**.x -> v1.**X**.x
[More information about version support can be found here](https://cluster-api.sigs.k8s.io/reference/versions.html)
`)
}

fmt.Printf("## Changes since %v\n---\n", commitRange)

fmt.Printf("## :chart_with_upwards_trend: Overview\n")
Expand Down Expand Up @@ -411,9 +420,14 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
entry := &releaseNoteEntry{}
entry.title = trimTitle(c.body)
var fork string
area, err := getAreaLabel(c.merge)
if err != nil {
return nil, err

var area string
if *prefixAreaLabel {
var err error
area, err = getAreaLabel(c.merge)
if err != nil {
return nil, err
}
}

switch {
Expand Down Expand Up @@ -458,7 +472,13 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {
if entry.title == "" {
return entry, nil
}
entry.title = fmt.Sprintf("- %s: %s", area, entry.title)

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

_, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &entry.prNumber, &fork)
entry.title = formatMerge(entry.title, entry.prNumber)

Expand Down

0 comments on commit 94afcd4

Please sign in to comment.