Skip to content

Commit 36b965c

Browse files
authored
fix: correct goreport detected errors (#26)
1 parent 97ef3d4 commit 36b965c

File tree

7 files changed

+69
-53
lines changed

7 files changed

+69
-53
lines changed

cmd/run.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,29 @@ import (
1313
)
1414

1515
const (
16-
GitCommitUser = "git-commit-user"
16+
// GitCommitUser is the user login used for commit changes
17+
GitCommitUser = "git-commit-user"
18+
// GitCommitEmail is the email used for commit changes
1719
GitCommitEmail = "git-commit-email"
18-
GitPassword = "git-password"
19-
GitBranch = "git-branch"
20-
GitRepoUrl = "git-repo-url"
21-
GitFile = "git-file"
22-
GitDir = "git-dir"
23-
24-
AppName = "app-name"
25-
SshPrivateKey = "ssh-private-key"
26-
DryRun = "dry-run"
27-
LogLevel = "logLevel"
20+
// GitPassword is the git password used for auth
21+
GitPassword = "git-password"
22+
// GitBranch is the branch of the git repository
23+
GitBranch = "git-branch"
24+
// GitRepoURL is the git repository url
25+
GitRepoURL = "git-repo-url"
26+
// GitFile is the file that is going to be changed
27+
GitFile = "git-file"
28+
// GitDir is the directory where the file to be changed is located
29+
GitDir = "git-dir"
30+
// AppName is the name of the helm application
31+
AppName = "app-name"
32+
// SSHPrivateKey is the location of the SSH private key used for auth
33+
SSHPrivateKey = "ssh-private-key"
34+
// DryRun is going to indicate if the changes are going to be committed or not
35+
DryRun = "dry-run"
36+
// LogLevel will indicate the log level
37+
LogLevel = "logLevel"
38+
// HelmKeyValues will be used for indicate the key and values to be changed in helm
2839
HelmKeyValues = "helm-key-values"
2940
)
3041

@@ -39,10 +50,10 @@ var runCmd = &cobra.Command{
3950
gitEmail, _ := cmd.Flags().GetString(GitCommitEmail)
4051
gitPass, _ := cmd.Flags().GetString(GitPassword)
4152
gitBranch, _ := cmd.Flags().GetString(GitBranch)
42-
gitRepoURL, _ := cmd.Flags().GetString(GitRepoUrl)
53+
gitRepoURL, _ := cmd.Flags().GetString(GitRepoURL)
4354
gitFile, _ := cmd.Flags().GetString(GitFile)
4455
gitDir, _ := cmd.Flags().GetString(GitDir)
45-
sshKey, _ := cmd.Flags().GetString(SshPrivateKey)
56+
sshKey, _ := cmd.Flags().GetString(SSHPrivateKey)
4657
appName, _ := cmd.Flags().GetString(AppName)
4758
logLevel, _ := cmd.Flags().GetString(LogLevel)
4859
dryRun, _ := cmd.Flags().GetBool(DryRun)
@@ -138,18 +149,18 @@ func init() {
138149
runCmd.Flags().String(GitCommitEmail, "", "E-Mail address to use for Git commits")
139150
runCmd.Flags().String(GitPassword, "", "Password for github user")
140151
runCmd.Flags().String(GitBranch, "develop", "branch")
141-
runCmd.Flags().String(GitRepoUrl, "", "git repo url")
152+
runCmd.Flags().String(GitRepoURL, "", "git repo url")
142153
runCmd.Flags().String(GitFile, "", "file eg. values.yaml")
143154
runCmd.Flags().String(GitDir, "", "file eg. /production/charts/")
144155
runCmd.Flags().String(AppName, "", "app name")
145-
runCmd.Flags().String(SshPrivateKey, "", "ssh private key")
156+
runCmd.Flags().String(SSHPrivateKey, "", "ssh private key")
146157
runCmd.Flags().Bool(DryRun, false, "run in dry-run mode. If set to true, do not perform any changes")
147158
runCmd.Flags().String(LogLevel, "info", "set the loglevel to one of trace|debug|info|warn|error")
148159
runCmd.Flags().StringToString(HelmKeyValues, nil, "helm key-values sets")
149160

150161
_ = runCmd.MarkFlagRequired(GitCommitUser)
151162
_ = runCmd.MarkFlagRequired(GitCommitEmail)
152-
_ = runCmd.MarkFlagRequired(GitRepoUrl)
163+
_ = runCmd.MarkFlagRequired(GitRepoURL)
153164
_ = runCmd.MarkFlagRequired(GitFile)
154165
_ = runCmd.MarkFlagRequired(HelmKeyValues)
155166
_ = runCmd.MarkFlagRequired(AppName)

internal/app/decoder/decoder_yaml.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package decoder
22

33
import (
4-
yaml "gopkg.in/yaml.v3"
54
"io"
5+
6+
yaml "gopkg.in/yaml.v3"
67
)
78

9+
// Decoder container the methods to Init a Decode a Decoder
810
type Decoder interface {
911
Init(reader io.Reader)
1012
Decode(node *yaml.Node) error
@@ -14,6 +16,7 @@ type yamlDecoder struct {
1416
decoder yaml.Decoder
1517
}
1618

19+
// NewYamlDecoder creates a new Decoder
1720
func NewYamlDecoder() Decoder {
1821
return &yamlDecoder{}
1922
}

internal/app/git/creds.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func isHTTPSURL(url string) bool {
5757

5858
// generateAuthForSSH generate the necessary public keys as auth for git repository using
5959
// the provided privateKeyFile containing a valid SSH private key
60-
func generateAuthForSSH(repoUrl string, userName string, privateKeyFile string, password string) (ssh.AuthMethod, error) {
60+
func generateAuthForSSH(repoURL string, userName string, privateKeyFile string, password string) (ssh.AuthMethod, error) {
6161
publicKeys, err := ssh.NewPublicKeysFromFile("git", privateKeyFile, password)
6262
if err != nil {
6363
log.Warnf("generate publickeys failed: %s\n", err.Error())
@@ -67,16 +67,16 @@ func generateAuthForSSH(repoUrl string, userName string, privateKeyFile string,
6767
}
6868

6969
// fromSSH generate a valid credentials using ssh key
70-
func (c Credentials) fromSSH(repoUrl string, password string) (ssh.AuthMethod, error) {
71-
if c.allowsSshAuth() {
72-
sshPublicKeys, err := generateAuthForSSH(repoUrl, c.Username, c.SSHPrivKey, password)
70+
func (c Credentials) fromSSH(repoURL string, password string) (ssh.AuthMethod, error) {
71+
if c.allowsSSHAuth() {
72+
sshPublicKeys, err := generateAuthForSSH(repoURL, c.Username, c.SSHPrivKey, password)
7373
if err != nil {
7474
return nil, err
7575
}
7676
return sshPublicKeys, nil
7777
}
7878

79-
return nil, sshPrivateKeyNotProvided(repoUrl)
79+
return nil, sshPrivateKeyNotProvided(repoURL)
8080
}
8181

8282
// generatAuthFor generate a valid credentials for go-git library using
@@ -100,7 +100,7 @@ func (c Credentials) from(repoURL string) (*http.BasicAuth, error) {
100100

101101
// allowSshAuth check if necessary attributes for generate an SSH
102102
// credentials are provided
103-
func (c Credentials) allowsSshAuth() bool {
103+
func (c Credentials) allowsSSHAuth() bool {
104104
return c.SSHPrivKey != ""
105105
}
106106

@@ -112,18 +112,18 @@ func (c Credentials) allowsAuth() bool {
112112

113113
// sshPrivateKeyNotProvided return an error used when sshPrivKey
114114
// is not provided for generate and SSH credentials
115-
func sshPrivateKeyNotProvided(repoUrl string) error {
116-
return fmt.Errorf("sshPrivKey not provided for authenticatication to repository %s", repoUrl)
115+
func sshPrivateKeyNotProvided(repoURL string) error {
116+
return fmt.Errorf("sshPrivKey not provided for authenticatication to repository %s", repoURL)
117117
}
118118

119119
// UserAndPasswordNotProvided return an error used when
120120
// username or password are not provided for generate and credentials
121-
func UserAndPasswordNotProvided(repoUrl string) error {
122-
return fmt.Errorf("no value provided for username and password for authentication to repository %s", repoUrl)
121+
func UserAndPasswordNotProvided(repoURL string) error {
122+
return fmt.Errorf("no value provided for username and password for authentication to repository %s", repoURL)
123123
}
124124

125125
// unknownRepositoryType return an error used when
126126
// the repository provided is not or SSH type
127-
func unknownRepositoryType(repoUrl string) error {
128-
return fmt.Errorf("unknown repository type for git repository URL %s", repoUrl)
127+
func unknownRepositoryType(repoURL string) error {
128+
return fmt.Errorf("unknown repository type for git repository URL %s", repoURL)
129129
}

internal/app/log/log.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import (
1818
logger "github.com/sirupsen/logrus"
1919
)
2020

21-
// LogContext contains a structured context for logging
22-
type LogContext struct {
21+
// Context contains a structured context for logging
22+
type Context struct {
2323
fields logger.Fields
2424
normalOut io.Writer
2525
errorOut io.Writer
2626
mutex sync.RWMutex
2727
}
2828

29-
// NewContext returns a LogContext with default settings
30-
func NewContext() *LogContext {
31-
var logctx LogContext
29+
// NewContext returns a Context with default settings
30+
func NewContext() *Context {
31+
var logctx Context
3232
logctx.fields = make(logger.Fields)
3333
logctx.normalOut = os.Stdout
3434
logctx.errorOut = os.Stderr
@@ -55,20 +55,20 @@ func SetLogLevel(logLevel string) error {
5555
}
5656

5757
// WithContext is an alias for NewContext
58-
func WithContext() *LogContext {
58+
func WithContext() *Context {
5959
return NewContext()
6060
}
6161

6262
// AddField adds a structured field to logctx
63-
func (logctx *LogContext) AddField(key string, value interface{}) *LogContext {
63+
func (logctx *Context) AddField(key string, value interface{}) *Context {
6464
logctx.mutex.Lock()
6565
logctx.fields[key] = value
6666
logctx.mutex.Unlock()
6767
return logctx
6868
}
6969

7070
// Tracef logs a debug message for logctx to stdout
71-
func (logctx *LogContext) Tracef(format string, args ...interface{}) {
71+
func (logctx *Context) Tracef(format string, args ...interface{}) {
7272
logger.SetOutput(logctx.normalOut)
7373
if logctx.fields != nil && len(logctx.fields) > 0 {
7474
logger.WithFields(logctx.fields).Tracef(format, args...)
@@ -78,7 +78,7 @@ func (logctx *LogContext) Tracef(format string, args ...interface{}) {
7878
}
7979

8080
// Debugf logs a debug message for logctx to stdout
81-
func (logctx *LogContext) Debugf(format string, args ...interface{}) {
81+
func (logctx *Context) Debugf(format string, args ...interface{}) {
8282
logger.SetOutput(logctx.normalOut)
8383
if logctx.fields != nil && len(logctx.fields) > 0 {
8484
logger.WithFields(logctx.fields).Debugf(format, args...)
@@ -88,7 +88,7 @@ func (logctx *LogContext) Debugf(format string, args ...interface{}) {
8888
}
8989

9090
// Infof logs an informational message for logctx to stdout
91-
func (logctx *LogContext) Infof(format string, args ...interface{}) {
91+
func (logctx *Context) Infof(format string, args ...interface{}) {
9292
logger.SetOutput(logctx.normalOut)
9393
if logctx.fields != nil && len(logctx.fields) > 0 {
9494
logger.WithFields(logctx.fields).Infof(format, args...)
@@ -98,7 +98,7 @@ func (logctx *LogContext) Infof(format string, args ...interface{}) {
9898
}
9999

100100
// Warnf logs a warning message for logctx to stdout
101-
func (logctx *LogContext) Warnf(format string, args ...interface{}) {
101+
func (logctx *Context) Warnf(format string, args ...interface{}) {
102102
logger.SetOutput(logctx.normalOut)
103103
if logctx.fields != nil && len(logctx.fields) > 0 {
104104
logger.WithFields(logctx.fields).Warnf(format, args...)
@@ -108,7 +108,7 @@ func (logctx *LogContext) Warnf(format string, args ...interface{}) {
108108
}
109109

110110
// Errorf logs a non-fatal error message for logctx to stdout
111-
func (logctx *LogContext) Errorf(format string, args ...interface{}) {
111+
func (logctx *Context) Errorf(format string, args ...interface{}) {
112112
logger.SetOutput(logctx.errorOut)
113113
if logctx.fields != nil && len(logctx.fields) > 0 {
114114
logger.WithFields(logctx.fields).Errorf(format, args...)
@@ -118,7 +118,7 @@ func (logctx *LogContext) Errorf(format string, args ...interface{}) {
118118
}
119119

120120
// Fatalf logs a fatal error message for logctx to stdout
121-
func (logctx *LogContext) Fatalf(format string, args ...interface{}) {
121+
func (logctx *Context) Fatalf(format string, args ...interface{}) {
122122
logger.SetOutput(logctx.errorOut)
123123
if logctx.fields != nil && len(logctx.fields) > 0 {
124124
logger.WithFields(logctx.fields).Fatalf(format, args...)
@@ -127,19 +127,19 @@ func (logctx *LogContext) Fatalf(format string, args ...interface{}) {
127127
}
128128
}
129129

130-
// Debugf logs a warning message without context to stdout
130+
// Tracef logs a trace message without context to stdout
131131
func Tracef(format string, args ...interface{}) {
132132
logCtx := NewContext()
133133
logCtx.Tracef(format, args...)
134134
}
135135

136-
// Debugf logs a warning message without context to stdout
136+
// Debugf logs a debug message without context to stdout
137137
func Debugf(format string, args ...interface{}) {
138138
logCtx := NewContext()
139139
logCtx.Debugf(format, args...)
140140
}
141141

142-
// Infof logs a warning message without context to stdout
142+
// Infof logs an informational message without context to stdout
143143
func Infof(format string, args ...interface{}) {
144144
logCtx := NewContext()
145145
logCtx.Infof(format, args...)

internal/app/updater/commit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func commitChangesLocked(cfg HelmUpdaterConfig, state *SyncIterationState) (*[]C
4343
}
4444

4545
// cloneRepository clones the git repository in a temporal directory.
46-
func cloneRepository(appName string, repoUrl string, authCreds transport.AuthMethod, tempRoot string) (*git.Repository, error) {
46+
func cloneRepository(appName string, repoURL string, authCreds transport.AuthMethod, tempRoot string) (*git.Repository, error) {
4747
logCtx := log.WithContext().AddField("application", appName)
48-
logCtx.Infof("Cloning git repository %s in temporal folder located in %s", repoUrl, tempRoot)
48+
logCtx.Infof("Cloning git repository %s in temporal folder located in %s", repoURL, tempRoot)
4949
r, err := git.PlainClone(tempRoot, false, &git.CloneOptions{
5050
Auth: authCreds,
51-
URL: repoUrl,
51+
URL: repoURL,
5252
Progress: os.Stdout,
5353
})
5454
if err != nil {
@@ -160,7 +160,7 @@ func configureCommitMessage(appName string, apps []ChangeEntry, helmUpdaterConfi
160160

161161
// createTempFileInDirectory creates a temporal directory where a copy of
162162
// the git repository is going to be stored.
163-
func CreateTempFileInDirectory(dirName string, applicationName string, repoURL string) (*string, error) {
163+
func createTempFileInDirectory(dirName string, applicationName string, repoURL string) (*string, error) {
164164
logCtx := log.WithContext().AddField("application", applicationName)
165165
tempRoot, err := ioutil.TempDir(os.TempDir(), dirName)
166166
if err != nil {
@@ -260,8 +260,8 @@ func fetchLatestChangesGitRepository(appName string, gitR git.Repository, creds
260260
}
261261

262262
// cloneGitRepositoryInBranch clone git repository with a specific branch checking if that branch exists already
263-
func cloneGitRepositoryInBranch(appName string, repoUrl string, creds transport.AuthMethod, tempRoot string, gitConfBranch string) (*git.Worktree, error) {
264-
gitR, err := cloneRepository(appName, repoUrl, creds, tempRoot)
263+
func cloneGitRepositoryInBranch(appName string, repoURL string, creds transport.AuthMethod, tempRoot string, gitConfBranch string) (*git.Worktree, error) {
264+
gitR, err := cloneRepository(appName, repoURL, creds, tempRoot)
265265
if err != nil {
266266
return nil, err
267267
}
@@ -291,7 +291,7 @@ func commitChangesGit(cfg HelmUpdaterConfig, write changeWriter) (*[]ChangeEntry
291291
return nil, fmt.Errorf("could not get creds for repo '%s': %v", cfg.AppName, err)
292292
}
293293

294-
tempRoot, err := CreateTempFileInDirectory(fmt.Sprintf("git-%s", cfg.AppName), cfg.AppName, cfg.GitConf.RepoURL)
294+
tempRoot, err := createTempFileInDirectory(fmt.Sprintf("git-%s", cfg.AppName), cfg.AppName, cfg.GitConf.RepoURL)
295295
if err != nil {
296296
return nil, err
297297
}

internal/app/utils/capture.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
)
77

8+
// CaptureStdout get the stdout output
89
func CaptureStdout(callback func()) (string, error) {
910
oldStdout := os.Stdout
1011
oldStderr := os.Stderr
@@ -30,6 +31,7 @@ func CaptureStdout(callback func()) (string, error) {
3031
return string(data), err
3132
}
3233

34+
// CaptureStderr get the error output
3335
func CaptureStderr(callback func()) (string, error) {
3436
oldStdout := os.Stdout
3537
oldStderr := os.Stderr

internal/app/utils/route_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
// UpdateApplication get the relative path folder based in number of relative paths indicated
9+
// GetRouteRelativePath get the relative path folder based in number of relative paths indicated
1010
func GetRouteRelativePath(numRelativePath int, relativePath string) (*string, error) {
1111
wd, err := os.Getwd()
1212
if err != nil {

0 commit comments

Comments
 (0)