Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 5356f81

Browse files
authored
feat: lint codebase and update dependencies (#2)
* feat: add lint and lint codebase * feat: update dependencies and test script * feat: lint and test github action * fix: unnecessary tmp variable
1 parent ba807b4 commit 5356f81

File tree

12 files changed

+469
-122
lines changed

12 files changed

+469
-122
lines changed

.github/workflows/test.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: golangci-lint
2+
on: push
3+
jobs:
4+
golangci:
5+
name: lint
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: golangci-lint
10+
uses: golangci/golangci-lint-action@v2
11+
with:
12+
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
13+
version: v1.29

.golangci.yaml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
run:
2+
allow-parallel-runners: true
3+
4+
output:
5+
sort-results: true
6+
7+
linters-settings:
8+
dupl:
9+
threshold: 100
10+
funlen:
11+
lines: 100
12+
statements: 50
13+
gci:
14+
local-prefixes: github.com/golangci/golangci-lint
15+
goconst:
16+
min-len: 2
17+
min-occurrences: 2
18+
gocritic:
19+
enabled-tags:
20+
- diagnostic
21+
- opinionated
22+
- performance
23+
- style
24+
disabled-checks:
25+
- dupImport # https://github.com/go-critic/go-critic/issues/845
26+
# - ifElseChain
27+
- octalLiteral
28+
# - whyNoLint
29+
- wrapperFunc
30+
gocyclo:
31+
min-complexity: 15
32+
goimports:
33+
local-prefixes: github.com/golangci/golangci-lint
34+
golint:
35+
min-confidence: 0
36+
gomnd:
37+
settings:
38+
mnd:
39+
# don't include the "operation" and "assign"
40+
checks:
41+
- argument
42+
- case
43+
- condition
44+
- return
45+
govet:
46+
check-shadowing: true
47+
settings:
48+
printf:
49+
funcs:
50+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
51+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
52+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
53+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
54+
lll:
55+
line-length: 140
56+
maligned:
57+
suggest-new: true
58+
misspell:
59+
locale: US
60+
nolintlint:
61+
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
62+
allow-unused: false # report any unused nolint directives
63+
require-explanation: false # don't require an explanation for nolint directives
64+
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
65+
66+
linters:
67+
# please, do not use `enable-all`: it's deprecated and will be removed soon.
68+
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
69+
disable-all: true
70+
enable:
71+
- bodyclose
72+
- deadcode
73+
- depguard
74+
- dogsled
75+
- dupl
76+
- errcheck
77+
- exhaustive
78+
- funlen
79+
- gochecknoinits
80+
- goconst
81+
- gocritic
82+
- gocyclo
83+
- gofmt
84+
- goimports
85+
- golint
86+
- gomnd
87+
- goprintffuncname
88+
- gosec
89+
- gosimple
90+
- govet
91+
- ineffassign
92+
- interfacer
93+
- lll
94+
- misspell
95+
- nakedret
96+
- noctx
97+
- nolintlint
98+
- rowserrcheck
99+
- scopelint
100+
- staticcheck
101+
- structcheck
102+
- stylecheck
103+
- typecheck
104+
- unconvert
105+
- unparam
106+
- unused
107+
- varcheck
108+
- whitespace
109+
# don't enable:
110+
# - asciicheck
111+
# - gochecknoglobals
112+
# - gocognit
113+
# - godot
114+
# - godox
115+
# - goerr113
116+
# - maligned
117+
# - nestif
118+
# - prealloc
119+
# - testpackage
120+
# - wsl
121+
issues:
122+
exclude:
123+
- Using the variable on range scope `tt` in function literal
124+

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
lint:
2+
golangci-lint run
3+
4+
lint-fix:
5+
golangci-lint run --fix
6+
7+
update-deps:
8+
go get -u ./...
9+
10+
test:
11+
go test ./...

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ Things that you need to have before we start:
1515
* Git repository
1616
* At least two Git tags in rage
1717

18+
### Tools
19+
1. Lint: https://golangci-lint.run/usage/quick-start/
20+
21+
### Scripts
22+
1. Lint: `make lint`
23+
1. Lint with autofix: `make lint-fix`
24+
1825
### Installing
1926

2027
Just grab one file from download page: https://github.com/psmarcin/jira-versioner/releases/latest.

cmd/jira-versioner/main.go

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,80 @@ package main
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
7+
58
"github.com/psmarcin/jira-versioner/pkg/git"
69
"github.com/psmarcin/jira-versioner/pkg/jira"
710
"github.com/spf13/cobra"
811
"go.uber.org/zap"
9-
"os"
10-
"path/filepath"
1112
)
1213

