Skip to content

Commit e011752

Browse files
ashmckenzieArchish27
authored andcommitted
Merge branch '782-lfs-lint' into 'main'
Lint fixes for lfs packages Closes #782 See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1139 Merged-by: Ash McKenzie <[email protected]> Approved-by: Patrick Bajao <[email protected]> Co-authored-by: Archish <[email protected]>
2 parents b96ec55 + 1d3e2ff commit e011752

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

internal/gitlabnet/lfsauthenticate/client_test.go

Lines changed: 6 additions & 5 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

1213
"gitlab.com/gitlab-org/gitlab-shell/v14/client/testserver"
@@ -26,10 +27,10 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
2627
Handler: func(w http.ResponseWriter, r *http.Request) {
2728
b, err := io.ReadAll(r.Body)
2829
defer r.Body.Close()
29-
require.NoError(t, err)
30+
assert.NoError(t, err)
3031

3132
var request *Request
32-
require.NoError(t, json.Unmarshal(b, &request))
33+
assert.NoError(t, json.Unmarshal(b, &request))
3334

3435
switch request.KeyID {
3536
case keyID:
@@ -39,7 +40,7 @@ func setup(t *testing.T) []testserver.TestRequestHandler {
3940
"repository_http_path": "https://gitlab.com/repo/path",
4041
"expires_in": 1800,
4142
}
42-
require.NoError(t, json.NewEncoder(w).Encode(body))
43+
assert.NoError(t, json.NewEncoder(w).Encode(body))
4344
case "forbidden":
4445
w.WriteHeader(http.StatusForbidden)
4546
case "broken":
@@ -88,7 +89,7 @@ func TestFailedRequests(t *testing.T) {
8889
_, err = client.Authenticate(context.Background(), operation, repo, "")
8990
require.Error(t, err)
9091

91-
require.Equal(t, tc.expectedOutput, err.Error())
92+
assert.Equal(t, tc.expectedOutput, err.Error())
9293
})
9394
}
9495
}
@@ -128,7 +129,7 @@ func TestSuccessfulRequests(t *testing.T) {
128129
ExpiresIn: 1800,
129130
}
130131

131-
require.Equal(t, expectedResponse, response)
132+
assert.Equal(t, expectedResponse, response)
132133
})
133134
}
134135
}

internal/gitlabnet/lfstransfer/client.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package lfstransfer provides functionality for handling LFS (Large File Storage) transfers.
12
package lfstransfer
23

