Skip to content

Commit

Permalink
chore(deps): update dependency golangci/golangci-lint to v1.54.2 (#711)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency golangci/golangci-lint to v1.54.2

* chore(aqua): update aqua-checksums.json

* refactor: fix lint errors

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: suzuki-shunsuke-app[bot] <91834585+suzuki-shunsuke-app[bot]@users.noreply.github.com>
Co-authored-by: Shunsuke Suzuki <suzuki.shunsuke.1989@gmail.com>
  • Loading branch information
3 people committed Oct 7, 2023
1 parent 3e7f2ec commit 475ee37
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 96 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters:
- exhaustivestruct
- varnamelen
- ireturn
- depguard
# TODO
- dupl
- wrapcheck
Expand Down
24 changes: 12 additions & 12 deletions aqua-checksums.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{
"checksums": [
{
"id": "github_release/github.com/golangci/golangci-lint/v1.51.2/golangci-lint-1.51.2-darwin-amd64.tar.gz",
"checksum": "0549CBAA2DF451CF3A2011A9D73A9CB127784D26749D9CD14C9F4818AF104D44",
"id": "github_release/github.com/golangci/golangci-lint/v1.54.2/golangci-lint-1.54.2-darwin-amd64.tar.gz",
"checksum": "925C4097EAE9E035B0B052A66D0A149F861E2AB611A4E677C7FFD2D4E05B9B89",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/golangci/golangci-lint/v1.51.2/golangci-lint-1.51.2-darwin-arm64.tar.gz",
"checksum": "36E69882205A0E42A63AD57EC3015639C11051E03F0BEB9CF7949C6451408960",
"id": "github_release/github.com/golangci/golangci-lint/v1.54.2/golangci-lint-1.54.2-darwin-arm64.tar.gz",
"checksum": "7B33FB1BE2F26B7E3D1F3C10CE9B2B5CE6D13BB1D8468A4B2BA794F05B4445E1",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/golangci/golangci-lint/v1.51.2/golangci-lint-1.51.2-linux-amd64.tar.gz",
"checksum": "4DE479EB9D9BC29DA51AEC1834E7C255B333723D38DBD56781C68E5DDDC6A90B",
"id": "github_release/github.com/golangci/golangci-lint/v1.54.2/golangci-lint-1.54.2-linux-amd64.tar.gz",
"checksum": "17C9CA05253EFE833D47F38CAF670AAD2202B5E6515879A99873FABD4C7452B3",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/golangci/golangci-lint/v1.51.2/golangci-lint-1.51.2-linux-arm64.tar.gz",
"checksum": "9E03C47B7628D49F950445D74881A0E3CB3A1E6B3C5AC3B67672D600124C1B08",
"id": "github_release/github.com/golangci/golangci-lint/v1.54.2/golangci-lint-1.54.2-linux-arm64.tar.gz",
"checksum": "A9F14B33473C65FCFBF411EC054B53A87DBB849F4E09EE438F1EE76DBF3F3D4E",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/golangci/golangci-lint/v1.51.2/golangci-lint-1.51.2-windows-amd64.zip",
"checksum": "AAC163D9BF3F79457399C2852CFAE550CD250F23DF9B324966F9C54E767FF42D",
"id": "github_release/github.com/golangci/golangci-lint/v1.54.2/golangci-lint-1.54.2-windows-amd64.zip",
"checksum": "CE17D122F3F93E0A9E52009D2C03CC1C1A1AE28338C2702A1F53ECCD10A1AFA3",
"algorithm": "sha256"
},
{
"id": "github_release/github.com/golangci/golangci-lint/v1.51.2/golangci-lint-1.51.2-windows-arm64.zip",
"checksum": "DA25A1202B10FCFAA5FBA02FF1D41A2D81562BEC52231F3239FFD8AF7CD3E143",
"id": "github_release/github.com/golangci/golangci-lint/v1.54.2/golangci-lint-1.54.2-windows-arm64.zip",
"checksum": "6A324882E39B47939B8BEC23F04449C730123C9D2FF771C3F40942AB37A26D8D",
"algorithm": "sha256"
},
{
Expand Down
2 changes: 1 addition & 1 deletion aqua/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
packages:
- name: golangci/golangci-lint@v1.51.2
- name: golangci/golangci-lint@v1.54.2
2 changes: 1 addition & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (ctrl *Controller) getNotifier(ctx context.Context) (notifier.Notifier, err
}
// Write output to file instead of github comment
if ctrl.Config.Output != "" {
client, err := localfile.NewClient(ctx, &localfile.Config{
client, err := localfile.NewClient(&localfile.Config{
OutputFile: ctrl.Config.Output,
Parser: ctrl.Parser,
UseRawOutput: ctrl.Config.Terraform.UseRawOutput,
Expand Down
5 changes: 3 additions & 2 deletions pkg/notifier/github/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package github

import (
"context"
"fmt"

"github.com/sirupsen/logrus"
"github.com/suzuki-shunsuke/tfcmt/v4/pkg/notifier"
Expand All @@ -16,7 +17,7 @@ func (g *NotifyService) Apply(ctx context.Context, param *notifier.ParamExec) er
var errMsgs []string

if cfg.PR.Number == 0 {
if prNumber, err := g.client.Commits.PRNumber(ctx, cfg.PR.Revision, PullRequestStateClosed); err == nil {
if prNumber, err := g.client.Commits.PRNumber(ctx, cfg.PR.Revision); err == nil {
cfg.PR.Number = prNumber
}
}
Expand Down Expand Up @@ -78,7 +79,7 @@ func (g *NotifyService) Apply(ctx context.Context, param *notifier.ParamExec) er
Number: cfg.PR.Number,
Revision: cfg.PR.Revision,
}); err != nil {
return err
return fmt.Errorf("post a comment: %w", err)
}
return nil
}
75 changes: 41 additions & 34 deletions pkg/notifier/github/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,87 @@ package github

import (
"context"
"os"
"testing"
)

func TestNewClient(t *testing.T) { //nolint:paralleltest
t.Setenv(EnvToken, "")

testCases := []struct {
name string
config Config
envToken string
expect string
}{
{
// specify directly
name: "specify directly",
config: Config{Token: "abcdefg"},
envToken: "",
expect: "",
},
{
// specify via env but not to be set env (part 1)
name: "specify via env but not to be set env (part 1)",
config: Config{Token: "GITHUB_TOKEN"},
envToken: "",
expect: "github token is missing",
},
{
// specify via env (part 1)
name: "specify via env (part 1)",
config: Config{Token: "GITHUB_TOKEN"},
envToken: "abcdefg",
expect: "",
},
{
// specify via env but not to be set env (part 2)
name: "specify via env but not to be set env (part 2)",
config: Config{Token: "$GITHUB_TOKEN"},
envToken: "",
expect: "github token is missing",
},
{
// specify via env (part 2)
name: "specify via env (part 2)",
config: Config{Token: "$GITHUB_TOKEN"},
envToken: "abcdefg",
expect: "",
},
{
// no specification (part 1)
name: "no specification (part 1)",
config: Config{},
envToken: "",
expect: "github token is missing",
},
{
// no specification (part 2)
name: "no specification (part 2)",
config: Config{},
envToken: "abcdefg",
expect: "github token is missing",
},
}
for _, testCase := range testCases {
os.Setenv(EnvToken, testCase.envToken)
_, err := NewClient(context.Background(), &testCase.config)
if err == nil {
continue
}
if err.Error() != testCase.expect {
t.Errorf("got %q but want %q", err.Error(), testCase.expect)
}
for _, testCase := range testCases { //nolint:paralleltest
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Setenv(EnvToken, testCase.envToken)
_, err := NewClient(context.Background(), &testCase.config)
if err == nil {
return
}
if err.Error() != testCase.expect {
t.Errorf("got %q but want %q", err.Error(), testCase.expect)
}
})
}
}

func TestNewClientWithBaseURL(t *testing.T) { //nolint:paralleltest
t.Setenv(EnvBaseURL, "")

testCases := []struct {
name string
config Config
envBaseURL string
expect string
}{
{
// specify directly
name: "specify directly",
config: Config{
Token: "abcdefg",
BaseURL: "https://git.example.com/api/v3/",
Expand All @@ -87,7 +91,7 @@ func TestNewClientWithBaseURL(t *testing.T) { //nolint:paralleltest
expect: "https://git.example.com/api/v3/",
},
{
// specify via env but not to be set env (part 1)
name: "specify via env but not to be set env (part 1)",
config: Config{
Token: "abcdefg",
BaseURL: "GITHUB_BASE_URL",
Expand All @@ -96,7 +100,7 @@ func TestNewClientWithBaseURL(t *testing.T) { //nolint:paralleltest
expect: "https://api.github.com/",
},
{
// specify via env (part 1)
name: "specify via env (part 1)",
config: Config{
Token: "abcdefg",
BaseURL: "GITHUB_BASE_URL",
Expand All @@ -105,7 +109,7 @@ func TestNewClientWithBaseURL(t *testing.T) { //nolint:paralleltest
expect: "https://git.example.com/api/v3/",
},
{
// specify via env but not to be set env (part 2)
name: "specify via env but not to be set env (part 2)",
config: Config{
Token: "abcdefg",
BaseURL: "$GITHUB_BASE_URL",
Expand All @@ -114,7 +118,7 @@ func TestNewClientWithBaseURL(t *testing.T) { //nolint:paralleltest
expect: "https://api.github.com/",
},
{
// specify via env (part 2)
name: "specify via env (part 2)",
config: Config{
Token: "abcdefg",
BaseURL: "$GITHUB_BASE_URL",
Expand All @@ -123,28 +127,31 @@ func TestNewClientWithBaseURL(t *testing.T) { //nolint:paralleltest
expect: "https://git.example.com/api/v3/",
},
{
// no specification (part 1)
name: "no specification (part 1)",
config: Config{Token: "abcdefg"},
envBaseURL: "",
expect: "https://api.github.com/",
},
{
// no specification (part 2)
name: "no specification (part 2)",
config: Config{Token: "abcdefg"},
envBaseURL: "https://git.example.com/api/v3/",
expect: "https://api.github.com/",
},
}
for _, testCase := range testCases {
os.Setenv(EnvBaseURL, testCase.envBaseURL)
c, err := NewClient(context.Background(), &testCase.config)
if err != nil {
continue
}
url := c.Client.BaseURL.String()
if url != testCase.expect {
t.Errorf("got %q but want %q", url, testCase.expect)
}
for _, testCase := range testCases { //nolint:paralleltest
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Setenv(EnvBaseURL, testCase.envBaseURL)
c, err := NewClient(context.Background(), &testCase.config)
if err != nil {
t.Fatal(err)
}
url := c.Client.BaseURL.String()
if url != testCase.expect {
t.Errorf("got %q but want %q", url, testCase.expect)
}
})
}
}

Expand Down
37 changes: 18 additions & 19 deletions pkg/notifier/github/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
func TestCommentPost(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
config Config
body string
opt PostOptions
ok bool
}{
{
name: "1",
config: newFakeConfig(),
body: "",
opt: PostOptions{
Expand All @@ -23,15 +25,7 @@ func TestCommentPost(t *testing.T) {
ok: true,
},
{
config: newFakeConfig(),
body: "",
opt: PostOptions{
Number: 0,
Revision: "abcd",
},
ok: true,
},
{
name: "2",
config: newFakeConfig(),
body: "",
opt: PostOptions{
Expand All @@ -41,6 +35,7 @@ func TestCommentPost(t *testing.T) {
ok: true,
},
{
name: "3",
config: newFakeConfig(),
body: "",
opt: PostOptions{
Expand All @@ -52,15 +47,19 @@ func TestCommentPost(t *testing.T) {
}

for _, testCase := range testCases {
client, err := NewClient(context.Background(), &testCase.config)
if err != nil {
t.Fatal(err)
}
api := newFakeAPI()
client.API = &api
err = client.Comment.Post(context.Background(), testCase.body, &testCase.opt)
if (err == nil) != testCase.ok {
t.Errorf("got error %q", err)
}
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
client, err := NewClient(context.Background(), &testCase.config)
if err != nil {
t.Fatal(err)
}
api := newFakeAPI()
client.API = &api
err = client.Comment.Post(context.Background(), testCase.body, &testCase.opt)
if (err == nil) != testCase.ok {
t.Errorf("got error %q", err)
}
})
}
}
10 changes: 1 addition & 9 deletions pkg/notifier/github/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import (
// methods of GitHub API
type CommitsService service

type PullRequestState string

const (
PullRequestStateOpen = "open"
PullRequestStateClosed = "closed"
PullRequestStateAll = "all"
)

func (g *CommitsService) PRNumber(ctx context.Context, sha string, state PullRequestState) (int, error) {
func (g *CommitsService) PRNumber(ctx context.Context, sha string) (int, error) {
prs, _, err := g.client.API.PullRequestsListPullRequestsWithCommit(ctx, sha, &github.ListOptions{})
if err != nil {
return 0, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/notifier/github/commits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestPRNumber(t *testing.T) {
}
api := newFakeAPI()
client.API = &api
prNumber, err := client.Commits.PRNumber(context.Background(), testCase.revision, PullRequestStateOpen)
prNumber, err := client.Commits.PRNumber(context.Background(), testCase.revision)
if (err == nil) != testCase.ok {
t.Errorf("got error %q", err)
}
Expand Down

0 comments on commit 475ee37

Please sign in to comment.