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

fix: brew/scoop panic (#2515)

This commit is contained in:
Carlos Alexandro Becker 2021-09-27 08:13:56 -03:00 committed by GitHub
parent 3d62f95fd5
commit 29016cb0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 25 deletions

View File

@ -43,20 +43,11 @@ type Client interface {
// New creates a new client depending on the token type.
func New(ctx *context.Context) (Client, error) {
log.WithField("type", ctx.TokenType).Debug("token type")
if ctx.TokenType == context.TokenTypeGitHub {
return NewGitHub(ctx, ctx.Token)
}
if ctx.TokenType == context.TokenTypeGitLab {
return NewGitLab(ctx, ctx.Token)
}
if ctx.TokenType == context.TokenTypeGitea {
return NewGitea(ctx, ctx.Token)
}
return nil, nil
return newWithToken(ctx, ctx.Token)
}
func newWithToken(ctx *context.Context, token string) (Client, error) {
log.WithField("type", ctx.TokenType).Debug("token type")
if ctx.TokenType == context.TokenTypeGitHub {
return NewGitHub(ctx, token)
}
@ -66,7 +57,7 @@ func newWithToken(ctx *context.Context, token string) (Client, error) {
if ctx.TokenType == context.TokenTypeGitea {
return NewGitea(ctx, token)
}
return nil, nil
return nil, fmt.Errorf("invalid client token type: %q", ctx.TokenType)
}
func NewIfToken(ctx *context.Context, cli Client, token string) (Client, error) {

View File

@ -12,7 +12,7 @@ func TestClientEmpty(t *testing.T) {
ctx := &context.Context{}
client, err := New(ctx)
require.Nil(t, client)
require.NoError(t, err)
require.EqualError(t, err, `invalid client token type: ""`)
}
func TestClientNewGitea(t *testing.T) {
@ -153,7 +153,7 @@ func TestNewWithToken(t *testing.T) {
}
cli, err := newWithToken(ctx, "{{ .Env.TK }}")
require.NoError(t, err)
require.EqualError(t, err, `invalid client token type: "nope"`)
require.Nil(t, cli)
})
}

View File

@ -83,11 +83,6 @@ func (Pipe) Run(ctx *context.Context) error {
// Publish brew formula.
func (Pipe) Publish(ctx *context.Context) error {
// we keep GitHub as default for now, in line with releases
if string(ctx.TokenType) == "" {
ctx.TokenType = context.TokenTypeGitHub
}
cli, err := client.New(ctx)
if err != nil {
return err

View File

@ -83,12 +83,6 @@ func (Pipe) Run(ctx *context.Context) error {
return err
}
if githubToken != "" {
log.Debug("token type: github")
ctx.TokenType = context.TokenTypeGitHub
ctx.Token = githubToken
}
if gitlabToken != "" {
log.Debug("token type: gitlab")
ctx.TokenType = context.TokenTypeGitLab
@ -101,6 +95,15 @@ func (Pipe) Run(ctx *context.Context) error {
ctx.Token = giteaToken
}
if githubToken != "" {
log.Debug("token type: github")
ctx.Token = githubToken
}
if ctx.TokenType == "" {
ctx.TokenType = context.TokenTypeGitHub
}
return nil
}

View File

@ -59,6 +59,12 @@ func TestSetDefaultTokenFiles(t *testing.T) {
})
require.EqualError(t, Pipe{}.Run(ctx), `template: tmpl:1: unexpected "}" in operand`)
})
t.Run("no token", func(t *testing.T) {
ctx := context.New(config.Project{})
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, ctx.TokenType, context.TokenTypeGitHub)
})
}
func TestValidGithubEnv(t *testing.T) {