From f7be01e3034acbdbc74b081c6f5e6b6d825cc679 Mon Sep 17 00:00:00 2001
From: Christoph Witzko <github@christophwitzko.com>
Date: Fri, 13 Jan 2023 14:21:17 +0100
Subject: [PATCH] style: add .golangci-lint.yaml

---
 .golangci.yaml           | 25 +++++++++++++++++++++++++
 pkg/provider/git.go      | 15 ++++++++-------
 pkg/provider/git_test.go | 19 ++++++++++---------
 3 files changed, 43 insertions(+), 16 deletions(-)
 create mode 100644 .golangci.yaml

diff --git a/.golangci.yaml b/.golangci.yaml
new file mode 100644
index 0000000..f5c0478
--- /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 29cff84..75191cb 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 c60ae50..ec6f956 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 {
-- 
GitLab