Skip to content

Commit 8f8dfe6

Browse files
committed
refactor: modernize linting and refactor code for consistency and clarity
- Update golangci-lint configuration to use a more modern format, revise enabled linters and add formatter settings - Split environment variable lists in main.go into multiple lines for better readability - Refactor function signatures for consistency in repo/key.go and repo/remote.go Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 702ee82 commit 8f8dfe6

4 files changed

Lines changed: 97 additions & 51 deletions

File tree

.golangci.yml

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,63 @@
1-
run:
2-
timeout: 5m
1+
version: "2"
32
linters:
3+
default: none
44
enable:
5-
- asciicheck
5+
- bodyclose
66
- dogsled
7-
- durationcheck
7+
- dupl
88
- errcheck
9-
- errorlint
10-
- exportloopref
11-
- gci
12-
- gofmt
13-
- goimports
9+
- exhaustive
10+
- goconst
11+
- gocritic
12+
- gocyclo
13+
- goprintffuncname
1414
- gosec
15+
- govet
16+
- ineffassign
1517
- misspell
1618
- nakedret
17-
- nilerr
18-
- perfsprint
19-
- revive
20-
- testifylint
21-
- usestdlibvars
22-
- wastedassign
19+
- noctx
20+
- nolintlint
21+
- rowserrcheck
22+
- staticcheck
23+
- unconvert
24+
- unparam
25+
- unused
26+
- whitespace
27+
- copyloopvar
28+
- predeclared
29+
exclusions:
30+
generated: lax
31+
presets:
32+
- comments
33+
- common-false-positives
34+
- legacy
35+
- std-error-handling
36+
paths:
37+
- internal/mocks
38+
- third_party$
39+
- builtin$
40+
- examples$
41+
formatters:
42+
enable:
43+
- gofmt
44+
- gofumpt
45+
- goimports
46+
- golines
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$
2353

24-
linters-settings:
25-
gosec:
26-
# To select a subset of rules to run.
27-
# Available rules: https://github.com/securego/gosec#available-rules
28-
# Default: [] - means include all rules
29-
includes: []
30-
# To exclude a subset of rules from running.
31-
# Default: [] - means exclude no rules
32-
excludes:
33-
- G402
34-
perfsprint:
35-
err-error: true
36-
errorf: true
37-
int-conversion: true
38-
sprintf1: true
39-
strconcat: true
40-
testifylint:
41-
enable-all: true
54+
settings:
55+
gofmt:
56+
simplify: true
57+
gofumpt:
58+
# Module path which contains the source code being formatted.
59+
# Default: ""
60+
module-path: github/appleboy/drone-git-push
61+
# Choose whether to use the extra rules.
62+
# Default: false
63+
extra-rules: true

