Skip to content

Commit

Permalink
hack/release-notes: add repo flag, make area label optional
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer buringerst@vmware.com
  • Loading branch information
sbueringer committed Jul 20, 2023
1 parent 0cbde4a commit af40856
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions hack/tools/release/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ var (
unknown,
}

repo = flag.String("repo", "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.")

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

userFriendlyAreas = map[string]string{
Expand Down Expand Up @@ -154,7 +158,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 @@ -411,9 +415,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 +467,11 @@ 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)
}

_, _ = 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 af40856

Please sign in to comment.