Skip to content

Commit

Permalink
Add godot linter to harmonitze toplevel comments (woodpecker-ci#3650)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored May 13, 2024
1 parent 83eba29 commit 89e100c
Show file tree
Hide file tree
Showing 144 changed files with 302 additions and 302 deletions.
14 changes: 11 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ linters-settings:
- standard
- default
- prefix(go.woodpecker-ci.org/woodpecker)
gomnd:
mnd:
ignored-numbers:
- '0o600'
- '0o660'
Expand All @@ -121,6 +121,13 @@ linters-settings:
- strings.Split
- callerName
- securecookie.GenerateRandomKey
godot:
scope: toplevel
period: true
capital: true
exclude:
- '^\s*cSpell:'
- '^\s*TODO:'

linters:
disable-all: true
Expand Down Expand Up @@ -166,13 +173,14 @@ linters:
- contextcheck
- forcetypeassert
- gci
- gomnd
- mnd
- godot

issues:
exclude-rules:
- path: 'fixtures|cmd/agent/flags.go|cmd/server/flags.go|pipeline/backend/kubernetes/flags.go|_test.go'
linters:
- gomnd
- mnd

run:
timeout: 15m
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/golangci/golangci-lint
rev: v1.57.2
rev: v1.58.1
hooks:
- id: golangci-lint
- repo: https://github.com/igorshubovych/markdownlint-cli
Expand Down
2 changes: 1 addition & 1 deletion agent/rpc/auth_client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewAuthGrpcClient(conn *grpc.ClientConn, agentToken string, agentID int64)
}

func (c *AuthClient) Auth() (string, int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) //nolint: gomnd
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) //nolint:mnd
defer cancel()

req := &proto.AuthRequest{
Expand Down
8 changes: 4 additions & 4 deletions agent/rpc/auth_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"google.golang.org/grpc/metadata"
)

// AuthInterceptor is a client interceptor for authentication
// AuthInterceptor is a client interceptor for authentication.
type AuthInterceptor struct {
authClient *AuthClient
accessToken string
}

