From 69767ec7985b849cd2e5a8272de146c440953921 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 19 Apr 2017 17:05:10 -0300 Subject: [PATCH] improvements --- context/context.go | 23 +++++++++++------------ main.go | 2 +- pipeline/git/git.go | 25 ++++++++++++++----------- pipeline/release/body.go | 10 ++++------ pipeline/release/body_test.go | 5 ++--- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/context/context.go b/context/context.go index 079aa76b0..46bbda57e 100644 --- a/context/context.go +++ b/context/context.go @@ -17,23 +17,22 @@ import ( // GitInfo includes tags and diffs used in some point type GitInfo struct { - CurrentTag string - PreviousTag string - Commit string + CurrentTag string + Commit string } // Context carries along some data through the pipes type Context struct { ctx.Context - Config config.Project - Token string - Git GitInfo - Archives map[string]string - Artifacts []string - Changelog string - Version string - Validate bool - Publish bool + Config config.Project + Token string + Git GitInfo + Archives map[string]string + Artifacts []string + ReleaseNotes string + Version string + Validate bool + Publish bool } var lock sync.Mutex diff --git a/main.go b/main.go index c110e2efa..7b43e3da5 100644 --- a/main.go +++ b/main.go @@ -55,7 +55,7 @@ func main() { }, cli.StringFlag{ Name: "release-notes", - Usage: "Define a file with custom release notes to be used instead of the git log between tags", + Usage: "Path to a markdown file with custom release notes", }, cli.BoolFlag{ Name: "skip-validate", diff --git a/pipeline/git/git.go b/pipeline/git/git.go index d07feef3c..a3e4cf467 100644 --- a/pipeline/git/git.go +++ b/pipeline/git/git.go @@ -47,21 +47,20 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) (err error) { - tag, prev, commit, err := getInfo() + tag, commit, err := getInfo() if err != nil { return } ctx.Git = context.GitInfo{ - CurrentTag: tag, - PreviousTag: prev, - Commit: commit, + CurrentTag: tag, + Commit: commit, } - if ctx.Changelog == "" { - log, err := git("log", "--pretty=oneline", "--abbrev-commit", prev+".."+tag) + if ctx.ReleaseNotes == "" { + log, err := getChangelog(tag) if err != nil { return err } - ctx.Changelog = log + ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", log) } // removes usual `v` prefix ctx.Version = strings.TrimPrefix(tag, "v") @@ -87,12 +86,16 @@ func validate(commit, tag, version string) error { return nil } -func getInfo() (tag, prev, commit string, err error) { - tag, err = cleanGit("describe", "--tags", "--abbrev=0", "--always") +func getChangelog(tag string) (string, error) { + prev, err := previous(tag) if err != nil { - return + return "", err } - prev, err = previous(tag) + return git("log", "--pretty=oneline", "--abbrev-commit", prev+".."+tag) +} + +func getInfo() (tag, commit string, err error) { + tag, err = cleanGit("describe", "--tags", "--abbrev=0", "--always") if err != nil { return } diff --git a/pipeline/release/body.go b/pipeline/release/body.go index 3a8d4da0a..3013052b2 100644 --- a/pipeline/release/body.go +++ b/pipeline/release/body.go @@ -8,9 +8,7 @@ import ( "github.com/goreleaser/goreleaser/context" ) -const bodyTemplate = `## Changelog - -{{ .Changelog }} +const bodyTemplate = `{{ .ReleaseNotes }} --- Automated with @goreleaser @@ -25,10 +23,10 @@ func buildBody(ctx *context.Context) (bytes.Buffer, error) { } var template = template.Must(template.New("release").Parse(bodyTemplate)) err = template.Execute(&out, struct { - Changelog, GoVersion string + ReleaseNotes, GoVersion string }{ - Changelog: ctx.Changelog, - GoVersion: string(bts), + ReleaseNotes: ctx.ReleaseNotes, + GoVersion: string(bts), }) return out, err } diff --git a/pipeline/release/body_test.go b/pipeline/release/body_test.go index 2cdea8523..04dede0c0 100644 --- a/pipeline/release/body_test.go +++ b/pipeline/release/body_test.go @@ -12,11 +12,10 @@ func TestBody(t *testing.T) { var assert = assert.New(t) var changelog = "\nfeature1: description\nfeature2: other description" var ctx = &context.Context{ - Changelog: changelog, + ReleaseNotes: changelog, } out, err := buildBody(ctx) assert.NoError(err) - assert.Contains(out.String(), "## Changelog") assert.Contains(out.String(), changelog) assert.Contains(out.String(), "Automated with @goreleaser") assert.Contains(out.String(), "Built with go version go1.8") @@ -30,7 +29,7 @@ func TestGoVersionFails(t *testing.T) { }() os.Setenv("PATH", "") var ctx = &context.Context{ - Changelog: "changelog", + ReleaseNotes: "changelog", } _, err := buildBody(ctx) assert.Error(err)