13-
var (
14-
rootCmd = &cobra.Command{
14+
func main() {
15+
rootCmd := &cobra.Command{
1516
Use: "jira-versioner",
1617
Short: "A simple version setter for Jira tasks since last version",
1718
Long: `A solution for automatically create version,
1819
link all issues from commits to newly created version.
1920
All automatically.`,
2021
Run: rootFunc,
2122
}
22-
)
23-
24-
func init() {
2523
// get current directory path
2624
ex, err := os.Executable()
2725
if err != nil {
2826
panic(err)
2927
}
3028
pwd := filepath.Dir(ex)
3129

32-
//rootCmd.Flags().StringP("verbose", "v", "info", "")
3330
rootCmd.Flags().StringP("jira-version", "v", "", "Version name for Jira")
3431
rootCmd.Flags().StringP("tag", "t", "", "Existing git tag")
3532
rootCmd.Flags().StringP("jira-email", "e", "", "Jira email")
3633
rootCmd.Flags().StringP("jira-token", "k", "", "Jira token/key/password")
3734
rootCmd.Flags().StringP("jira-project", "p", "", "Jira project, it has to be ID, example: 10003")
3835
rootCmd.Flags().StringP("jira-base-url", "u", "", "Jira service base url, example: https://example.atlassian.net")
3936
rootCmd.Flags().StringP("dir", "d", pwd, "Absolute directory path to git repository")
40-
rootCmd.Flags().BoolP("dry-run", "", false, "Enable dry run mode")
41-
rootCmd.MarkFlagRequired("tag")
42-
rootCmd.MarkFlagRequired("jira-email")
43-
rootCmd.MarkFlagRequired("jira-token")
44-
rootCmd.MarkFlagRequired("jira-project")
45-
rootCmd.MarkFlagRequired("jira-base-url")
37+
_ = rootCmd.Flags().BoolP("dry-run", "", false, "Enable dry run mode")
38+
39+
err = rootCmd.MarkFlagRequired("tag")
40+
if err != nil {
41+
fmt.Printf("err: %+v", err)
42+
os.Exit(1)
43+
}
44+
err = rootCmd.MarkFlagRequired("jira-email")
45+
if err != nil {
46+
fmt.Printf("err: %+v", err)
47+
os.Exit(1)
48+
}
49+
err = rootCmd.MarkFlagRequired("jira-token")
50+
if err != nil {
51+
fmt.Printf("err: %+v", err)
52+
os.Exit(1)
53+
}
54+
err = rootCmd.MarkFlagRequired("jira-project")
55+
if err != nil {
56+
fmt.Printf("err: %+v", err)
57+
os.Exit(1)
58+
}
59+
err = rootCmd.MarkFlagRequired("jira-base-url")
60+
if err != nil {
61+
fmt.Printf("err: %+v", err)
62+
os.Exit(1)
63+
}
4664

4765
rootCmd.Example = "jira-versioner -e jira@example.com -k pa$$wor0 -p 10003 -t v1.1.0 -u https://example.atlassian.net"
48-
}
4966

50-
func main() {
51-
Execute()
67+
if err = rootCmd.Execute(); err != nil {
68+
fmt.Println(err)
69+
os.Exit(1)
70+
}
5271
}
5372

54-
func rootFunc(c *cobra.Command, args []string) {
73+
func rootFunc(c *cobra.Command, _ []string) {
5574
log := zap.NewExample().Sugar()
5675
dryRun := false
57-
defer log.Sync()
76+
defer func() {
77+
_ = log.Sync()
78+
}()
5879

5980
tag := c.Flag("tag").Value.String()
6081

@@ -66,42 +87,44 @@ func rootFunc(c *cobra.Command, args []string) {
6687
jiraEmail := c.Flag("jira-email").Value.String()
6788
jiraToken := c.Flag("jira-token").Value.String()
6889
jiraProject := c.Flag("jira-project").Value.String()
69-
jiraBaseUrl := c.Flag("jira-base-url").Value.String()
90+
jiraBaseURL := c.Flag("jira-base-url").Value.String()
7091
dryRunRaw := c.Flag("dry-run").Value.String()
7192
if dryRunRaw == "true" {
7293
dryRun = true
7394
}
7495
gitDir := c.Flag("dir").Value.String()
7596

7697
log.Debugf(
77-
"[JIRA-VERSIONER] starting with params jira-email: %s, jira-token: %s, jira-project: %s, jira-base-url: %s, dir: %s, tag: %s, jira-version: %s, dry-run: %t",
78-
jiraEmail,
79-
jiraToken,
80-
jiraProject,
81-
jiraBaseUrl,
82-
gitDir,
83-
tag,
84-
version,
85-
dryRun,
98+
"[JIRA-VERSIONER] starting with parameters: %+v",
99+
map[string]interface{}{
100+
"jiraEmail": jiraEmail,
101+
"jiraToken": jiraToken,
102+
"jiraProject": jiraProject,
103+
"jiraBaseURL": jiraBaseURL,
104+
"gitDir": gitDir,
105+
"tag": tag,
106+
"version": version,
107+
"dryRun": dryRun,
108+
},
86109
)
87110
log.Infof("[JIRA-VERSIONER] git directory: %s", gitDir)
88111

89112
g := git.New(gitDir, log)
90113

91114
tasks, err := g.GetTasks(tag)
92115
if err != nil {
93-
log.Fatalf("[GIT] error while getting tasks since latest commit %+v", err)
116+
log.Fatalf("[GIT] error while getting tasks since latest commit %+v", err) // nolint
94117
}
95118

96-
var jiraConfig = jira.NewConfig{
119+
var jiraConfig = jira.Config{
97120
Username: jiraEmail,
98121
Token: jiraToken,
99122
ProjectID: jiraProject,
100-
BaseURL: jiraBaseUrl,
123+
BaseURL: jiraBaseURL,
101124
Log: log,
102125
DryRun: dryRun,
103126
}
104-
j, err := jira.New(jiraConfig)
127+
j, err := jira.New(&jiraConfig)
105128
if err != nil {
106129
log.Fatalf("[VERSION] error while connecting to jira server %+v", err)
107130
}
@@ -115,10 +138,3 @@ func rootFunc(c *cobra.Command, args []string) {
115138

116139
log.Infof("[JIRA-VERSIONER] done ✅")
117140
}
118-
119-
func Execute() {
120-
if err := rootCmd.Execute(); err != nil {
121-
fmt.Println(err)
122-
os.Exit(1)
123-
}
124-
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ require (
99
github.com/kr/text v0.2.0 // indirect
1010
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1111
github.com/pkg/errors v0.9.1
12-
github.com/spf13/cobra v1.0.0
13-
github.com/spf13/pflag v1.0.5 // indirect
12+
github.com/spf13/cobra v1.1.3
1413
github.com/stretchr/testify v1.6.1
1514
github.com/trivago/tgo v1.0.7 // indirect
16-
go.uber.org/zap v1.15.0
15+
go.uber.org/multierr v1.6.0 // indirect
16+
go.uber.org/zap v1.16.0
1717
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
1818
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c // indirect
1919
)

0 commit comments

Comments
 (0)