From ac88082399d19657290f0e8915081be6654b5571 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 28 Aug 2018 16:12:23 -0700 Subject: [PATCH 1/3] Update mailmap file Signed-off-by: Derek McGowan --- .mailmap | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.mailmap b/.mailmap index a14e7f650..01633f51c 100644 --- a/.mailmap +++ b/.mailmap @@ -3,6 +3,8 @@ Abhinandan Prativadi abhi Akihiro Suda Akihiro Suda Andrei Vagin Andrei Vagin Frank Yang frank yang +Jie Zhang kadisi +John Howard John Howard Justin Terry Justin Terry (VM) Justin Terry Justin Kenfe-Mickaƫl Laventure Kenfe-Mickael Laventure From f76a5ec83a042e29baf4f1eb540a31c0ee9d3abd Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 28 Aug 2018 16:12:56 -0700 Subject: [PATCH 2/3] Update template Fix spacing on releases. Add tag prefix line Signed-off-by: Derek McGowan --- cmd/containerd-release/main.go | 21 ++++++++++++++++++--- cmd/containerd-release/template.go | 6 ++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/containerd-release/main.go b/cmd/containerd-release/main.go index 27fb8e492..7130677d6 100644 --- a/cmd/containerd-release/main.go +++ b/cmd/containerd-release/main.go @@ -24,8 +24,10 @@ import ( "path/filepath" "regexp" "sort" + "strings" "text/tabwriter" "text/template" + "unicode" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -84,6 +86,7 @@ type release struct { Changes []projectChange Contributors []string Dependencies []dependency + Tag string Version string Downloads []download } @@ -105,7 +108,11 @@ This tool should be ran from the root of the project repository for a new releas Usage: "show debug output", }, cli.StringFlag{ - Name: "template,t", + Name: "tag,t", + Usage: "tag name for the release, defaults to release file name", + }, + cli.StringFlag{ + Name: "template", Usage: "template filepath to use in place of the default", Value: defaultTemplateFile, }, @@ -113,8 +120,12 @@ This tool should be ran from the root of the project repository for a new releas app.Action = func(context *cli.Context) error { var ( releasePath = context.Args().First() - tag = parseTag(releasePath) + tag = context.String("tag") ) + if tag == "" { + tag = parseTag(releasePath) + } + version := strings.TrimLeft(tag, "v") if context.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) } @@ -226,7 +237,11 @@ This tool should be ran from the root of the project repository for a new releas r.Contributors = orderContributors(contributors) r.Dependencies = updatedDeps r.Changes = projectChanges - r.Version = tag + r.Tag = tag + r.Version = version + + // Remove trailing new lines + r.Preface = strings.TrimRightFunc(r.Preface, unicode.IsSpace) tmpl, err := getTemplate(context) if err != nil { diff --git a/cmd/containerd-release/template.go b/cmd/containerd-release/template.go index 085e6cecf..a1da2d2e3 100644 --- a/cmd/containerd-release/template.go +++ b/cmd/containerd-release/template.go @@ -18,8 +18,10 @@ package main const ( defaultTemplateFile = "TEMPLATE" - releaseNotes = `Welcome to the {{.Version}} release of {{.ProjectName}}! -{{if .PreRelease -}} + releaseNotes = `{{.ProjectName}} {{.Version}} + +Welcome to the {{.Tag}} release of {{.ProjectName}}! +{{- if .PreRelease }} *This is a pre-release of {{.ProjectName}}* {{- end}} From 69e7c77e6aee062c4bd812cde1ffca2bf10c7661 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 28 Aug 2018 17:49:35 -0700 Subject: [PATCH 3/3] Add option to add links to changelog Allows creating links in changelog, similar to what Github does for markdown but works for dependencies as well. Signed-off-by: Derek McGowan --- cmd/containerd-release/main.go | 20 +++++++++++++ cmd/containerd-release/util.go | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/cmd/containerd-release/main.go b/cmd/containerd-release/main.go index 7130677d6..c190d0e27 100644 --- a/cmd/containerd-release/main.go +++ b/cmd/containerd-release/main.go @@ -116,11 +116,16 @@ This tool should be ran from the root of the project repository for a new releas Usage: "template filepath to use in place of the default", Value: defaultTemplateFile, }, + cli.BoolFlag{ + Name: "linkify,l", + Usage: "add links to changelog", + }, } app.Action = func(context *cli.Context) error { var ( releasePath = context.Args().First() tag = context.String("tag") + linkify = context.Bool("linkify") ) if tag == "" { tag = parseTag(releasePath) @@ -150,6 +155,11 @@ This tool should be ran from the root of the project repository for a new releas if err != nil { return err } + if linkify { + if err := linkifyChanges(changes, githubCommitLink(r.GithubRepo), githubPRLink(r.GithubRepo)); err != nil { + return err + } + } if err := addContributors(r.Previous, r.Commit, contributors); err != nil { return err } @@ -221,6 +231,16 @@ This tool should be ran from the root of the project repository for a new releas if err := addContributors(dep.Previous, dep.Commit, contributors); err != nil { return errors.Wrapf(err, "failed to get authors for %s", name) } + if linkify { + if !strings.HasPrefix(dep.Name, "github.com/") { + logrus.Debugf("linkify only supported for Github, skipping %s", dep.Name) + } else { + ghname := dep.Name[11:] + if err := linkifyChanges(changes, githubCommitLink(ghname), githubPRLink(ghname)); err != nil { + return err + } + } + } projectChanges = append(projectChanges, projectChange{ Name: name, diff --git a/cmd/containerd-release/util.go b/cmd/containerd-release/util.go index ec526bbda..552338490 100644 --- a/cmd/containerd-release/util.go +++ b/cmd/containerd-release/util.go @@ -25,6 +25,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "sort" "strings" @@ -113,6 +114,26 @@ func getChangelog(previous, commit string) ([]byte, error) { return git("log", "--oneline", gitChangeDiff(previous, commit)) } +func linkifyChanges(c []change, commit, msg func(change) (string, error)) error { + for i := range c { + commitLink, err := commit(c[i]) + if err != nil { + return err + } + + description, err := msg(c[i]) + if err != nil { + return err + } + + c[i].Commit = fmt.Sprintf("[`%s`](%s)", c[i].Commit, commitLink) + c[i].Description = description + + } + + return nil +} + func parseChangelog(changelog []byte) ([]change, error) { var ( changes []change @@ -282,3 +303,36 @@ func getTemplate(context *cli.Context) (string, error) { } return string(data), nil } + +func githubCommitLink(repo string) func(change) (string, error) { + return func(c change) (string, error) { + full, err := git("rev-parse", c.Commit) + if err != nil { + return "", err + } + commit := strings.TrimSpace(string(full)) + + return fmt.Sprintf("https://github.com/%s/commit/%s", repo, commit), nil + } +} + +func githubPRLink(repo string) func(change) (string, error) { + r := regexp.MustCompile("^Merge pull request #[0-9]+") + return func(c change) (string, error) { + var err error + message := r.ReplaceAllStringFunc(c.Description, func(m string) string { + idx := strings.Index(m, "#") + pr := m[idx+1:] + + // TODO: Validate links using github API + // TODO: Validate PR merged as commit hash + link := fmt.Sprintf("https://github.com/%s/pull/%s", repo, pr) + + return fmt.Sprintf("%s [#%s](%s)", m[:idx], pr, link) + }) + if err != nil { + return "", err + } + return message, nil + } +}