Skip to content

Commit 92b14bb

Browse files
committed
Merge branch '784-auditevent-lint' of gitlab.com:gitlab-community/gitlab-shell into 782-lfs-lint
2 parents 0b7fb26 + bbc531d commit 92b14bb

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ GO_TAGS := tracer_static tracer_static_jaeger continuous_profiler_stackdriver
99

1010
ARCH ?= $(shell uname -m | sed -e 's/x86_64/amd64/' | sed -e 's/aarch64/arm64/')
1111

12-
GOTESTSUM_VERSION := 1.11.0
12+
GOTESTSUM_VERSION := 1.12.0
1313
GOTESTSUM_FILE := support/bin/gotestsum-${GOTESTSUM_VERSION}
1414

15-
GOLANGCI_LINT_VERSION := 1.60.2
15+
GOLANGCI_LINT_VERSION := 1.60.3
1616
GOLANGCI_LINT_FILE := support/bin/golangci-lint-${GOLANGCI_LINT_VERSION}
1717

1818
export GOFLAGS := -mod=readonly

internal/command/gitauditevent/audit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package gitauditevent handles Git audit events for GitLab.
12
package gitauditevent
23

34
import (

internal/command/gitauditevent/audit_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/command/commandargs"
@@ -30,13 +31,13 @@ func TestGitAudit(t *testing.T) {
3031
called = true
3132

3233
body, err := io.ReadAll(r.Body)
33-
require.NoError(t, err)
34+
assert.NoError(t, err)
3435
defer r.Body.Close()
3536

3637
var request *gitauditevent.Request
37-
require.NoError(t, json.Unmarshal(body, &request))
38-
require.Equal(t, testUsername, request.Username)
39-
require.Equal(t, testRepo, request.Repo)
38+
assert.NoError(t, json.Unmarshal(body, &request))
39+
assert.Equal(t, testUsername, request.Username)
40+
assert.Equal(t, testRepo, request.Repo)
4041

4142
w.WriteHeader(http.StatusOK)
4243
},

internal/gitlabnet/gitauditevent/client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package gitauditevent handles Git audit events for GitLab.
12
package gitauditevent
23

34
import (
@@ -13,11 +14,13 @@ import (
1314

1415
const uri = "/api/v4/internal/shellhorse/git_audit_event"
1516

17+
// Client handles communication with the GitLab audit event API.
1618
type Client struct {
1719
config *config.Config
1820
client *client.GitlabNetClient
1921
}
2022

23+
// NewClient creates a new Client for sending audit events.
2124
func NewClient(config *config.Config) (*Client, error) {
2225
client, err := gitlabnet.GetClient(config)
2326
if err != nil {
@@ -27,6 +30,7 @@ func NewClient(config *config.Config) (*Client, error) {
2730
return &Client{config: config, client: client}, nil
2831
}
2932

33+
// Request represents the data for a Git audit event.
3034
type Request struct {
3135
Action commandargs.CommandType `json:"action"`
3236
Protocol string `json:"protocol"`
@@ -35,6 +39,7 @@ type Request struct {
3539
PackfileStats *pb.PackfileNegotiationStatistics `json:"packfile_stats,omitempty"`
3640
}
3741

42+
// Audit sends an audit event to the GitLab API.
3843
func (c *Client) Audit(ctx context.Context, username string, action commandargs.CommandType, repo string, packfileStats *pb.PackfileNegotiationStatistics) error {
3944
request := &Request{
4045
Action: action,
@@ -48,6 +53,6 @@ func (c *Client) Audit(ctx context.Context, username string, action commandargs.
4853
if err != nil {
4954
return err
5055
}
51-
defer response.Body.Close()
56+
defer response.Body.Close() //nolint:errcheck
5257
return nil
5358
}

internal/gitlabnet/gitauditevent/client_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"testing"
99

10+
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
pb "gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
1213
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -48,17 +49,17 @@ func setup(t *testing.T, responseStatus int) *Client {
4849
Path: uri,
4950
Handler: func(w http.ResponseWriter, r *http.Request) {
5051
body, err := io.ReadAll(r.Body)
51-
require.NoError(t, err)
52+
assert.NoError(t, err)
5253
defer r.Body.Close()
5354

5455
var request *Request
55-
require.NoError(t, json.Unmarshal(body, &request))
56-
require.Equal(t, testUsername, request.Username)
57-
require.Equal(t, testAction, request.Action)
58-
require.Equal(t, testRepo, request.Repo)
59-
require.Equal(t, "ssh", request.Protocol)
60-
require.Equal(t, testPackfileWants, request.PackfileStats.Wants)
61-
require.Equal(t, testPackfileHaves, request.PackfileStats.Haves)
56+
assert.NoError(t, json.Unmarshal(body, &request))
57+
assert.Equal(t, testUsername, request.Username)
58+
assert.Equal(t, testAction, request.Action)
59+
assert.Equal(t, testRepo, request.Repo)
60+
assert.Equal(t, "ssh", request.Protocol)
61+
assert.Equal(t, testPackfileWants, request.PackfileStats.Wants)
62+
assert.Equal(t, testPackfileHaves, request.PackfileStats.Haves)
6263

6364
w.WriteHeader(responseStatus)
6465
},

support/lint_last_known_acceptable.txt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ internal/command/discover/discover.go:23:15: ST1005: error strings should not be
131131
internal/command/discover/discover.go:29:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
132132
internal/command/discover/discover.go:32:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
133133
internal/command/discover/discover.go:35:20: context-keys-type: should not use basic type string as key in context.WithValue (revive)
134-
internal/command/gitauditevent/audit.go:1:1: package-comments: should have a package comment (revive)
135-
internal/command/gitauditevent/audit_test.go:33:5: go-require: do not use require in http handlers (testifylint)
136-
internal/command/gitauditevent/audit_test.go:37:5: go-require: do not use require in http handlers (testifylint)
137-
internal/command/gitauditevent/audit_test.go:38:5: go-require: do not use require in http handlers (testifylint)
138-
internal/command/gitauditevent/audit_test.go:39:5: go-require: do not use require in http handlers (testifylint)
139134
internal/command/githttp/pull.go:1:1: package-comments: should have a package comment (revive)
140135
internal/command/githttp/pull.go:20:5: var-naming: var uploadPackHttpPrefix should be uploadPackHTTPPrefix (revive)
141136
internal/command/githttp/pull.go:22:6: exported: exported type PullCommand should have comment or be unexported (revive)
@@ -365,20 +360,6 @@ internal/gitlabnet/git/client_test.go:204:5: go-require: do not use require in h
365360
internal/gitlabnet/git/client_test.go:213:5: go-require: do not use require in http handlers (testifylint)
366361
internal/gitlabnet/git/client_test.go:214:5: go-require: do not use require in http handlers (testifylint)
367362
internal/gitlabnet/git/client_test.go:217:5: go-require: do not use require in http handlers (testifylint)
368-
internal/gitlabnet/gitauditevent/client.go:1:1: package-comments: should have a package comment (revive)
369-
internal/gitlabnet/gitauditevent/client.go:16:6: exported: exported type Client should have comment or be unexported (revive)
370-
internal/gitlabnet/gitauditevent/client.go:21:1: exported: exported function NewClient should have comment or be unexported (revive)
371-
internal/gitlabnet/gitauditevent/client.go:30:6: exported: exported type Request should have comment or be unexported (revive)
372-
internal/gitlabnet/gitauditevent/client.go:38:1: exported: exported method Client.Audit should have comment or be unexported (revive)
373-
internal/gitlabnet/gitauditevent/client.go:51:27: Error return value of `response.Body.Close` is not checked (errcheck)
374-
internal/gitlabnet/gitauditevent/client_test.go:51:5: go-require: do not use require in http handlers (testifylint)
375-
internal/gitlabnet/gitauditevent/client_test.go:55:5: go-require: do not use require in http handlers (testifylint)
376-
internal/gitlabnet/gitauditevent/client_test.go:56:5: go-require: do not use require in http handlers (testifylint)
377-
internal/gitlabnet/gitauditevent/client_test.go:57:5: go-require: do not use require in http handlers (testifylint)
378-
internal/gitlabnet/gitauditevent/client_test.go:58:5: go-require: do not use require in http handlers (testifylint)
379-
internal/gitlabnet/gitauditevent/client_test.go:59:5: go-require: do not use require in http handlers (testifylint)
380-
internal/gitlabnet/gitauditevent/client_test.go:60:5: go-require: do not use require in http handlers (testifylint)
381-
internal/gitlabnet/gitauditevent/client_test.go:61:5: go-require: do not use require in http handlers (testifylint)
382363
internal/gitlabnet/healthcheck/client_test.go:19:41: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
383364
internal/gitlabnet/lfsauthenticate/client_test.go:29:5: go-require: do not use require in http handlers (testifylint)
384365
internal/gitlabnet/lfsauthenticate/client_test.go:32:5: go-require: do not use require in http handlers (testifylint)

0 commit comments

Comments
 (0)