Skip to content

Commit 60c1a88

Browse files
committed
refactor: remove code lints
Signed-off-by: Luis Davim <dluis@vmware.com>
1 parent c209547 commit 60c1a88

File tree

7 files changed

+341
-57
lines changed

7 files changed

+341
-57
lines changed

cmd/jiralert/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func main() {
6161

6262
flag.Parse()
6363

64-
var logger = setupLogger(*logLevel, *logFormat)
64+
logger := setupLogger(*logLevel, *logFormat)
6565
level.Info(logger).Log("msg", "starting JIRAlert", "version", Version)
6666

6767
if !*hashJiraLabel {
@@ -133,7 +133,6 @@ func main() {
133133
return
134134
}
135135
requestTotal.WithLabelValues(conf.Name, "200").Inc()
136-
137136
})
138137

139138
http.HandleFunc("/", HomeHandlerFunc())

cmd/jiralert/telemetry.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ package main
1515

1616
import "github.com/prometheus/client_golang/prometheus"
1717

18-
var (
19-
requestTotal = prometheus.NewCounterVec(
20-
prometheus.CounterOpts{
21-
Name: "jiralert_requests_total",
22-
Help: "Requests processed, by receiver and status code.",
23-
},
24-
[]string{"receiver", "code"},
25-
)
18+
var requestTotal = prometheus.NewCounterVec(
19+
prometheus.CounterOpts{
20+
Name: "jiralert_requests_total",
21+
Help: "Requests processed, by receiver and status code.",
22+
},
23+
[]string{"receiver", "code"},
2624
)
2725

2826
func init() {

go.mod

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,27 @@ require (
77
github.com/go-kit/kit v0.10.0
88
github.com/go-kit/log v0.2.1
99
github.com/pkg/errors v0.9.1
10-
github.com/prometheus/client_golang v1.6.0
11-
github.com/stretchr/testify v1.5.1
10+
github.com/prometheus/client_golang v1.13.0
11+
github.com/stretchr/testify v1.7.0
1212
github.com/trivago/tgo v1.0.7
13-
golang.org/x/text v0.3.2
13+
golang.org/x/text v0.4.0
1414
gopkg.in/yaml.v3 v3.0.1
1515
)
1616

1717
require (
1818
github.com/beorn7/perks v1.0.1 // indirect
19-
github.com/cespare/xxhash/v2 v2.1.1 // indirect
19+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
2020
github.com/davecgh/go-spew v1.1.1 // indirect
2121
github.com/fatih/structs v1.1.0 // indirect
2222
github.com/go-logfmt/logfmt v0.5.1 // indirect
2323
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
24-
github.com/golang/protobuf v1.4.1 // indirect
24+
github.com/golang/protobuf v1.5.2 // indirect
2525
github.com/google/go-querystring v1.1.0 // indirect
2626
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
2727
github.com/pmezard/go-difflib v1.0.0 // indirect
2828
github.com/prometheus/client_model v0.2.0 // indirect
29-
github.com/prometheus/common v0.10.0 // indirect
30-
github.com/prometheus/procfs v0.0.11 // indirect
29+
github.com/prometheus/common v0.37.0 // indirect
30+
github.com/prometheus/procfs v0.8.0 // indirect
3131
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 // indirect
32-
google.golang.org/protobuf v1.22.0 // indirect
33-
gopkg.in/yaml.v2 v2.3.0 // indirect
32+
google.golang.org/protobuf v1.28.1 // indirect
3433
)

go.sum

Lines changed: 310 additions & 17 deletions
Large diffs are not rendered by default.

pkg/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func LoadFile(filename string, logger log.Logger) (*Config, []byte, error) {
8282
// expand env variables $(var) from the config file
8383
// taken from https://github.dev/thanos-io/thanos/blob/296c4ab4baf2c8dd6abdf2649b0660ac77505e63/pkg/reloader/reloader.go#L445-L462 by https://github.com/fabxc
8484
func substituteEnvVars(b []byte, logger log.Logger) (r []byte, err error) {
85-
var envRe = regexp.MustCompile(`\$\(([a-zA-Z_0-9]+)\)`)
85+
envRe := regexp.MustCompile(`\$\(([a-zA-Z_0-9]+)\)`)
8686
r = envRe.ReplaceAllFunc(b, func(n []byte) []byte {
8787
if err != nil {
8888
return nil
@@ -92,7 +92,7 @@ func substituteEnvVars(b []byte, logger log.Logger) (r []byte, err error) {
9292

9393
v, ok := os.LookupEnv(string(n))
9494
if !ok {
95-
err = fmt.Errorf("Missing env variable: %q", n)
95+
err = fmt.Errorf("missing env variable: %q", n)
9696
return nil
9797
}
9898
return []byte(v)

pkg/config/config_test.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,10 @@ func TestLoadFile(t *testing.T) {
8989

9090
require.NoError(t, err)
9191
require.Equal(t, testConf, string(content))
92-
9392
}
9493

9594
// Checks if the env var substitution is happening correctly in the loaded file
9695
func TestEnvSubstitution(t *testing.T) {
97-
9896
config := "user: $(JA_USER)"
9997
os.Setenv("JA_USER", "user")
10098

@@ -106,7 +104,6 @@ func TestEnvSubstitution(t *testing.T) {
106104
config = "user: $(JA_MISSING)"
107105
_, err = substituteEnvVars([]byte(config), log.NewNopLogger())
108106
require.Error(t, err)
109-
110107
}
111108

112109
// A test version of the ReceiverConfig struct to create test yaml fixtures.
@@ -186,7 +183,6 @@ func TestRequiredReceiverConfigKeys(t *testing.T) {
186183
}
187184
configErrorTestRunner(t, config, test.errorMessage)
188185
}
189-
190186
}
191187

192188
// Auth keys error scenarios.
@@ -352,7 +348,6 @@ func TestReceiverOverrides(t *testing.T) {
352348
configValue := reflect.ValueOf(receiver).Elem().FieldByName(test.overrideField).Interface()
353349
require.Equal(t, configValue, test.expectedValue)
354350
}
355-
356351
}
357352

358353
// TODO(bwplotka, rporres). Add more tests:
@@ -366,11 +361,12 @@ func newReceiverTestConfig(mandatory []string, optional []string) *receiverTestC
366361

367362
for _, name := range mandatory {
368363
var value reflect.Value
369-
if name == "APIURL" {
364+
switch name {
365+
case "APIURL":
370366
value = reflect.ValueOf("https://jiralert.atlassian.net")
371-
} else if name == "ReopenDuration" {
367+
case "ReopenDuration":
372368
value = reflect.ValueOf("30d")
373-
} else {
369+
default:
374370
value = reflect.ValueOf(name)
375371
}
376372

@@ -379,11 +375,12 @@ func newReceiverTestConfig(mandatory []string, optional []string) *receiverTestC
379375

380376
for _, name := range optional {
381377
var value reflect.Value
382-
if name == "AddGroupLabels" {
378+
switch name {
379+
case "AddGroupLabels":
383380
value = reflect.ValueOf(true)
384-
} else if name == "AutoResolve" {
381+
case "AutoResolve":
385382
value = reflect.ValueOf(&AutoResolve{State: "Done"})
386-
} else {
383+
default:
387384
value = reflect.ValueOf(name)
388385
}
389386

@@ -418,8 +415,10 @@ func removeFromStrSlice(strSlice []string, element string) []string {
418415
// Returns mandatory receiver fields to be used creating test config structs.
419416
// It does not include PAT auth, those tests will be created separately.
420417
func mandatoryReceiverFields() []string {
421-
return []string{"Name", "APIURL", "User", "Password", "Project",
422-
"IssueType", "Summary", "ReopenState", "ReopenDuration"}
418+
return []string{
419+
"Name", "APIURL", "User", "Password", "Project",
420+
"IssueType", "Summary", "ReopenState", "ReopenDuration",
421+
}
423422
}
424423

425424
func TestAutoResolveConfigReceiver(t *testing.T) {
@@ -439,7 +438,6 @@ func TestAutoResolveConfigReceiver(t *testing.T) {
439438
}
440439

441440
configErrorTestRunner(t, config, "bad config in receiver \"test\", 'auto_resolve' was defined with empty 'state' field")
442-
443441
}
444442

445443
func TestAutoResolveConfigDefault(t *testing.T) {
@@ -457,5 +455,4 @@ func TestAutoResolveConfigDefault(t *testing.T) {
457455
}
458456

459457
configErrorTestRunner(t, config, "bad config in defaults section: state cannot be empty")
460-
461458
}

pkg/notify/notify.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,11 @@ func toGroupTicketLabel(groupLabels alertmanager.KV, hashJiraLabel bool) string
261261
// old default behavior
262262
buf := bytes.NewBufferString("ALERT{")
263263
for _, p := range groupLabels.SortedPairs() {
264-
buf.WriteString(p.Name)
265-
buf.WriteString(fmt.Sprintf("=%q,", p.Value))
264+
fmt.Fprintf(buf, "%s=%q,", p.Name, p.Value)
266265
}
267266
buf.Truncate(buf.Len() - 1)
268267
buf.WriteString("}")
269-
return strings.Replace(buf.String(), " ", "", -1)
268+
return strings.ReplaceAll(buf.String(), " ", "")
270269
}
271270

272271
func (r *Receiver) search(project, issueLabel string) (*jira.Issue, bool, error) {
@@ -406,5 +405,4 @@ func (r *Receiver) doTransition(issueKey string, transitionState string) (bool,
406405
}
407406
}
408407
return false, errors.Errorf("JIRA state %q does not exist or no transition possible for %s", r.conf.ReopenState, issueKey)
409-
410408
}

0 commit comments

Comments
 (0)