1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-04 03:11:55 +02:00

Merge pull request #96 from goreleaser/uneeded-pointers

removed unneeded pointers from context
This commit is contained in:
Carlos Alexandro Becker 2017-01-18 15:16:46 -02:00 committed by GitHub
commit 65b7458098
8 changed files with 35 additions and 38 deletions

View File

@ -16,18 +16,18 @@ type Repo struct {
// Context carries along some data through the pipes // Context carries along some data through the pipes
type Context struct { type Context struct {
Config *config.Project Config config.Project
Token *string Token string
Git *GitInfo Git GitInfo
ReleaseRepo *Repo ReleaseRepo Repo
BrewRepo *Repo BrewRepo Repo
Archives map[string]string Archives map[string]string
} }
// New context // New context
func New(config config.Project) *Context { func New(config config.Project) *Context {
return &Context{ return &Context{
Config: &config, Config: config,
Archives: map[string]string{}, Archives: map[string]string{},
} }
} }

View File

@ -71,7 +71,7 @@ func (Pipe) Run(ctx *context.Context) error {
if ctx.Config.Brew.Repo == "" { if ctx.Config.Brew.Repo == "" {
return nil return nil
} }
client := clients.GitHub(*ctx.Token) client := clients.GitHub(ctx.Token)
path := filepath.Join( path := filepath.Join(
ctx.Config.Brew.Folder, ctx.Config.Build.BinaryName+".rb", ctx.Config.Brew.Folder, ctx.Config.Build.BinaryName+".rb",
) )

View File

@ -19,7 +19,7 @@ func TestExtOthers(t *testing.T) {
func TestNameFor(t *testing.T) { func TestNameFor(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
var config = &config.Project{ var config = config.Project{
Archive: config.Archive{ Archive: config.Archive{
NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}", NameTemplate: "{{.BinaryName}}_{{.Os}}_{{.Arch}}_{{.Version}}",
Replacements: map[string]string{ Replacements: map[string]string{
@ -33,7 +33,7 @@ func TestNameFor(t *testing.T) {
} }
var ctx = &context.Context{ var ctx = &context.Context{
Config: config, Config: config,
Git: &context.GitInfo{ Git: context.GitInfo{
CurrentTag: "v1.2.3", CurrentTag: "v1.2.3",
}, },
} }

View File

@ -11,45 +11,43 @@ import (
func TestFillBasicData(t *testing.T) { func TestFillBasicData(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
var config = &config.Project{}
var ctx = &context.Context{ var ctx = &context.Context{
Config: config, Config: config.Project{},
} }
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(Pipe{}.Run(ctx))
assert.Equal("goreleaser/goreleaser", config.Release.Repo) assert.Equal("goreleaser/goreleaser", ctx.Config.Release.Repo)
assert.Equal("goreleaser", config.Build.BinaryName) assert.Equal("goreleaser", ctx.Config.Build.BinaryName)
assert.Equal("main.go", config.Build.Main) assert.Equal("main.go", ctx.Config.Build.Main)
assert.Equal("tar.gz", config.Archive.Format) assert.Equal("tar.gz", ctx.Config.Archive.Format)
assert.Contains(config.Build.Goos, "darwin") assert.Contains(ctx.Config.Build.Goos, "darwin")
assert.Contains(config.Build.Goos, "linux") assert.Contains(ctx.Config.Build.Goos, "linux")
assert.Contains(config.Build.Goarch, "386") assert.Contains(ctx.Config.Build.Goarch, "386")
assert.Contains(config.Build.Goarch, "amd64") assert.Contains(ctx.Config.Build.Goarch, "amd64")
assert.NotEmpty( assert.NotEmpty(
config.Archive.Replacements, ctx.Config.Archive.Replacements,
config.Archive.NameTemplate, ctx.Config.Archive.NameTemplate,
config.Build.Ldflags, ctx.Config.Build.Ldflags,
config.Archive.Files, ctx.Config.Archive.Files,
) )
} }
func TestFilesFilled(t *testing.T) { func TestFilesFilled(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
var config = &config.Project{ var ctx = &context.Context{
Archive: config.Archive{ Config: config.Project{
Files: []string{ Archive: config.Archive{
"README.md", Files: []string{
"README.md",
},
}, },
}, },
} }
var ctx = &context.Context{
Config: config,
}
assert.NoError(Pipe{}.Run(ctx)) assert.NoError(Pipe{}.Run(ctx))
assert.Len(config.Archive.Files, 1) assert.Len(ctx.Config.Archive.Files, 1)
} }
func TestAcceptFiles(t *testing.T) { func TestAcceptFiles(t *testing.T) {

5
pipeline/env/env.go vendored
View File

@ -20,10 +20,9 @@ func (Pipe) Description() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) (err error) { func (Pipe) Run(ctx *context.Context) (err error) {
token := os.Getenv("GITHUB_TOKEN") ctx.Token = os.Getenv("GITHUB_TOKEN")
if token == "" { if ctx.Token == "" {
return ErrMissingToken return ErrMissingToken
} }
ctx.Token = &token
return return
} }

View File

@ -25,7 +25,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
return return
} }
ctx.Git = &context.GitInfo{ ctx.Git = context.GitInfo{
CurrentTag: tag, CurrentTag: tag,
PreviousTag: previous, PreviousTag: previous,
Diff: log, Diff: log,

View File

@ -21,7 +21,7 @@ func (Pipe) Description() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) error { func (Pipe) Run(ctx *context.Context) error {
client := clients.GitHub(*ctx.Token) client := clients.GitHub(ctx.Token)
r, err := getOrCreateRelease(client, ctx) r, err := getOrCreateRelease(client, ctx)
if err != nil { if err != nil {

View File

@ -17,12 +17,12 @@ func (Pipe) Description() string {
// Run the pipe // Run the pipe
func (Pipe) Run(ctx *context.Context) (err error) { func (Pipe) Run(ctx *context.Context) (err error) {
owner, name := split(ctx.Config.Release.Repo) owner, name := split(ctx.Config.Release.Repo)
ctx.ReleaseRepo = &context.Repo{ ctx.ReleaseRepo = context.Repo{
Owner: owner, Owner: owner,
Name: name, Name: name,
} }
owner, name = split(ctx.Config.Brew.Repo) owner, name = split(ctx.Config.Brew.Repo)
ctx.BrewRepo = &context.Repo{ ctx.BrewRepo = context.Repo{
Owner: owner, Owner: owner,
Name: name, Name: name,
} }