1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-06 03:13:48 +02:00

fix: lint issues

This commit is contained in:
Carlos Alexandro Becker 2018-05-13 16:06:14 -03:00 committed by Carlos Alexandro Becker
parent 0b25773b77
commit 8690ee07e5
5 changed files with 21 additions and 17 deletions

2
Gopkg.lock generated
View File

@ -258,6 +258,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "a47b30326926a615c574552d71af84d17e5198486ad61bed0d63672ebaba696d"
inputs-digest = "3fac5f0b013f4e66674db9d8ac7781f82ffdb4d46e3e004cfab2728b78c37a84"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -9,9 +9,9 @@ export PATH := ./bin:$(PATH)
setup:
go get -u golang.org/x/tools/cmd/stringer
go get -u golang.org/x/tools/cmd/cover
curl -sfL https://install.goreleaser.com/github.com/gohugoio/hugo.sh | bash
curl -sfL https://install.goreleaser.com/github.com/alecthomas/gometalinter.sh | bash
curl -sfL https://install.goreleaser.com/github.com/caarlos0/bandep.sh | bash
curl -sfL https://install.goreleaser.com/github.com/gohugoio/hugo.sh | sh
curl -sfL https://install.goreleaser.com/github.com/alecthomas/gometalinter.sh | sh
curl -sfL https://install.goreleaser.com/github.com/caarlos0/bandep.sh | sh
ifeq ($(OS), Darwin)
brew install dep
else
@ -44,6 +44,7 @@ fmt:
# Run all the linters
lint:
rm -rf pipeline/s3/testdata/config/certs
gometalinter --vendor ./...
find . -name '*.md' -not -wholename './vendor/*' | xargs prettier -l
.PHONY: lint

View File

@ -90,7 +90,7 @@ func (c *githubClient) CreateFile(
func (c *githubClient) CreateRelease(ctx *context.Context, body string) (int64, error) {
var release *github.RepositoryRelease
title, err := nametemplate.Apply(ctx, "github", ctx.Config.Release.NameTemplate)
title, err := nametemplate.Apply(ctx, ctx.Config.Release.NameTemplate)
if err != nil {
return 0, err
}

View File

@ -1,3 +1,4 @@
// Package nametemplate provides common template function for releases and etc.
package nametemplate
import (
@ -8,11 +9,16 @@ import (
"github.com/goreleaser/goreleaser/context"
)
func Apply(ctx *context.Context, name, tmpl string) (string, error) {
// Apply applies the given name template using the context as source.
func Apply(ctx *context.Context, tmpl string) (string, error) {
var out bytes.Buffer
t, err := template.New(name).
t, err := template.New("release").
Option("missingkey=error").
Funcs(mkFuncMap()).
Funcs(template.FuncMap{
"time": func(s string) string {
return time.Now().UTC().Format(s)
},
}).
Parse(tmpl)
if err != nil {
return "", err
@ -26,11 +32,3 @@ func Apply(ctx *context.Context, name, tmpl string) (string, error) {
})
return out.String(), err
}
func mkFuncMap() template.FuncMap {
return template.FuncMap{
"time": func(s string) string {
return time.Now().UTC().Format(s)
},
}
}

View File

@ -29,8 +29,13 @@ func TestFuncMap(t *testing.T) {
Name: "MM/DD/YYYY",
},
} {
out, err := Apply(ctx, "foo", tc.Template)
out, err := Apply(ctx, tc.Template)
assert.NoError(t, err)
assert.NotEmpty(t, out)
}
}
func TestInvalidTemplate(t *testing.T) {
_, err := Apply(context.New(config.Project{}), "{{{.Foo}")
assert.EqualError(t, err, "template: release:1: unexpected \"{\" in command")
}