1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2024-12-31 01:53:50 +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
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{},
}
}

View File

@ -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",
)

View File

@ -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",
},
}

View File

@ -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) {

5
pipeline/env/env.go vendored
View File

@ -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
}

View File

@ -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,

View File

@ -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 {

View File

@ -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,
}