diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f5c0478c05e1ef02a4b48be0866a2b8874659675 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,25 @@ +linters: + enable: + - errorlint + - forbidigo + - gochecknoinits + - gocritic + - goconst + - gocyclo + - gofumpt + - goimports + - misspell + - revive + - unconvert + - unparam + - wastedassign + +linters-settings: + gocyclo: + min-complexity: 12 + gofumpt: + extra-rules: true + govet: + enable-all: true + disable: + - fieldalignment diff --git a/pkg/provider/git.go b/pkg/provider/git.go index 29cff84b2391fae151bfda3f1700ec27860c6b9a..75191cb0803f2ce4f82a9518b2f5517868cd4762 100644 --- a/pkg/provider/git.go +++ b/pkg/provider/git.go @@ -52,18 +52,19 @@ func (repo *Repository) Init(config map[string]string) error { config["auth_username"] = "git" } - if config["auth"] == "basic" { + switch config["auth"] { + case "basic": repo.auth = &http.BasicAuth{ Username: config["auth_username"], Password: config["auth_password"], } - } else if config["auth"] == "ssh" { + case "ssh": auth, err := ssh.NewPublicKeysFromFile(config["auth_username"], config["auth_private_key"], config["auth_password"]) if err != nil { return err } repo.auth = auth - } else { + default: repo.auth = nil } @@ -137,15 +138,15 @@ func (repo *Repository) GetReleases(rawRe string) ([]*semrel.Release, error) { if rawRe != "" && !re.MatchString(tag) { return nil } - version, err := semver.NewVersion(tag) - if err != nil { + version, semverErr := semver.NewVersion(tag) + if semverErr != nil { return nil } // resolve annotated tags sha := reference.Hash() - if tagObj, err := repo.repo.TagObject(sha); err == nil { - if com, err := tagObj.Commit(); err == nil { + if tagObj, tagErr := repo.repo.TagObject(sha); tagErr == nil { + if com, commitErr := tagObj.Commit(); commitErr == nil { sha = com.Hash } } diff --git a/pkg/provider/git_test.go b/pkg/provider/git_test.go index c60ae50a279e7fde5d3e6255c90bc8391b3874f8..ec6f956131ed7b25541a61ce9124235e46fb3ca1 100644 --- a/pkg/provider/git_test.go +++ b/pkg/provider/git_test.go @@ -2,7 +2,7 @@ package provider import ( "fmt" - "io/ioutil" + "os" "strings" "testing" "time" @@ -53,8 +53,9 @@ func newRepository(t *testing.T) { require.NotNil(repo.auth) } +//gocyclo:ignore func setupRepo() (string, error) { - dir, err := ioutil.TempDir("", "provider-git") + dir, err := os.MkdirTemp("", "provider-git") if err != nil { return "", err } @@ -83,19 +84,19 @@ func setupRepo() (string, error) { versionCount := 0 betaCount := 1 for i := 0; i < 100; i++ { - commit, err := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: author}) - if err != nil { + commit, commitErr := w.Commit(fmt.Sprintf("feat: commit %d", i), &git.CommitOptions{Author: author, AllowEmptyCommits: true}) + if commitErr != nil { return "", err } if i%10 == 0 { - if _, err := repo.CreateTag(fmt.Sprintf("v1.%d.0", versionCount), commit, nil); err != nil { - return "", err + if _, tagErr := repo.CreateTag(fmt.Sprintf("v1.%d.0", versionCount), commit, nil); tagErr != nil { + return "", tagErr } versionCount++ } if i%5 == 0 { - if _, err := repo.CreateTag(fmt.Sprintf("v2.0.0-beta.%d", betaCount), commit, nil); err != nil { - return "", err + if _, tagErr := repo.CreateTag(fmt.Sprintf("v2.0.0-beta.%d", betaCount), commit, nil); tagErr != nil { + return "", tagErr } betaCount++ } @@ -109,7 +110,7 @@ func setupRepo() (string, error) { return "", err } - if _, err = w.Commit("fix: error", &git.CommitOptions{Author: author}); err != nil { + if _, err = w.Commit("fix: error", &git.CommitOptions{Author: author, AllowEmptyCommits: true}); err != nil { return "", err } if err = w.Checkout(&git.CheckoutOptions{Branch: plumbing.NewBranchReferenceName("master")}); err != nil {