mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-24 04:16:27 +02:00
fix: separated defaulter for project name
this was first broken in 58307599588f8d9177c62151d5a4e77f83196fe7 and hotfixed in 093291f3ad176f23463103baa3bb254bf96a6773 I believe this is a better fix
This commit is contained in:
parent
093291f3ad
commit
36c49b1306
@ -16,6 +16,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/pipeline/env"
|
||||
"github.com/goreleaser/goreleaser/pipeline/fpm"
|
||||
"github.com/goreleaser/goreleaser/pipeline/nfpm"
|
||||
"github.com/goreleaser/goreleaser/pipeline/project"
|
||||
"github.com/goreleaser/goreleaser/pipeline/release"
|
||||
"github.com/goreleaser/goreleaser/pipeline/scoop"
|
||||
"github.com/goreleaser/goreleaser/pipeline/sign"
|
||||
@ -43,6 +44,7 @@ var defaulters = []Defaulter{
|
||||
env.Pipe{},
|
||||
snapshot.Pipe{},
|
||||
release.Pipe{},
|
||||
project.Pipe{},
|
||||
archive.Pipe{},
|
||||
build.Pipe{},
|
||||
fpm.Pipe{},
|
||||
|
19
pipeline/project/project.go
Normal file
19
pipeline/project/project.go
Normal file
@ -0,0 +1,19 @@
|
||||
// Package project sets "high level" defaults related to the project.
|
||||
package project
|
||||
|
||||
import "github.com/goreleaser/goreleaser/context"
|
||||
|
||||
// Pipe implemens defaulter to set the project name
|
||||
type Pipe struct{}
|
||||
|
||||
func (Pipe) String() string {
|
||||
return "project name"
|
||||
}
|
||||
|
||||
// Default set project defaults
|
||||
func (Pipe) Default(ctx *context.Context) error {
|
||||
if ctx.Config.ProjectName == "" {
|
||||
ctx.Config.ProjectName = ctx.Config.Release.GitHub.Name
|
||||
}
|
||||
return nil
|
||||
}
|
37
pipeline/project/project_test.go
Normal file
37
pipeline/project/project_test.go
Normal file
@ -0,0 +1,37 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/goreleaser/goreleaser/config"
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
func TestCustomProjectName(t *testing.T) {
|
||||
var ctx = context.New(config.Project{
|
||||
ProjectName: "foo",
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "bar",
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "foo", ctx.Config.ProjectName)
|
||||
}
|
||||
|
||||
func TestEmptyProjectName(t *testing.T) {
|
||||
var ctx = context.New(config.Project{
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "bar",
|
||||
Name: "bar",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "bar", ctx.Config.ProjectName)
|
||||
}
|
@ -25,9 +25,6 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
ctx.Config.Release.NameTemplate = "{{.Tag}}"
|
||||
}
|
||||
if ctx.Config.Release.GitHub.Name != "" {
|
||||
if ctx.Config.ProjectName == "" {
|
||||
ctx.Config.ProjectName = ctx.Config.Release.GitHub.Name
|
||||
}
|
||||
return nil
|
||||
}
|
||||
repo, err := remoteRepo()
|
||||
@ -35,9 +32,6 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
return err
|
||||
}
|
||||
ctx.Config.Release.GitHub = repo
|
||||
if ctx.Config.ProjectName == "" {
|
||||
ctx.Config.ProjectName = repo.Name
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,6 @@ func TestDefault(t *testing.T) {
|
||||
Config: config.Project{},
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Equal(t, "goreleaser", ctx.Config.ProjectName)
|
||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Name)
|
||||
assert.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||
}
|
||||
@ -168,7 +167,6 @@ func TestDefaultFilled(t *testing.T) {
|
||||
},
|
||||
}
|
||||
assert.NoError(t, Pipe{}.Default(ctx))
|
||||
assert.Equal(t, "foo", ctx.Config.ProjectName)
|
||||
assert.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
||||
assert.Equal(t, "bar", ctx.Config.Release.GitHub.Owner)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user