From 57edf8105737ca466fc9f8fc79e1ac9c76c2b6e1 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 2 Jan 2017 10:45:05 -0200 Subject: [PATCH 1/5] gometalinter on ci and some fixes --- .travis.yml | 9 ++++++++- config/config.go | 4 +++- pipeline/compress/compress.go | 5 +---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c6cff919..2b501bb26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,18 @@ language: go go: 1.7.4 install: + - go get github.com/alecthomas/gometalinter - go get github.com/Masterminds/glide - glide install script: - go test -cover `glide nv` + - gometalinter --vendor --disable-all \ + --enable=deadcode \ + --enable=ineffassign \ + --enable=gosimple \ + --enable=staticcheck \ + ./... after_success: test ! -z "$TRAVIS_TAG" && go run main.go notifications: - email: false \ No newline at end of file + email: false diff --git a/config/config.go b/config/config.go index b59e1d38b..f9e6b3879 100644 --- a/config/config.go +++ b/config/config.go @@ -54,7 +54,9 @@ func Load(file string) (config ProjectConfig, err error) { if err != nil { return config, err } - err = yaml.Unmarshal(data, &config) + if err := yaml.Unmarshal(data, &config); err != nil { + return config, err + } config.fillBasicData() if err := config.fillFiles(); err != nil { return config, err diff --git a/pipeline/compress/compress.go b/pipeline/compress/compress.go index fff42f1b2..33cd1bd52 100644 --- a/pipeline/compress/compress.go +++ b/pipeline/compress/compress.go @@ -51,10 +51,7 @@ func create(system, arch string, config config.ProjectConfig) error { return err } } - if err := addFile(tw, config.BinaryName+ext(system), binaryPath(system, arch, config.BinaryName)); err != nil { - return err - } - return nil + return addFile(tw, config.BinaryName+ext(system), binaryPath(system, arch, config.BinaryName)) } func addFile(tw *tar.Writer, name, path string) error { From eba57ca35745f73dafe8e63717d7a76f69c455a6 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 2 Jan 2017 10:47:19 -0200 Subject: [PATCH 2/5] gofmt and goimports --- .travis.yml | 2 ++ config/git/tag_test.go | 3 ++- pipeline/release/release_test.go | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2b501bb26..638e8ca81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,8 @@ script: --enable=ineffassign \ --enable=gosimple \ --enable=staticcheck \ + --enable=gofmt \ + --enable=goimports \ ./... after_success: test ! -z "$TRAVIS_TAG" && go run main.go diff --git a/config/git/tag_test.go b/config/git/tag_test.go index f988e38b9..77ba71d14 100644 --- a/config/git/tag_test.go +++ b/config/git/tag_test.go @@ -1,8 +1,9 @@ package git import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestCurrentTag(t *testing.T) { diff --git a/pipeline/release/release_test.go b/pipeline/release/release_test.go index 349ff9216..410d72d8b 100644 --- a/pipeline/release/release_test.go +++ b/pipeline/release/release_test.go @@ -2,8 +2,9 @@ package release import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestDescription(t *testing.T) { From c993a5baf0288570653df15b024816d0736f9e64 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 2 Jan 2017 10:51:24 -0200 Subject: [PATCH 3/5] duplicated code --- .travis.yml | 1 + config/config_test.go | 74 +++++++++++-------------------------------- 2 files changed, 20 insertions(+), 55 deletions(-) diff --git a/.travis.yml b/.travis.yml index 638e8ca81..9c9718cb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ script: --enable=staticcheck \ --enable=gofmt \ --enable=goimports \ + --enable=dupl \ ./... after_success: test ! -z "$TRAVIS_TAG" && go run main.go diff --git a/config/config_test.go b/config/config_test.go index 5124e6c6e..3b4a9459e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -29,73 +29,23 @@ func TestFillFilesMissingFiles(t *testing.T) { } func TestFillFilesUSENMarkdown(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/1") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENSE.md", "README.md"}, config.Files) + assertFiles(t, "./.test/1", []string{"LICENSE.md", "README.md"}) } func TestFillFilesRealENMarkdown(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/2") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENCE.md", "README.md"}, config.Files) + assertFiles(t, "./.test/2", []string{"LICENCE.md", "README.md"}) } func TestFillFilesArbitratryENTXT(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/3") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENCE.txt", "README.txt"}, config.Files) + assertFiles(t, "./.test/3", []string{"LICENCE.txt", "README.txt"}) } func TestFillFilesArbitratryENNoSuffix(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/4") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"LICENCE"}, config.Files) + assertFiles(t, "./.test/4", []string{"LICENCE"}) } func TestFillFilesChangelog(t *testing.T) { - assert := assert.New(t) - - cwd, _ := os.Getwd() - os.Chdir("./.test/5") - defer os.Chdir(cwd) - - config := ProjectConfig{} - err := config.fillFiles() - - assert.NoError(err) - assert.Equal([]string{"CHANGELOG", "CHANGELOG.md"}, config.Files) + assertFiles(t, "./.test/5", []string{"CHANGELOG", "CHANGELOG.md"}) } func TestValidadeMissingBinaryName(t *testing.T) { @@ -118,3 +68,17 @@ func TestValidadeMinimalConfig(t *testing.T) { config := ProjectConfig{BinaryName: "asd", Repo: "asd/asd"} assert.NoError(config.validate()) } + +func assertFiles(t *testing.T, dir string, files []string) { + assert := assert.New(t) + + cwd, _ := os.Getwd() + os.Chdir(dir) + defer os.Chdir(cwd) + + config := ProjectConfig{} + err := config.fillFiles() + + assert.NoError(err) + assert.Equal(files, config.Files) +} From 3388cbbf63162873c5aa0e784019bf6a114f5c10 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 2 Jan 2017 10:52:14 -0200 Subject: [PATCH 4/5] misspell --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 9c9718cb2..31a5bf204 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ script: --enable=gofmt \ --enable=goimports \ --enable=dupl \ + --enable=misspell \ ./... after_success: test ! -z "$TRAVIS_TAG" && go run main.go From 27aaac4132e47c402f7d52ab19f3f0ab7bf92657 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 2 Jan 2017 11:49:30 -0200 Subject: [PATCH 5/5] improved code a little --- pipeline/brew/brew.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pipeline/brew/brew.go b/pipeline/brew/brew.go index 6dce92d60..0160f2c29 100644 --- a/pipeline/brew/brew.go +++ b/pipeline/brew/brew.go @@ -84,16 +84,13 @@ func (Pipe) Run(config config.ProjectConfig) error { return err } func sha(client *github.Client, owner, repo, name string, out bytes.Buffer) (*string, error) { - var sha *string file, _, _, err := client.Repositories.GetContents( owner, repo, name, &github.RepositoryContentGetOptions{}, ) if err == nil { - sha = file.SHA - } else { - sha = github.String(fmt.Sprintf("%s", sha256.Sum256(out.Bytes()))) + return file.SHA, err } - return sha, err + return github.String(fmt.Sprintf("%s", sha256.Sum256(out.Bytes()))), err } func buildFormulae(config config.ProjectConfig, client *github.Client) (bytes.Buffer, error) {