Skip to content

Commit 79f05d0

Browse files
ashmckenzieArchish27
authored andcommitted
Merge branch '793-discover-lint' into 'main'
Lint fixes in healthcheck and discover package Closes #793 See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/1150 Merged-by: Ash McKenzie <[email protected]> Approved-by: Ash McKenzie <[email protected]> Reviewed-by: Ash McKenzie <[email protected]> Co-authored-by: Archish <[email protected]>
2 parents 580a3ba + 40689dd commit 79f05d0

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

internal/command/discover/discover.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package discover implements the "discover" command for fetching user info and displaying a welcome message.
12
package discover
23

34
import (
@@ -11,28 +12,32 @@ import (
1112
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/discover"
1213
)
1314

15+
type logDataKey struct{}
16+
17+
// Command struct encapsulates the necessary components for executing the Discover command.
1418
type Command struct {
1519
Config *config.Config
1620
Args *commandargs.Shell
1721
ReadWriter *readwriter.ReadWriter
1822
}
1923

24+
// Execute runs the discover command, fetching and displaying user information.
2025
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
2126
response, err := c.getUserInfo(ctx)
2227
if err != nil {
23-
return ctx, fmt.Errorf("Failed to get username: %v", err)
28+
return ctx, fmt.Errorf("Failed to get username: %v", err) //nolint:stylecheck // This is customer facing message
2429
}
2530

2631
logData := command.LogData{}
2732
if response.IsAnonymous() {
2833
logData.Username = "Anonymous"
29-
fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, Anonymous!\n")
34+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, Anonymous!\n")
3035
} else {
3136
logData.Username = response.Username
32-
fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, @%s!\n", response.Username)
37+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, @%s!\n", response.Username)
3338
}
3439

35-
ctxWithLogData := context.WithValue(ctx, "logData", logData)
40+
ctxWithLogData := context.WithValue(ctx, logDataKey{}, logData)
3641

3742
return ctxWithLogData, nil
3843
}

internal/command/discover/discover_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestExecute(t *testing.T) {
9090

9191
require.NoError(t, err)
9292
require.Equal(t, expectedOutput, buffer.String())
93-
require.Equal(t, expectedUsername, ctxWithLogData.Value("logData").(command.LogData).Username)
93+
require.Equal(t, expectedUsername, ctxWithLogData.Value(logDataKey{}).(command.LogData).Username)
9494
})
9595
}
9696
}

internal/command/healthcheck/healthcheck.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package healthcheck provides functionality to perform health checks.
12
package healthcheck
23

34
import (
@@ -14,24 +15,26 @@ var (
1415
redisMessage = "Redis available via internal API"
1516
)
1617

18+
// Command handles the execution of health checks.
1719
type Command struct {
1820
Config *config.Config
1921
ReadWriter *readwriter.ReadWriter
2022
}
2123

24+
// Execute performs the health check and outputs the result.
2225
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
2326
response, err := c.runCheck(ctx)
2427
if err != nil {
2528
return ctx, fmt.Errorf("%v: FAILED - %v", apiMessage, err)
2629
}
2730

28-
fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", apiMessage)
31+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", apiMessage)
2932

3033
if !response.Redis {
3134
return ctx, fmt.Errorf("%v: FAILED", redisMessage)
3235
}
3336

34-
fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", redisMessage)
37+
_, _ = fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", redisMessage)
3538
return ctx, nil
3639
}
3740

support/lint_last_known_acceptable.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,6 @@ internal/command/commandargs/shell.go:61:10: ST1005: error strings should not be
9090
internal/command/commandargs/shell.go:69:6: var-naming: var keyId should be keyID (revive)
9191
internal/command/commandargs/shell.go:98:6: var-naming: func tryParseKeyId should be tryParseKeyID (revive)
9292
internal/command/commandargs/shell.go:106:1: exported: exported method Shell.ParseCommand should have comment or be unexported (revive)
93-
internal/command/discover/discover.go:1:1: package-comments: should have a package comment (revive)
94-
internal/command/discover/discover.go:14:6: exported: exported type Command should have comment or be unexported (revive)
95-
internal/command/discover/discover.go:20:1: exported: exported method Command.Execute should have comment or be unexported (revive)
96-
internal/command/discover/discover.go:23:15: ST1005: error strings should not be capitalized (stylecheck)
97-
internal/command/discover/discover.go:29:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
98-
internal/command/discover/discover.go:32:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
99-
internal/command/discover/discover.go:35:20: context-keys-type: should not use basic type string as key in context.WithValue (revive)
100-
internal/command/healthcheck/healthcheck.go:1:1: package-comments: should have a package comment (revive)
101-
internal/command/healthcheck/healthcheck.go:17:6: exported: exported type Command should have comment or be unexported (revive)
102-
internal/command/healthcheck/healthcheck.go:22:1: exported: exported method Command.Execute should have comment or be unexported (revive)
103-
internal/command/healthcheck/healthcheck.go:28:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
104-
internal/command/healthcheck/healthcheck.go:34:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
10593
internal/command/lfsauthenticate/lfsauthenticate.go:87:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
10694
internal/command/lfsauthenticate/lfsauthenticate_test.go:76:5: go-require: do not use require in http handlers (testifylint)
10795
internal/command/lfsauthenticate/lfsauthenticate_test.go:79:5: go-require: do not use require in http handlers (testifylint)

0 commit comments

Comments
 (0)