From 25472d37da0af7caf87b2f9206448bcb84b568c6 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 21 Apr 2017 19:50:09 -0300 Subject: [PATCH 1/2] allowing draft releases --- README.md | 4 ++++ client/github.go | 28 ++++++++++++++++------------ config/config.go | 1 + pipeline/brew/brew.go | 4 ++++ pipeline/brew/brew_test.go | 14 ++++++++++++++ 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f4bc44c25..085382f2d 100644 --- a/README.md +++ b/README.md @@ -262,6 +262,10 @@ release: github: owner: user name: repo + + # If set to true, will not auto-publish the release. + # Default is false + draft: true ``` You can also specify a release notes file in markdown format using the diff --git a/client/github.go b/client/github.go index c28f50ac5..ce370cc3e 100644 --- a/client/github.go +++ b/client/github.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "log" "os" "github.com/google/go-github/github" @@ -68,34 +69,37 @@ func (c *githubClient) CreateFile( } func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) { - data := &github.RepositoryRelease{ + var release *github.RepositoryRelease + var data = &github.RepositoryRelease{ Name: github.String(ctx.Git.CurrentTag), TagName: github.String(ctx.Git.CurrentTag), Body: github.String(body), + Draft: github.Bool(ctx.Config.Release.Draft), } - r, _, err := c.client.Repositories.GetReleaseByTag( + release, _, err = c.client.Repositories.GetReleaseByTag( ctx, ctx.Config.Release.GitHub.Owner, ctx.Config.Release.GitHub.Name, ctx.Git.CurrentTag, ) if err != nil { - r, _, err = c.client.Repositories.CreateRelease( + release, _, err = c.client.Repositories.CreateRelease( ctx, ctx.Config.Release.GitHub.Owner, ctx.Config.Release.GitHub.Name, data, ) - return r.GetID(), err + } else { + release, _, err = c.client.Repositories.EditRelease( + ctx, + ctx.Config.Release.GitHub.Owner, + ctx.Config.Release.GitHub.Name, + release.GetID(), + data, + ) } - r, _, err = c.client.Repositories.EditRelease( - ctx, - ctx.Config.Release.GitHub.Owner, - ctx.Config.Release.GitHub.Name, - r.GetID(), - data, - ) - return r.GetID(), err + log.Printf("Release updated: %v\n", release.GetHTMLURL()) + return release.GetID(), err } func (c *githubClient) Upload( diff --git a/config/config.go b/config/config.go index 3ee8beaa6..e214905ee 100644 --- a/config/config.go +++ b/config/config.go @@ -67,6 +67,7 @@ type Archive struct { // Release config used for the GitHub release type Release struct { GitHub Repo + Draft bool } // FPM config diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index a88283a31..86863d7e9 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -102,6 +102,10 @@ func doRun(ctx *context.Context, client client.Client) error { log.Println("Skipped because brew section is not configured") return nil } + if ctx.Config.Release.Draft { + log.Println("Skipped because release is marked as draft") + return nil + } path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb") log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String()) content, err := buildFormula(ctx, client) diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index a7895861b..b15a74b67 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -165,6 +165,20 @@ func TestRunPipeNoPublish(t *testing.T) { assert.False(client.CreatedFile) } +func TestRunPipeDraftRelease(t *testing.T) { + assert := assert.New(t) + var ctx = &context.Context{ + Config: config.Project{ + Release: config.Release{ + Draft: true, + }, + }, + } + client := &DummyClient{} + assert.NoError(doRun(ctx, client)) + assert.False(client.CreatedFile) +} + type DummyClient struct { CreatedFile bool } From 0dc434dce3a1d4a2561acbe0db43e45e8725c6d9 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Fri, 21 Apr 2017 19:55:25 -0300 Subject: [PATCH 2/2] improved test coverage --- pipeline/brew/brew_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pipeline/brew/brew_test.go b/pipeline/brew/brew_test.go index b15a74b67..2da710082 100644 --- a/pipeline/brew/brew_test.go +++ b/pipeline/brew/brew_test.go @@ -168,10 +168,17 @@ func TestRunPipeNoPublish(t *testing.T) { func TestRunPipeDraftRelease(t *testing.T) { assert := assert.New(t) var ctx = &context.Context{ + Publish: true, Config: config.Project{ Release: config.Release{ Draft: true, }, + Brew: config.Homebrew{ + GitHub: config.Repo{ + Owner: "test", + Name: "test", + }, + }, }, } client := &DummyClient{}