From e8ab2b2fe29ebc017eece8cc6ec2f3feac38dfbf Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 18 Jan 2017 15:08:48 -0200 Subject: [PATCH] removed unneeded pointers from context --- context/context.go | 12 ++++----- pipeline/brew/brew.go | 2 +- pipeline/build/name_test.go | 4 +-- pipeline/defaults/defaults_test.go | 42 ++++++++++++++---------------- pipeline/env/env.go | 5 ++-- pipeline/git/git.go | 2 +- pipeline/release/release.go | 2 +- pipeline/repos/repos.go | 4 +-- 8 files changed, 35 insertions(+), 38 deletions(-) diff --git a/context/context.go b/context/context.go index 844fcb13e..a474287f1 100644 --- a/context/context.go +++ b/context/context.go @@ -16,18 +16,18 @@ type Repo struct { // Context carries along some data through the pipes type Context struct { - Config *config.Project - Token *string - Git *GitInfo - ReleaseRepo *Repo - BrewRepo *Repo + Config config.Project + Token string + Git GitInfo + ReleaseRepo Repo + BrewRepo Repo Archives map[string]string } // New context func New(config config.Project) *Context { return &Context{ - Config: &config, + Config: config, Archives: map[string]string{}, } } diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 9af6010d7..a9a063792 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -71,7 +71,7 @@ func (Pipe) Run(ctx *context.Context) error { if ctx.Config.Brew.Repo == "" { return nil } - client := clients.GitHub(*ctx.Token) + client := clients.GitHub(ctx.Token) path := filepath.Join( ctx.Config.Brew.Folder, ctx.Config.Build.BinaryName+".rb", ) diff --git a/pipeline/build/name_test.go b/pipeline/build/name_test.go index a56c065d1..b6f5c1c81 100644 --- a/pipeline/build/name_test.go +++ b/pipeline/build/name_test.go @@ -19,7 +19,7 @@ func TestExtOthers(t *testing.T) { func TestNameFor(t *testing.T) { assert := assert.New(t) - var config = &config.Project{ + var config = config.Project{ Archive: config.Archive{ NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}", Replacements: map[string]string{ @@ -33,7 +33,7 @@ func TestNameFor(t *testing.T) { } var ctx = &context.Context{ Config: config, - Git: &context.GitInfo{ + Git: context.GitInfo{ CurrentTag: "v1.2.3", }, } diff --git a/pipeline/defaults/defaults_test.go b/pipeline/defaults/defaults_test.go index 9b4cc528f..b3cc43936 100644 --- a/pipeline/defaults/defaults_test.go +++ b/pipeline/defaults/defaults_test.go @@ -11,45 +11,43 @@ import ( func TestFillBasicData(t *testing.T) { assert := assert.New(t) - var config = &config.Project{} var ctx = &context.Context{ - Config: config, + Config: config.Project{}, } assert.NoError(Pipe{}.Run(ctx)) - assert.Equal("goreleaser/goreleaser", config.Release.Repo) - assert.Equal("goreleaser", config.Build.BinaryName) - assert.Equal("main.go", config.Build.Main) - assert.Equal("tar.gz", config.Archive.Format) - assert.Contains(config.Build.Goos, "darwin") - assert.Contains(config.Build.Goos, "linux") - assert.Contains(config.Build.Goarch, "386") - assert.Contains(config.Build.Goarch, "amd64") + assert.Equal("goreleaser/goreleaser", ctx.Config.Release.Repo) + assert.Equal("goreleaser", ctx.Config.Build.BinaryName) + assert.Equal("main.go", ctx.Config.Build.Main) + assert.Equal("tar.gz", ctx.Config.Archive.Format) + assert.Contains(ctx.Config.Build.Goos, "darwin") + assert.Contains(ctx.Config.Build.Goos, "linux") + assert.Contains(ctx.Config.Build.Goarch, "386") + assert.Contains(ctx.Config.Build.Goarch, "amd64") assert.NotEmpty( - config.Archive.Replacements, - config.Archive.NameTemplate, - config.Build.Ldflags, - config.Archive.Files, + ctx.Config.Archive.Replacements, + ctx.Config.Archive.NameTemplate, + ctx.Config.Build.Ldflags, + ctx.Config.Archive.Files, ) } func TestFilesFilled(t *testing.T) { assert := assert.New(t) - var config = &config.Project{ - Archive: config.Archive{ - Files: []string{ - "README.md", + var ctx = &context.Context{ + Config: config.Project{ + Archive: config.Archive{ + Files: []string{ + "README.md", + }, }, }, } - var ctx = &context.Context{ - Config: config, - } assert.NoError(Pipe{}.Run(ctx)) - assert.Len(config.Archive.Files, 1) + assert.Len(ctx.Config.Archive.Files, 1) } func TestAcceptFiles(t *testing.T) { diff --git a/pipeline/env/env.go b/pipeline/env/env.go index bd5a011a1..98dcdea96 100644 --- a/pipeline/env/env.go +++ b/pipeline/env/env.go @@ -20,10 +20,9 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) (err error) { - token := os.Getenv("GITHUB_TOKEN") - if token == "" { + ctx.Token = os.Getenv("GITHUB_TOKEN") + if ctx.Token == "" { return ErrMissingToken } - ctx.Token = &token return } diff --git a/pipeline/git/git.go b/pipeline/git/git.go index d935d2151..9ebdd9562 100644 --- a/pipeline/git/git.go +++ b/pipeline/git/git.go @@ -25,7 +25,7 @@ func (Pipe) Run(ctx *context.Context) (err error) { return } - ctx.Git = &context.GitInfo{ + ctx.Git = context.GitInfo{ CurrentTag: tag, PreviousTag: previous, Diff: log, diff --git a/pipeline/release/release.go b/pipeline/release/release.go index 583a38a93..9fe41f358 100644 --- a/pipeline/release/release.go +++ b/pipeline/release/release.go @@ -21,7 +21,7 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { - client := clients.GitHub(*ctx.Token) + client := clients.GitHub(ctx.Token) r, err := getOrCreateRelease(client, ctx) if err != nil { diff --git a/pipeline/repos/repos.go b/pipeline/repos/repos.go index 20740a5f6..444622f94 100644 --- a/pipeline/repos/repos.go +++ b/pipeline/repos/repos.go @@ -17,12 +17,12 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) (err error) { owner, name := split(ctx.Config.Release.Repo) - ctx.ReleaseRepo = &context.Repo{ + ctx.ReleaseRepo = context.Repo{ Owner: owner, Name: name, } owner, name = split(ctx.Config.Brew.Repo) - ctx.BrewRepo = &context.Repo{ + ctx.BrewRepo = context.Repo{ Owner: owner, Name: name, }