Skip to content

Commit

Permalink
chore: fix linter execution and linting issues. (#2005)
Browse files Browse the repository at this point in the history
## What this PR does / why we need it:

The linter script was broken for a few months since I migrated to use
TMC scripts.
This fixes the linter and all linting issues.

## Which issue(s) this PR fixes:
none
## Special notes for your reviewer:

## Does this PR introduce a user-facing change?
```
no
```
  • Loading branch information
i4ki authored Dec 14, 2024
2 parents f85214e + cda816f commit 3730c61
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 120 deletions.
18 changes: 12 additions & 6 deletions cloud/deployment/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ type (
)

const (
OK Status = 1 << iota // OK status is used when the stack ran successfully.
Pending // Pending is a temporary status set when the deployment is about to commence.
Running // Running is a temporary status as part of an still ongoing deployment.
Failed // Failed status indicates the deployment of the stack failed.
Canceled // Canceled indicates the deployment of the stack was canceled.
Unrecognized // Unrecognized indicates any deployment status returned from TMC but not recognized by this client version.
// OK status is used when the stack ran successfully.
OK Status = 1 << iota
// Pending is a temporary status set when the deployment is about to commence.
Pending
// Running is a temporary status as part of an still ongoing deployment.
Running
// Failed status indicates the deployment of the stack failed.
Failed
// Canceled indicates the deployment of the stack was canceled.
Canceled
// Unrecognized indicates any deployment status returned from TMC but not recognized by this client version.
Unrecognized
lastStatus
)

Expand Down
18 changes: 12 additions & 6 deletions cloud/drift/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ type (
)

const (
OK Status = 1 << iota // OK status is used when the stack is not drifted.
Unknown // Unknown indicates the drift detection was not executed yet.
Drifted // Drifted status indicates the stack is drifted.
Failed // Failed status indicates the drift detection of the stack failed.
Unrecognized // Unrecognized indicates any drift status returned from TMC but not recognized by this client version.
lastStatus = Failed
// OK status is used when the stack is not drifted.
OK Status = 1 << iota
// Unknown indicates the drift detection was not executed yet.
Unknown
// Drifted status indicates the stack is drifted.
Drifted
// Failed status indicates the drift detection of the stack failed.
Failed
// Unrecognized indicates any drift status returned from TMC but not
// recognized by this client version.
Unrecognized
lastStatus = Failed
)

const (
Expand Down
7 changes: 0 additions & 7 deletions cloud/log_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,3 @@ func dropByte(data []byte, b byte) []byte {
}
return data
}

func min(a, b int) int {
if a < b {
return a
}
return b
}
14 changes: 9 additions & 5 deletions cloud/stack/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ type (
)

const (
OK Status = 1 << iota // OK status is used when the stack ran successfully.
Drifted // Drifted status is used when a stack definition is different from that of the current status.
Failed // Failed status indicates the deployment of the stack failed.
Unrecognized // Unrecognized indicates any status returned from TMC but still not recognized by the client.
lastStatus = Unrecognized
// OK status is used when the stack ran successfully.
OK Status = 1 << iota
// Drifted status is used when a stack definition is different from that of the current status.
Drifted
// Failed status indicates the deployment of the stack failed.
Failed
// Unrecognized indicates any status returned from TMC but still not recognized by the client.
Unrecognized
lastStatus = Unrecognized
)

const (
Expand Down
6 changes: 4 additions & 2 deletions cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,10 @@ type (

const (
unknownLogChannel LogChannel = iota
StdoutLogChannel // StdoutLogChannel is the stdout channel
StderrLogChannel // StderrLogChannel is the stderr channel
// StdoutLogChannel is the stdout channel
StdoutLogChannel
// StderrLogChannel is the stderr channel
StderrLogChannel
)

var (
Expand Down
3 changes: 3 additions & 0 deletions cmd/terramate/cli/cli_flags_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sort"
"strings"

// embed the help template
_ "embed"

"github.com/alecthomas/kong"
Expand Down Expand Up @@ -285,6 +286,8 @@ func writeTwoColumns(w *helpWriter, rows [][2]string) {

for _, row := range rows {
buf := bytes.NewBuffer(nil)

//nolint:all
doc.ToText(buf, row[1], "", strings.Repeat(" ", defaultIndent), w.width-leftSize-defaultColumnPadding)
lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")

Expand Down
2 changes: 0 additions & 2 deletions cmd/terramate/cli/gitlab/mr_smoke_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

//go:build gitlabci

package gitlab_test

import (
Expand Down
5 changes: 5 additions & 0 deletions cmd/terramate/cli/telemetry/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

// Package telemetry provides types and helpers for CLI telemetry.
package telemetry
1 change: 1 addition & 0 deletions cmd/terramate/cli/telemetry/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
)

// Endpoint returns the real telemetry endpoint.
func Endpoint() url.URL {
var u url.URL
u.Scheme = "https"
Expand Down
2 changes: 1 addition & 1 deletion cmd/terramate/cli/telemetry/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Command(cmd string) MessageOpt {
}
}

// Command sets the organization name.
// OrgName sets the organization name.
func OrgName(orgName string) MessageOpt {
return func(msg *Message) {
msg.OrgName = orgName
Expand Down
3 changes: 1 addition & 2 deletions cmd/terramate/cli/telemetry/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func TestRecordLifecycle(t *testing.T) {
Client: cl,
})

rec.WaitForSend()

assert.NoError(t, rec.WaitForSend())
assert.EqualInts(t, 1, len(tr.receivedReqs))

req := tr.receivedReqs[0]
Expand Down
28 changes: 21 additions & 7 deletions cmd/terramate/cli/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,38 @@ import (

"github.com/rs/zerolog/log"
"github.com/terramate-io/terramate"
"github.com/terramate-io/terramate/errors"
)

// PlatformType is the CI/CD platform.
type PlatformType int

const (
// PlatformLocal represents the local user environment.
PlatformLocal PlatformType = iota
// PlatformGithub is the GitHub Actions platform.
PlatformGithub
// PlatformGitlab is the GitLab CI platform.
PlatformGitlab
// PlatformGenericCI is a generic CI/CD platform.
PlatformGenericCI
)

// AuthType is the authentication method that was used.
type AuthType int

const (
// AuthNone represents no authentication.
AuthNone AuthType = iota
// AuthIDPGoogle represents Google IDP authentication.
AuthIDPGoogle
// AuthIDPGithub represents GitHub IDP authentication.
AuthIDPGithub
// AuthOIDCGithub represents GitHub OIDC authentication.
AuthOIDCGithub
// AuthOIDCGitlab represents GitLab OIDC authentication.
AuthOIDCGitlab
// AuthAPIKey represents API key authentication.
AuthAPIKey
)

Expand Down Expand Up @@ -68,20 +79,18 @@ func DetectPlatformFromEnv() PlatformType {
return PlatformGitlab
} else if isEnvVarSet("CI") {
return PlatformGenericCI
} else {
return PlatformLocal
}
return PlatformLocal
}

// DetectPlatformFromEnv detects AuthType based on environment variables and credentials.
// DetectAuthTypeFromEnv detects AuthType based on environment variables and credentials.
func DetectAuthTypeFromEnv(credpath string) AuthType {
if isEnvVarSet("ACTIONS_ID_TOKEN_REQUEST_TOKEN") {
return AuthOIDCGithub
} else if isEnvVarSet("TM_GITLAB_ID_TOKEN") {
return AuthOIDCGitlab
} else {
return getAuthProviderFromCredentials(credpath)
}
return getAuthProviderFromCredentials(credpath)
}

// ReadSignature parses a signature file. It works for checkpoint and analytics signatures as both use the same format.
Expand Down Expand Up @@ -218,8 +227,13 @@ func doSendMessage(msg *Message, p SendMessageParams) error {

req.Header.Set("User-Agent", "terramate/v"+terramate.Version())
req.Header.Set("Content-Type", "application/json")
_, err = p.Client.Do(req)
return err
errs := errors.L()
resp, err := p.Client.Do(req)
errs.Append(err)
if err == nil {
errs.Append(resp.Body.Close())
}
return errs.AsError()
}

// userMessage is suffixed to the uid file.
Expand Down
1 change: 1 addition & 0 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/terramate-io/terramate/errors"
)

// ListResult contains the result of listing a directory.
type ListResult struct {
TmFiles []string
TmGenFiles []string
Expand Down
7 changes: 0 additions & 7 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,6 @@ func (dirExprs HierarchicalExprs) Eval(ctx *eval.Context) EvalReport {
}
}

min := func(a, b int) int {
if a < b {
return a
}
return b
}

for accessPath := range pendingExprs {
found := true
accessPathPaths := accessPath.Path()
Expand Down
Loading

0 comments on commit 3730c61

Please sign in to comment.