main.go

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,24 @@ func main() {
3434
app.Version = Version
3535
app.Flags = []cli.Flag{
3636
&cli.StringFlag{
37-
Name: "commit.author.name",
38-
Usage: "git author name",
39-
EnvVars: []string{"PLUGIN_AUTHOR_NAME", "DRONE_COMMIT_AUTHOR", "CI_COMMIT_AUTHOR", "INPUT_AUTHOR_NAME"},
37+
Name: "commit.author.name",
38+
Usage: "git author name",
39+
EnvVars: []string{
40+
"PLUGIN_AUTHOR_NAME",
41+
"DRONE_COMMIT_AUTHOR",
42+
"CI_COMMIT_AUTHOR",
43+
"INPUT_AUTHOR_NAME",
44+
},
4045
},
4146
&cli.StringFlag{
42-
Name: "commit.author.email",
43-
Usage: "git author email",
44-
EnvVars: []string{"PLUGIN_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL", "CI_COMMIT_AUTHOR_EMAIL", "INPUT_AUTHOR_EMAIL"},
47+
Name: "commit.author.email",
48+
Usage: "git author email",
49+
EnvVars: []string{
50+
"PLUGIN_AUTHOR_EMAIL",
51+
"DRONE_COMMIT_AUTHOR_EMAIL",
52+
"CI_COMMIT_AUTHOR_EMAIL",
53+
"INPUT_AUTHOR_EMAIL",
54+
},
4555
},
4656

4757
&cli.StringFlag{
@@ -50,14 +60,24 @@ func main() {
5060
EnvVars: []string{"PLUGIN_NETRC_MACHINE", "DRONE_NETRC_MACHINE", "INPUT_NETRC_MACHINE"},
5161
},
5262
&cli.StringFlag{
53-
Name: "netrc.username",
54-
Usage: "netrc username",
55-
EnvVars: []string{"PLUGIN_USERNAME", "DRONE_NETRC_USERNAME", "GITHUB_USERNAME", "INPUT_USERNAME"},
63+
Name: "netrc.username",
64+
Usage: "netrc username",
65+
EnvVars: []string{
66+
"PLUGIN_USERNAME",
67+
"DRONE_NETRC_USERNAME",
68+
"GITHUB_USERNAME",
69+
"INPUT_USERNAME",
70+
},
5671
},
5772
&cli.StringFlag{
58-
Name: "netrc.password",
59-
Usage: "netrc password",
60-
EnvVars: []string{"PLUGIN_PASSWORD", "DRONE_NETRC_PASSWORD", "GITHUB_PASSWORD", "INPUT_PASSWORD"},
73+
Name: "netrc.password",
74+
Usage: "netrc password",
75+
EnvVars: []string{
76+
"PLUGIN_PASSWORD",
77+
"DRONE_NETRC_PASSWORD",
78+
"GITHUB_PASSWORD",
79+
"INPUT_PASSWORD",
80+
},
6181
},
6282
&cli.StringFlag{
6383
Name: "ssh-key",
@@ -113,9 +133,13 @@ func main() {
113133
EnvVars: []string{"PLUGIN_COMMIT", "GIT_PUSH_COMMIT", "INPUT_COMMIT"},
114134
},
115135
&cli.StringFlag{
116-
Name: "commit-message",
117-
Usage: "commit message",
118-
EnvVars: []string{"PLUGIN_COMMIT_MESSAGE", "GIT_PUSH_COMMIT_MESSAGE", "INPUT_COMMIT_MESSAGE"},
136+
Name: "commit-message",
137+
Usage: "commit message",
138+
EnvVars: []string{
139+
"PLUGIN_COMMIT_MESSAGE",
140+
"GIT_PUSH_COMMIT_MESSAGE",
141+
"INPUT_COMMIT_MESSAGE",
142+
},
119143
},
120144
&cli.StringFlag{
121145
Name: "tag",

repo/key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func WriteNetrc(machine, login, password string) error {
8383
}
8484

8585
// WriteToken authenticate with Git hosting using a token.
86-
func WriteToken(remote string, login, password string) (string, error) {
86+
func WriteToken(remote, login, password string) (string, error) {
8787
if remote == "" || login == "" || password == "" {
8888
return remote, nil
8989
}

repo/remote.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func RemoteAdd(name, url string) *exec.Cmd {
2929
}
3030

3131
// RemotePush pushs the changes from the local head to a remote branch..
32-
func RemotePush(remote, branch string, force bool, followtags bool) *exec.Cmd {
32+
func RemotePush(remote, branch string, force, followtags bool) *exec.Cmd {
3333
return RemotePushNamedBranch(remote, "HEAD", branch, force, followtags)
3434
}
3535

@@ -58,7 +58,7 @@ func isValidInput(input string) bool {
5858
}
5959

6060
// RemotePushNamedBranch puchs changes from a local to a remote branch.
61-
func RemotePushNamedBranch(remote, localbranch string, branch string, force bool, followtags bool) *exec.Cmd {
61+
func RemotePushNamedBranch(remote, localbranch, branch string, force, followtags bool) *exec.Cmd {
6262
sanitizedRemote := sanitizeInput(remote)
6363
sanitizedLocalBranch := sanitizeInput(localbranch)
6464
sanitizedBranch := sanitizeInput(branch)

0 commit comments

Comments
 (0)