34
import (
@@ -17,6 +18,7 @@ import (
1718
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet"
1819
)
1920

21+
// Client holds configuration, arguments, and authentication details for the client.
2022
type Client struct {
2123
config *config.Config
2224
args *commandargs.Shell
@@ -25,13 +27,15 @@ type Client struct {
2527
header string
2628
}
2729

30+
// BatchAction represents an action for a batch operation with metadata.
2831
type BatchAction struct {
2932
Href string `json:"href"`
3033
Header map[string]string `json:"header,omitempty"`
3134
ExpiresAt time.Time `json:"expires_at,omitempty"`
3235
ExpiresIn int `json:"expires_in,omitempty"`
3336
}
3437

38+
// BatchObject represents an object in a batch operation with its metadata and actions.
3539
type BatchObject struct {
3640
Oid string `json:"oid,omitempty"`
3741
Size int64 `json:"size"`
@@ -50,6 +54,7 @@ type batchRequest struct {
5054
HashAlgorithm string `json:"hash_algo,omitempty"`
5155
}
5256

57+
// BatchResponse contains batch operation results and the hash algorithm used.
5358
type BatchResponse struct {
5459
Objects []*BatchObject `json:"objects"`
5560
HashAlgorithm string `json:"hash_algo,omitempty"`
@@ -79,30 +84,36 @@ type listLocksVerifyRequest struct {
7984
Ref *batchRef `json:"ref,omitempty"`
8085
}
8186

87+
// LockOwner represents the owner of a lock.
8288
type LockOwner struct {
8389
Name string `json:"name"`
8490
}
8591

92+
// Lock represents a lock with its ID, path, timestamp, and owner details.
8693
type Lock struct {
8794
ID string `json:"id"`
8895
Path string `json:"path"`
8996
LockedAt time.Time `json:"locked_at"`
9097
Owner *LockOwner `json:"owner"`
9198
}
9299

100+
// ListLocksResponse contains a list of locks and a cursor for pagination.
93101
type ListLocksResponse struct {
94102
Locks []*Lock `json:"locks,omitempty"`
95103
NextCursor string `json:"next_cursor,omitempty"`
96104
}
97105

106+
// ListLocksVerifyResponse provides lists of locks for "ours" and "theirs" with a cursor for pagination.
98107
type ListLocksVerifyResponse struct {
99108
Ours []*Lock `json:"ours,omitempty"`
100109
Theirs []*Lock `json:"theirs,omitempty"`
101110
NextCursor string `json:"next_cursor,omitempty"`
102111
}
103112

113+
// ClientHeader specifies the content type for Git LFS JSON requests.
104114
var ClientHeader = "application/vnd.git-lfs+json"
105115

116+
// NewClient creates a new Client instance using the provided configuration and credentials.
106117
func NewClient(config *config.Config, args *commandargs.Shell, href string, auth string) (*Client, error) {
107118
return &Client{config: config, args: args, href: href, auth: auth, header: ClientHeader}, nil
108119
}
@@ -121,6 +132,7 @@ func newHTTPClient() *retryablehttp.Client {
121132
return client
122133
}
123134

135+
// Batch performs a batch operation on objects and returns the result.
124136
func (c *Client) Batch(operation string, reqObjects []*BatchObject, ref string, reqHashAlgo string) (*BatchResponse, error) {
125137
// FIXME: This causes tests to fail
126138
// if ref == "" {
@@ -211,6 +223,7 @@ func (c *Client) PutObject(_, href string, headers map[string]string, r io.Reade
211223
return nil
212224
}
213225

226+
// Lock acquires a lock for the specified path with an optional reference name.
214227
func (c *Client) Lock(path, refname string) (*Lock, error) {
215228
var ref *batchRef
216229
if refname != "" {
@@ -268,6 +281,7 @@ func (c *Client) Lock(path, refname string) (*Lock, error) {
268281
}
269282
}
270283

284+
// Unlock releases the lock with the given id, optionally forcing the unlock.
271285
func (c *Client) Unlock(id string, force bool, refname string) (*Lock, error) {
272286
var ref *batchRef
273287
if refname != "" {
@@ -318,6 +332,7 @@ func (c *Client) Unlock(id string, force bool, refname string) (*Lock, error) {
318332
}
319333
}
320334

335+
// ListLocksVerify retrieves locks for the given path and id, with optional pagination.
321336
func (c *Client) ListLocksVerify(path, id, cursor string, limit int, ref string) (*ListLocksVerifyResponse, error) {
322337
url, err := url.Parse(c.href)
323338
if err != nil {

support/lint_last_known_acceptable.txt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,7 @@ internal/gitlabnet/client.go:21:15: ST1005: error strings should not be capitali
247247
internal/gitlabnet/client.go:27:1: exported: exported function ParseJSON should have comment or be unexported (revive)
248248
internal/gitlabnet/client.go:35:1: exported: exported function ParseIP should have comment or be unexported (revive)
249249
internal/gitlabnet/healthcheck/client_test.go:19:41: unused-parameter: parameter 'r' seems to be unused, consider removing or renaming it as _ (revive)
250-
internal/gitlabnet/lfsauthenticate/client_test.go:29:5: go-require: do not use require in http handlers (testifylint)
251-
internal/gitlabnet/lfsauthenticate/client_test.go:32:5: go-require: do not use require in http handlers (testifylint)
252-
internal/gitlabnet/lfsauthenticate/client_test.go:42:6: go-require: do not use require in http handlers (testifylint)
253-
internal/gitlabnet/lfstransfer/client.go:1:1: package-comments: should have a package comment (revive)
254-
internal/gitlabnet/lfstransfer/client.go:20:6: exported: exported type Client should have comment or be unexported (revive)
255-
internal/gitlabnet/lfstransfer/client.go:28:6: exported: exported type BatchAction should have comment or be unexported (revive)
256-
internal/gitlabnet/lfstransfer/client.go:35:6: exported: exported type BatchObject should have comment or be unexported (revive)
257-
internal/gitlabnet/lfstransfer/client.go:53:6: exported: exported type BatchResponse should have comment or be unexported (revive)
258-
internal/gitlabnet/lfstransfer/client.go:82:6: exported: exported type LockOwner should have comment or be unexported (revive)
259-
internal/gitlabnet/lfstransfer/client.go:86:6: exported: exported type Lock should have comment or be unexported (revive)
260-
internal/gitlabnet/lfstransfer/client.go:93:6: exported: exported type ListLocksResponse should have comment or be unexported (revive)
261-
internal/gitlabnet/lfstransfer/client.go:98:6: exported: exported type ListLocksVerifyResponse should have comment or be unexported (revive)
262-
internal/gitlabnet/lfstransfer/client.go:104:5: exported: exported var ClientHeader should have comment or be unexported (revive)
263-
internal/gitlabnet/lfstransfer/client.go:106:1: exported: exported function NewClient should have comment or be unexported (revive)
264-
internal/gitlabnet/lfstransfer/client.go:124:1: exported: exported method Client.Batch should have comment or be unexported (revive)
265-
internal/gitlabnet/lfstransfer/client.go:125: internal/gitlabnet/lfstransfer/client.go:125: Line contains TODO/BUG/FIXME/NOTE/OPTIMIZE/HACK: "FIXME: This causes tests to fail" (godox)
266-
internal/gitlabnet/lfstransfer/client.go:214:1: exported: exported method Client.Lock should have comment or be unexported (revive)
267-
internal/gitlabnet/lfstransfer/client.go:271:1: exported: exported method Client.Unlock should have comment or be unexported (revive)
268-
internal/gitlabnet/lfstransfer/client.go:321:1: exported: exported method Client.ListLocksVerify should have comment or be unexported (revive)
250+
internal/gitlabnet/lfstransfer/client.go:137: internal/gitlabnet/lfstransfer/client.go:137: Line contains TODO/BUG/FIXME/NOTE/OPTIMIZE/HACK: "FIXME: This causes tests to fail" (godox)
269251
internal/gitlabnet/personalaccesstoken/client_test.go:30:5: go-require: do not use require in http handlers (testifylint)
270252
internal/sshd/gssapi_unsupported.go:11:1: exported: exported function NewGSSAPIServer should have comment or be unexported (revive)
271253
internal/sshd/gssapi_unsupported.go:19:6: exported: exported type OSGSSAPIServer should have comment or be unexported (revive)

0 commit comments

Comments
 (0)