Skip to content

Commit

Permalink
Add release notes expander functionality
Browse files Browse the repository at this point in the history
Signed-off-by: chandankumar4 <chandan.kr404@gmail.com>
  • Loading branch information
chandankumar4 committed Mar 7, 2024
1 parent 22ec35e commit 6931f3a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 31 deletions.
30 changes: 22 additions & 8 deletions hack/tools/release/notes/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type pr struct {

// prLister returns a list of PRs.
type prLister interface {
listPRs() ([]pr, error)
listPRs(previousRelease ref) ([]pr, error)
}

// notesEntry represents a line item for the release notes.
Expand All @@ -67,25 +67,39 @@ type prProcessor interface {
// entriesPrinter formats and outputs to stdout the notes
// based on a list of entries.
type entriesPrinter interface {
print([]notesEntry, int, string)
print([]notesEntry, int, string, ref)
}

// run generates and prints the notes.
func (g *notesGenerator) run() error {
prs, err := g.lister.listPRs()
// run generating and prints the notes.
func (g *notesGenerator) run(previousReleaseRef ref) error {
if previousReleaseRef.value != "" {
previousReleasePRs, err := g.lister.listPRs(previousReleaseRef)
if err != nil {
return err
}
previousEntries := g.processor.process(previousReleasePRs)

dependencies, err := g.dependenciesProcessor.generateDependencies(previousReleaseRef)
if err != nil {
return err
}

g.printer.print(previousEntries, len(previousReleasePRs), dependencies, previousReleaseRef)
}

prs, err := g.lister.listPRs(ref{})
if err != nil {
return err
}

entries := g.processor.process(prs)

dependencies, err := g.dependenciesProcessor.generateDependencies()
dependencies, err := g.dependenciesProcessor.generateDependencies(ref{})
if err != nil {
return err
}

// Pass in length of PRs to printer as some PRs are excluded from the entries list
g.printer.print(entries, len(prs), dependencies)
g.printer.print(entries, len(prs), dependencies, ref{})

return nil
}
15 changes: 12 additions & 3 deletions hack/tools/release/notes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ func newGithubFromToPRLister(repo string, fromRef, toRef ref, branch string) *gi
// between fromRef and toRef, discarding any PR not seeing in the commits list.
// This ensures we don't include any PR merged in the same date range that
// doesn't belong to our git timeline.
func (l *githubFromToPRLister) listPRs() ([]pr, error) {
log.Printf("Computing diff between %s and %s", l.fromRef, l.toRef)
diff, err := l.client.getDiffAllCommits(l.fromRef.value, l.toRef.value)
func (l *githubFromToPRLister) listPRs(previousReleaseRef ref) ([]pr, error) {
var (
diff *githubDiff
err error
)
if previousReleaseRef.value != "" {
log.Printf("Computing diff between %s and %s", previousReleaseRef.value, l.toRef)
diff, err = l.client.getDiffAllCommits(previousReleaseRef.value, l.toRef.value)
} else {
log.Printf("Computing diff between %s and %s", l.fromRef, l.toRef)
diff, err = l.client.getDiffAllCommits(l.fromRef.value, l.toRef.value)
}
if err != nil {
return nil, err
}
Expand Down
15 changes: 14 additions & 1 deletion hack/tools/release/notes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type notesCmdConfig struct {
toRef string
newTag string
branch string
previousReleaseVersion string
prefixAreaLabel bool
preReleaseVersion bool
deprecation bool
Expand All @@ -65,6 +66,7 @@ func readCmdConfig() *notesCmdConfig {
flag.StringVar(&config.toRef, "to", "", "The ref (tag, branch or commit to stop at. It must be formatted as heads/<branch name> for branches and tags/<tag name> for tags. If not set, it will default to branch.")
flag.StringVar(&config.branch, "branch", "", "The branch to generate the notes from. If not set, it will be calculated from release.")
flag.StringVar(&config.newTag, "release", "", "The tag for the new release.")
flag.StringVar(&config.previousReleaseVersion, "previous-release-version", "", "The tag for the previous beta release.")

flag.BoolVar(&config.prefixAreaLabel, "prefix-area-label", true, "If enabled, will prefix the area label.")
flag.BoolVar(&config.preReleaseVersion, "pre-release-version", false, "If enabled, will add a pre-release warning header. (default false)")
Expand Down Expand Up @@ -102,6 +104,11 @@ func (cmd *notesCmd) run() error {

from, to := parseRef(cmd.config.fromRef), parseRef(cmd.config.toRef)

var previousReleaseRef ref
if cmd.config.previousReleaseVersion != "" {
previousReleaseRef = parseRef(cmd.config.previousReleaseVersion)
}

printer := newReleaseNotesPrinter(cmd.config.repo, from.value)
printer.isPreRelease = cmd.config.preReleaseVersion
printer.printDeprecation = cmd.config.deprecation
Expand All @@ -114,7 +121,7 @@ func (cmd *notesCmd) run() error {
newDependenciesProcessor(cmd.config.repo, from.value, to.value),
)

return generator.run()
return generator.run(previousReleaseRef)
}

func ensureInstalledDependencies() error {
Expand Down Expand Up @@ -151,6 +158,12 @@ func validateConfig(config *notesCmdConfig) error {
}
}

if config.preReleaseVersion {
if config.previousReleaseVersion == "" {
return errors.New("--previous-release-version need to be set with --pre-release-version as true")
}
}

return nil
}

Expand Down
51 changes: 34 additions & 17 deletions hack/tools/release/notes/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var defaultOutputOrder = []string{
release.Unknown,
}

var isExpanderAdded = false

// releaseNotesPrinter outputs the PR entries following
// the right format for the release notes.
type releaseNotesPrinter struct {
Expand All @@ -57,7 +59,7 @@ func newReleaseNotesPrinter(repo, fromTag string) *releaseNotesPrinter {
}

// print outputs to stdout the release notes.
func (p *releaseNotesPrinter) print(entries []notesEntry, commitsInRelease int, dependencies string) {
func (p *releaseNotesPrinter) print(entries []notesEntry, commitsInRelease int, dependencies string, previousReleaseRef ref) {
merges := map[string][]string{
release.Features: {},
release.Bugs: {},
Expand All @@ -76,10 +78,14 @@ func (p *releaseNotesPrinter) print(entries []notesEntry, commitsInRelease int,
}

if p.isPreRelease {
fmt.Printf("🚨 This is a RELEASE CANDIDATE. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/%s/issues/new).\n", p.repo)
fmt.Printf("🚨 This is a RELEASE CANDIDATE/BETA RELEASE. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/%s/issues/new).\n", p.repo)
}

if p.printKubernetesSupport {
if p.printKubernetesSupport && previousReleaseRef.value == "" {
// This will add the release notes expansion functionality for pre-release version
fmt.Print("<details>\n<summary>More details about the release</summary>\n")
isExpanderAdded = true

fmt.Print(`## 👌 Kubernetes version support
- Management Cluster: v1.**X**.x -> v1.**X**.x
Expand All @@ -106,7 +112,11 @@ REPLACE ME: A couple sentences describing the deprecation, including links to do
`)
}

fmt.Printf("## Changes since %s\n", p.fromTag)
if previousReleaseRef.value != "" {
fmt.Printf("## Changes since %s\n", previousReleaseRef.value)
} else {
fmt.Printf("## Changes since %s\n", p.fromTag)
}

fmt.Printf("## :chart_with_upwards_trend: Overview\n")
if commitsInRelease == 1 {
Expand Down Expand Up @@ -139,18 +149,20 @@ REPLACE ME: A couple sentences describing the deprecation, including links to do

switch key {
case release.Documentation:
sort.Strings(mergeslice)
if len(mergeslice) == 1 {
fmt.Printf(
":book: Additionally, there has been 1 contribution to our documentation and book. (%s) \n\n",
mergeslice[0],
)
} else {
fmt.Printf(
":book: Additionally, there have been %d contributions to our documentation and book. (%s) \n\n",
len(mergeslice),
strings.Join(mergeslice, ", "),
)
if previousReleaseRef.value == "" {
sort.Strings(mergeslice)
if len(mergeslice) == 1 {
fmt.Printf(
":book: Additionally, there has been 1 contribution to our documentation and book. (%s) \n\n",
mergeslice[0],
)
} else {
fmt.Printf(
":book: Additionally, there have been %d contributions to our documentation and book. (%s) \n\n",
len(mergeslice),
strings.Join(mergeslice, ", "),
)
}
}
default:
fmt.Println("## " + key)
Expand All @@ -170,5 +182,10 @@ REPLACE ME: A couple sentences describing the deprecation, including links to do
fmt.Print(dependencies)

fmt.Println("")
fmt.Println("_Thanks to all our contributors!_ 😊")
if isExpanderAdded {
fmt.Print("</details>\n<br/>\n")
}
if previousReleaseRef.value == "" {
fmt.Println("_Thanks to all our contributors!_ 😊")
}
}
12 changes: 10 additions & 2 deletions hack/tools/release/notes/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@ func (g prEntriesProcessor) process(prs []pr) []notesEntry {
return entries
}

func (d dependenciesProcessor) generateDependencies() (string, error) {
func (d dependenciesProcessor) generateDependencies(previousRelease ref) (string, error) {
repoURL := fmt.Sprintf("https://github.com/%s", d.repo)

var fromTag string
if previousRelease.value != "" {
fromTag = previousRelease.value
} else {
fromTag = d.fromTag
}

deps, err := notes.NewDependencies().ChangesForURL(
repoURL, d.fromTag, d.toTag,
repoURL, fromTag, d.toTag,
)
if err != nil {
return "", err
Expand Down

0 comments on commit 6931f3a

Please sign in to comment.