As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit 79f05d05 authored by Ash McKenzie's avatar Ash McKenzie Committed by GitLab
Browse files

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: default avatarAsh McKenzie <amckenzie@gitlab.com>
Approved-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Reviewed-by: default avatarAsh McKenzie <amckenzie@gitlab.com>
Co-authored-by: default avatarArchish <archishthakkar@gmail.com>
parents 580a3ba2 40689ddc
No related branches found
No related tags found
No related merge requests found
// Package discover implements the "discover" command for fetching user info and displaying a welcome message.
package discover
import (
Loading
Loading
@@ -11,28 +12,32 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/gitlabnet/discover"
)
type logDataKey struct{}
// Command struct encapsulates the necessary components for executing the Discover command.
type Command struct {
Config *config.Config
Args *commandargs.Shell
ReadWriter *readwriter.ReadWriter
}
// Execute runs the discover command, fetching and displaying user information.
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
response, err := c.getUserInfo(ctx)
if err != nil {
return ctx, fmt.Errorf("Failed to get username: %v", err)
return ctx, fmt.Errorf("Failed to get username: %v", err) //nolint:stylecheck // This is customer facing message
}
logData := command.LogData{}
if response.IsAnonymous() {
logData.Username = "Anonymous"
fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, Anonymous!\n")
_, _ = fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, Anonymous!\n")
} else {
logData.Username = response.Username
fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, @%s!\n", response.Username)
_, _ = fmt.Fprintf(c.ReadWriter.Out, "Welcome to GitLab, @%s!\n", response.Username)
}
ctxWithLogData := context.WithValue(ctx, "logData", logData)
ctxWithLogData := context.WithValue(ctx, logDataKey{}, logData)
return ctxWithLogData, nil
}
Loading
Loading
Loading
Loading
@@ -90,7 +90,7 @@ func TestExecute(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expectedOutput, buffer.String())
require.Equal(t, expectedUsername, ctxWithLogData.Value("logData").(command.LogData).Username)
require.Equal(t, expectedUsername, ctxWithLogData.Value(logDataKey{}).(command.LogData).Username)
})
}
}
Loading
Loading
// Package healthcheck provides functionality to perform health checks.
package healthcheck
import (
Loading
Loading
@@ -14,24 +15,26 @@ var (
redisMessage = "Redis available via internal API"
)
// Command handles the execution of health checks.
type Command struct {
Config *config.Config
ReadWriter *readwriter.ReadWriter
}
// Execute performs the health check and outputs the result.
func (c *Command) Execute(ctx context.Context) (context.Context, error) {
response, err := c.runCheck(ctx)
if err != nil {
return ctx, fmt.Errorf("%v: FAILED - %v", apiMessage, err)
}
fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", apiMessage)
_, _ = fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", apiMessage)
if !response.Redis {
return ctx, fmt.Errorf("%v: FAILED", redisMessage)
}
fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", redisMessage)
_, _ = fmt.Fprintf(c.ReadWriter.Out, "%v: OK\n", redisMessage)
return ctx, nil
}
Loading
Loading
Loading
Loading
@@ -90,18 +90,6 @@ internal/command/commandargs/shell.go:61:10: ST1005: error strings should not be
internal/command/commandargs/shell.go:69:6: var-naming: var keyId should be keyID (revive)
internal/command/commandargs/shell.go:98:6: var-naming: func tryParseKeyId should be tryParseKeyID (revive)
internal/command/commandargs/shell.go:106:1: exported: exported method Shell.ParseCommand should have comment or be unexported (revive)
internal/command/discover/discover.go:1:1: package-comments: should have a package comment (revive)
internal/command/discover/discover.go:14:6: exported: exported type Command should have comment or be unexported (revive)
internal/command/discover/discover.go:20:1: exported: exported method Command.Execute should have comment or be unexported (revive)
internal/command/discover/discover.go:23:15: ST1005: error strings should not be capitalized (stylecheck)
internal/command/discover/discover.go:29:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:32:14: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/discover/discover.go:35:20: context-keys-type: should not use basic type string as key in context.WithValue (revive)
internal/command/healthcheck/healthcheck.go:1:1: package-comments: should have a package comment (revive)
internal/command/healthcheck/healthcheck.go:17:6: exported: exported type Command should have comment or be unexported (revive)
internal/command/healthcheck/healthcheck.go:22:1: exported: exported method Command.Execute should have comment or be unexported (revive)
internal/command/healthcheck/healthcheck.go:28:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/healthcheck/healthcheck.go:34:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/lfsauthenticate/lfsauthenticate.go:87:13: Error return value of `fmt.Fprintf` is not checked (errcheck)
internal/command/lfsauthenticate/lfsauthenticate_test.go:76:5: go-require: do not use require in http handlers (testifylint)
internal/command/lfsauthenticate/lfsauthenticate_test.go:79:5: go-require: do not use require in http handlers (testifylint)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment