Skip to content

Commit

Permalink
style: add .golangci-lint.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwitzko committed Jan 13, 2023
1 parent 7878460 commit f7be01e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
25 changes: 25 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 8 additions & 7 deletions pkg/provider/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/provider/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package provider

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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++
}
Expand All @@ -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 {
Expand Down

0 comments on commit f7be01e

Please sign in to comment.