Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#887 from mumoshu/relnote4final
Browse files Browse the repository at this point in the history
relnote: Add support for release notes of final versions
  • Loading branch information
mumoshu authored Aug 30, 2017
2 parents a2daf1a + 2b17f39 commit 9e4101a
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 29 deletions.
14 changes: 14 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@

To generate a release note for the release `v0.9.8-rc.1` in Markdown:


The pre-requisite is to run `go get` several times to install dependencies:

```
$ go get -u "github.com/google/go-github/github"
$ go get -u "golang.org/x/oauth2"
$ go get -u "golang.org/x/context"
```

For a release note for a release-candidate version of kube-aws, run:

```
$ VERSION=v0.9.8-rc.1 go run relnotes.go
```

For one for a final version, run:

```
$ VERSION=v0.9.8 go run relnotes.go
```
113 changes: 84 additions & 29 deletions hack/relnote.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"os"
"os/exec"
"sort"
"strings"

"github.com/google/go-github/github"
Expand All @@ -32,6 +33,10 @@ func Info(msg string) {
println(msg)
}

func Title(title string) {
fmt.Printf("\n# %s\n\n", title)
}

func Header(title string) {
fmt.Printf("\n## %s\n\n", title)
}
Expand Down Expand Up @@ -160,33 +165,19 @@ func indent(orig string, num int) string {
return buf.String()
}

func generateNote(primaryMaintainer string, org string, repository string, releaseVersion string) {
accessToken, found := os.LookupEnv("GITHUB_ACCESS_TOKEN")
if !found {
exitWithErrorMessage("GITHUB_ACCESS_TOKEN must be set")
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: accessToken},
)
tc := oauth2.NewClient(ctx, ts)

client := github.NewClient(tc)

milestoneOpt := &github.MilestoneListOptions{
ListOptions: github.ListOptions{PerPage: 10},
}
type Config struct {
ctx context.Context
client *github.Client
org string
repository string
primaryMaintainer string
}

allMilestones := []*github.Milestone{}
for {
milestones, resp, err := client.Issues.ListMilestones(ctx, org, repository, milestoneOpt)
PanicIfError(err)
allMilestones = append(allMilestones, milestones...)
if resp.NextPage == 0 {
break
}
milestoneOpt.Page = resp.NextPage
}
func collectIssuesForMilestoneNamed(releaseVersion string, config Config, allMilestones []*github.Milestone) []Item {
ctx := config.ctx
client := config.client
org := config.org
repository := config.repository

milestoneNumber := -1
for _, m := range allMilestones {
Expand Down Expand Up @@ -229,7 +220,7 @@ func generateNote(primaryMaintainer string, org string, repository string, relea
num := issue.GetNumber()
title := issue.GetTitle()
summary := ""
if login != primaryMaintainer {
if login != config.primaryMaintainer {
summary = fmt.Sprintf("#%d: %s(Thanks to @%s)", num, title, login)
} else {
summary = fmt.Sprintf("#%d: %s", num, title)
Expand All @@ -251,7 +242,8 @@ func generateNote(primaryMaintainer string, org string, repository string, relea
fmt.Printf("%s is doc update\n", title)
}

isMiscUpdate := onlyMiscFilesAreChanged(changedFiles)
isMiscUpdate := labels.Contains("release-infra") ||
onlyMiscFilesAreChanged(changedFiles)
if isMiscUpdate {
fmt.Printf("%s is misc update\n", title)
}
Expand Down Expand Up @@ -314,7 +306,70 @@ func generateNote(primaryMaintainer string, org string, repository string, relea
opt.Page = resp.NextPage
}

Info("# Changelog since v")
return items
}

func generateNote(primaryMaintainer string, org string, repository string, releaseVersion string) {
rc := strings.Contains(releaseVersion, "rc")

accessToken, found := os.LookupEnv("GITHUB_ACCESS_TOKEN")
if !found {
exitWithErrorMessage("GITHUB_ACCESS_TOKEN must be set")
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: accessToken},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)

config := Config{
ctx: ctx,
client: client,
primaryMaintainer: primaryMaintainer,
org: org,
repository: repository,
}

milestoneOpt := &github.MilestoneListOptions{
ListOptions: github.ListOptions{PerPage: 10},
}

allMilestones := []*github.Milestone{}
for {
milestones, resp, err := client.Issues.ListMilestones(ctx, org, repository, milestoneOpt)
PanicIfError(err)
allMilestones = append(allMilestones, milestones...)
if resp.NextPage == 0 {
break
}
milestoneOpt.Page = resp.NextPage
}

milestoneNames := []string{}

if rc {
milestoneNames = append(milestoneNames, releaseVersion)
} else {
for _, m := range allMilestones {
if strings.HasPrefix(m.GetTitle(), releaseVersion) {
milestoneNames = append(milestoneNames, m.GetTitle())
}
}
}

sort.Strings(milestoneNames)

fmt.Printf("Aggregating milestones: %s\n", strings.Join(milestoneNames, ", "))

items := []Item{}
for _, n := range milestoneNames {
is := collectIssuesForMilestoneNamed(n, config, allMilestones)
items = append(items, is...)
}

Title("Changelog since v")
Info("Please see our [roadmap](https://github.com/kubernetes-incubator/kube-aws/blob/master/ROADMAP.md) for details on upcoming releases.")

Header("Component versions")

Expand Down

0 comments on commit 9e4101a

Please sign in to comment.