// NewAuthInterceptor returns a new auth interceptor
// NewAuthInterceptor returns a new auth interceptor.
func NewAuthInterceptor(
authClient *AuthClient,
refreshDuration time.Duration,
Expand All @@ -46,7 +46,7 @@ func NewAuthInterceptor(
return interceptor, nil
}

// Unary returns a client interceptor to authenticate unary RPC
// Unary returns a client interceptor to authenticate unary RPC.
func (interceptor *AuthInterceptor) Unary() grpc.UnaryClientInterceptor {
return func(
ctx context.Context,
Expand All @@ -60,7 +60,7 @@ func (interceptor *AuthInterceptor) Unary() grpc.UnaryClientInterceptor {
}
}

// Stream returns a client interceptor to authenticate stream RPC
// Stream returns a client interceptor to authenticate stream RPC.
func (interceptor *AuthInterceptor) Stream() grpc.StreamClientInterceptor {
return func(
ctx context.Context,
Expand Down
10 changes: 5 additions & 5 deletions agent/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/pipeline/rpc/proto"
)

// set grpc version on compile time to compare against server version response
// Set grpc version on compile time to compare against server version response.
const ClientGrpcVersion int32 = proto.Version

type client struct {
Expand All @@ -54,12 +54,12 @@ func (c *client) Close() error {
func (c *client) newBackOff() backoff.BackOff {
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = 0
b.MaxInterval = 10 * time.Second //nolint: gomnd
b.InitialInterval = 10 * time.Millisecond //nolint: gomnd
b.MaxInterval = 10 * time.Second //nolint:mnd
b.InitialInterval = 10 * time.Millisecond //nolint:mnd
return b
}

// Version returns the server- & grpc-version
// Version returns the server- & grpc-version.
func (c *client) Version(ctx context.Context) (*rpc.Version, error) {
res, err := c.client.Version(ctx, &proto.Empty{})
if err != nil {
Expand Down Expand Up @@ -242,7 +242,7 @@ func (c *client) Done(ctx context.Context, id string, state rpc.State) (err erro
return nil
}

// Extend extends the workflow deadline
// Extend extends the workflow deadline.
func (c *client) Extend(ctx context.Context, id string) (err error) {
retry := c.newBackOff()
req := new(proto.ExtendRequest)
Expand Down
2 changes: 0 additions & 2 deletions agent/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,10 @@ func (r *Runner) Run(runnerCtx context.Context) error { //nolint:contextcheck
return nil
}

// extract repository name from the configuration
func extractRepositoryName(config *backend.Config) string {
return config.Stages[0].Steps[0].Environment["CI_REPO"]
}

// extract pipeline number from the configuration
func extractPipelineNumber(config *backend.Config) string {
return config.Stages[0].Steps[0].Environment["CI_PIPELINE_NUMBER"]
}
2 changes: 1 addition & 1 deletion agent/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *Runner) createTracer(ctxmeta context.Context, logger zerolog.Logger, wo
StepUUID: state.Pipeline.Step.UUID,
Exited: state.Process.Exited,
ExitCode: state.Process.ExitCode,
Started: time.Now().Unix(), // TODO do not do this
Started: time.Now().Unix(), // TODO: do not do this
Finished: time.Now().Unix(),
}
if state.Process.Error != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var GlobalFlags = append([]cli.Flag{
}, logger.GlobalLoggerFlags...)

// FormatFlag return format flag with value set based on template
// if hidden value is set, flag will be hidden
// if hidden value is set, flag will be hidden.
func FormatFlag(tmpl string, hidden ...bool) *cli.StringFlag {
return &cli.StringFlag{
Name: "format",
Expand Down
2 changes: 1 addition & 1 deletion cli/cron/cron_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func cronList(c *cli.Context) error {
return nil
}

// template for pipeline list information
// tTemplate for pipeline list information.
var tmplCronList = "\x1b[33m{{ .Name }} \x1b[0m" + `
ID: {{ .ID }}
Branch: {{ .Branch }}
Expand Down
2 changes: 1 addition & 1 deletion cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func deploy(c *cli.Context) error {
return tmpl.Execute(os.Stdout, deploy)
}

// template for deployment information
// Template for deployment information.
var tmplDeployInfo = `Number: {{ .Number }}
Status: {{ .Status }}
Commit: {{ .Commit }}
Expand Down
2 changes: 1 addition & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func convertPathForWindows(path string) string {
base := filepath.VolumeName(path)

// Check if path is volume name like C:
//nolint: gomnd
//nolint:mnd
if len(base) == 2 {
path = strings.TrimPrefix(path, base)
base = strings.ToLower(strings.TrimSuffix(base, ":"))
Expand Down
2 changes: 1 addition & 1 deletion cli/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ func info(c *cli.Context) error {
return tmpl.Execute(os.Stdout, user)
}

// template for user information
// Template for user information.
var tmplInfo = `User: {{ .Login }}
Email: {{ .Email }}`
2 changes: 1 addition & 1 deletion cli/log/log_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func logPurge(c *cli.Context) (err error) {
return err
}

stepArg := c.Args().Get(2) //nolint: gomnd
stepArg := c.Args().Get(2) //nolint:mnd
// TODO: Add lookup by name: stepID, err := internal.ParseStep(client, repoID, stepIDOrName)
var stepID int64
if len(stepArg) != 0 {
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
)

//nolint:gomnd
//nolint:mnd
var pipelineListCmd = &cli.Command{
Name: "ls",
Usage: "show pipeline history",
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func pipelinePs(c *cli.Context) error {
return nil
}

// template for pipeline ps information
// Template for pipeline ps information.
var tmplPipelinePs = "\x1b[33mStep #{{ .PID }} \x1b[0m" + `
Step: {{ .Name }}
State: {{ .State }}
Expand Down
2 changes: 1 addition & 1 deletion cli/pipeline/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func pipelineQueue(c *cli.Context) error {
return nil
}

// template for pipeline list information
// Template for pipeline list information.
var tmplPipelineQueue = "\x1b[33m{{ .FullName }} #{{ .Number }} \x1b[0m" + `
Status: {{ .Status }}
Event: {{ .Event }}
Expand Down
2 changes: 1 addition & 1 deletion cli/registry/registry_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func registryList(c *cli.Context) error {
return nil
}

// template for registry list information
// Template for registry list information.
var tmplRegistryList = "\x1b[33m{{ .Address }} \x1b[0m" + `
Username: {{ .Username }}
Email: {{ .Email }}
Expand Down
2 changes: 1 addition & 1 deletion cli/repo/repo_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func repoInfo(c *cli.Context) error {
return tmpl.Execute(os.Stdout, repo)
}

// template for repo information
// tTemplate for repo information.
var tmplRepoInfo = `Owner: {{ .Owner }}
Repo: {{ .Name }}
URL: {{ .ForgeURL }}
Expand Down
2 changes: 1 addition & 1 deletion cli/repo/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ func repoList(c *cli.Context) error {
return nil
}

// template for repository list items
// Template for repository list items.
var tmplRepoList = "\x1b[33m{{ .FullName }}\x1b[0m (id: {{ .ID }}, forgeRemoteID: {{ .ForgeRemoteID }})"
2 changes: 1 addition & 1 deletion cli/secret/secret_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func secretList(c *cli.Context) error {
return nil
}

// template for secret list items
// Template for secret list items.
var tmplSecretList = "\x1b[33m{{ .Name }} \x1b[0m" + `
Events: {{ list .Events }}
{{- if .Images }}
Expand Down
2 changes: 1 addition & 1 deletion cli/user/user_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ func userInfo(c *cli.Context) error {
return tmpl.Execute(os.Stdout, user)
}

// template for user information
// Template for user information.
var tmplUserInfo = `User: {{ .Login }}
Email: {{ .Email }}`
2 changes: 1 addition & 1 deletion cli/user/user_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ func userList(c *cli.Context) error {
return nil
}

// template for user list items
// Template for user list items.
var tmplUserList = `{{ .Login }}`
2 changes: 1 addition & 1 deletion cmd/agent/core/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func run(c *cli.Context, backends []types.Backend) error {

agentToken := c.String("grpc-token")
authClient := agentRpc.NewAuthGrpcClient(authConn, agentToken, agentConfig.AgentID)
authInterceptor, err := agentRpc.NewAuthInterceptor(authClient, 30*time.Minute) //nolint: gomnd
authInterceptor, err := agentRpc.NewAuthInterceptor(authClient, 30*time.Minute) //nolint:mnd
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/core/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/urfave/cli/v2"
)

//nolint:gomnd
//nolint:mnd
var flags = []cli.Flag{
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_SERVER"},
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/core/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/version"
)

// the file implements some basic healthcheck logic based on the
// The file implements some basic healthcheck logic based on the
// following specification:
// https://github.com/mozilla-services/Dockerflow

Expand Down Expand Up @@ -74,7 +74,7 @@ type versionResp struct {
Source string `json:"source"`
}

// default statistics counter
// Default statistics counter.
var counter = &agent.State{
Metadata: map[string]agent.Info{},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/core/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package core
import (
"os"

// Load config from .env
// Load config from .env file.
_ "github.com/joho/godotenv/autoload"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
Expand Down
2 changes: 1 addition & 1 deletion cmd/server/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/version"
)

// generate docs/swagger.json via:
// Generate docs/swagger.json via:
//go:generate go run woodpecker_docs_gen.go swagger.go
//go:generate go run github.com/go-swagger/go-swagger/cmd/swagger@latest validate ../../docs/swagger.json

Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/common/script_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

// generateScriptPosix is a helper function that generates a step script
// for a linux container using the given
// for a linux container using the given.
func generateScriptPosix(commands []string) string {
var buf bytes.Buffer

Expand Down
6 changes: 3 additions & 3 deletions pipeline/backend/kubernetes/backend_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
backend "go.woodpecker-ci.org/woodpecker/v2/pipeline/backend/types"
)

// BackendOptions defines all the advanced options for the kubernetes backend
// BackendOptions defines all the advanced options for the kubernetes backend.
type BackendOptions struct {
Resources Resources `mapstructure:"resources"`
RuntimeClassName *string `mapstructure:"runtimeClassName"`
Expand All @@ -18,13 +18,13 @@ type BackendOptions struct {
SecurityContext *SecurityContext `mapstructure:"securityContext"`
}

// Resources defines two maps for kubernetes resource definitions
// Resources defines two maps for kubernetes resource definitions.
type Resources struct {
Requests map[string]string `mapstructure:"requests"`
Limits map[string]string `mapstructure:"limits"`
}

// Toleration defines Kubernetes toleration
// Toleration defines Kubernetes toleration.
type Toleration struct {
Key string `mapstructure:"key"`
Operator TolerationOperator `mapstructure:"operator"`
Expand Down
7 changes: 3 additions & 4 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
// To authenticate to GCP K8s clusters
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // To authenticate to GCP K8s clusters
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"

Expand All @@ -42,7 +41,7 @@ import (

const (
EngineName = "kubernetes"
// TODO 5 seconds is against best practice, k3s didn't work otherwise
// TODO: 5 seconds is against best practice, k3s didn't work otherwise
defaultResyncDuration = 5 * time.Second
)

Expand Down Expand Up @@ -268,7 +267,7 @@ func (e *kube) WaitStep(ctx context.Context, step *types.Step, taskUUID string)
si.Start(stop)
defer close(stop)

// TODO Cancel on ctx.Done
// TODO: Cancel on ctx.Done
<-finished

pod, err := e.client.CoreV1().Pods(e.config.Namespace).Get(ctx, podName, metav1.GetOptions{})
Expand Down
Loading

0 comments on commit 89e100c

Please sign in to comment.