Skip to content

Commit

Permalink
Fix go vet issues
Browse files Browse the repository at this point in the history
* After updating to go 1.22 there were some go vet issues
* This commit address those

Signed-off-by: Savita Ashture <[email protected]>
  • Loading branch information
savitaashture committed Aug 14, 2024
1 parent 9fb743d commit a1e40f2
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pkg/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (l listener) processRes(processEvent bool, provider provider.Interface, log
if err != nil {
errStr := fmt.Sprintf("got error while processing : %v", err)
logger.Error(errStr)
return nil, logger, fmt.Errorf(errStr)
return nil, logger, fmt.Errorf("%s", errStr)
}

if skipReason != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/matcher/annotation_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func MatchPipelinerunByAnnotation(ctx context.Context, logger *zap.SugaredLogger
return matchedPRs, nil
}

return nil, fmt.Errorf(buildAvailableMatchingAnnotationErr(event, pruns))
return nil, fmt.Errorf("%s", buildAvailableMatchingAnnotationErr(event, pruns))
}

func buildAvailableMatchingAnnotationErr(event *info.Event, pruns []*tektonv1.PipelineRun) string {
Expand Down
5 changes: 2 additions & 3 deletions pkg/pipelineascode/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/triggertype"
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider"
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider/github"

"github.com/openshift-pipelines/pipelines-as-code/pkg/resolve"
"github.com/openshift-pipelines/pipelines-as-code/pkg/secrets"
"github.com/openshift-pipelines/pipelines-as-code/pkg/templates"
Expand Down Expand Up @@ -155,7 +154,7 @@ func (p *PacRun) getPipelineRunsFromRepo(ctx context.Context, repo *v1alpha1.Rep
errmsg := err.Error()
errmsg = strings.ReplaceAll(errmsg, " error converting YAML to JSON: yaml:", "")
errmsg = strings.ReplaceAll(errmsg, "unmarshalling", "while parsing the")
return nil, fmt.Errorf(errmsg)
return nil, fmt.Errorf("%s", errmsg)
}
if err != nil || rawTemplates == "" {
msg := fmt.Sprintf("cannot locate templates in %s/ directory for this repository in %s", tektonDir, p.event.HeadBranch)
Expand All @@ -170,7 +169,7 @@ func (p *PacRun) getPipelineRunsFromRepo(ctx context.Context, repo *v1alpha1.Rep
// "raw" pipelinerun string
if msg, needUpdate := p.checkNeedUpdate(rawTemplates); needUpdate {
p.eventEmitter.EmitMessage(repo, zap.InfoLevel, "RepositoryNeedUpdate", msg)
return nil, fmt.Errorf(msg)
return nil, fmt.Errorf("%s", msg)
}

// This is for bitbucket
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/gitea/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (v *Provider) IsAllowed(ctx context.Context, event *info.Event) (bool, erro

// error with the policy reason if it was set
if policyReason != "" {
return false, fmt.Errorf(policyReason)
return false, fmt.Errorf("%s", policyReason)
}

// finally silently return false if no rules allowed this
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/github/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (v *Provider) IsAllowed(ctx context.Context, event *info.Event) (bool, erro

// error with the policy reason if it was set
if policyReason != "" {
return false, fmt.Errorf(policyReason)
return false, fmt.Errorf("%s", policyReason)
}

// finally silently return false if no rules allowed this
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (v *Provider) checkWebhookSecretValidity(ctx context.Context, cw clockwork.

if cw.Now().After(ts) {
errm := fmt.Sprintf("token has expired at %s", resp.TokenExpiration.Format(time.RFC1123))
return fmt.Errorf(errm)
return fmt.Errorf("%s", errm)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func TestGithubGetCommitInfo(t *testing.T) {
mux.HandleFunc(fmt.Sprintf("/repos/%s/%s/git/commits/%s",
tt.event.Organization, tt.event.Repository, tt.event.SHA), func(rw http.ResponseWriter, _ *http.Request) {
if tt.apiReply != "" {
fmt.Fprintf(rw, tt.apiReply)
fmt.Fprintf(rw, "%s", tt.apiReply)
return
}
fmt.Fprintf(rw, `{"html_url": "%s", "message": "%s"}`, tt.shaurl, tt.shatitle)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/github/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ func TestProviderGetExistingCheckRunID(t *testing.T) {
Client: client,
}
mux.HandleFunc(fmt.Sprintf("/repos/%v/%v/commits/%v/check-runs", event.Organization, event.Repository, event.SHA), func(w http.ResponseWriter, _ *http.Request) {
_, _ = fmt.Fprintf(w, tt.jsonret)
_, _ = fmt.Fprintf(w, "%s", tt.jsonret)
})

got, err := v.getExistingCheckRunID(ctx, event, provider.StatusOpts{
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func (v *Provider) GetFileInsideRepo(_ context.Context, runevent *info.Event, pa

func (v *Provider) GetCommitInfo(_ context.Context, runevent *info.Event) error {
if v.Client == nil {
return fmt.Errorf(noClientErrStr)
return fmt.Errorf("%s", noClientErrStr)
}

// if we don't have a SHA (ie: incoming-webhook) then get it from the branch
Expand Down
14 changes: 7 additions & 7 deletions pkg/reconciler/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import (
func (r *Reconciler) cleanupPipelineRuns(ctx context.Context, logger *zap.SugaredLogger, pacInfo *info.PacOpts, repo *v1alpha1.Repository, pr *tektonv1.PipelineRun) error {
keepMaxPipeline, ok := pr.Annotations[keys.MaxKeepRuns]
if ok {
max, err := strconv.Atoi(keepMaxPipeline)
maxVal, err := strconv.Atoi(keepMaxPipeline)
if err != nil {
return err
}
// if annotation value is more than max limit defined in config then use from config
if pacInfo.MaxKeepRunsUpperLimit > 0 && max > pacInfo.MaxKeepRunsUpperLimit {
logger.Infof("max-keep-run value in annotation (%v) is more than max-keep-run-upper-limit (%v), so using upper-limit", max, pacInfo.MaxKeepRunsUpperLimit)
max = pacInfo.MaxKeepRunsUpperLimit
if pacInfo.MaxKeepRunsUpperLimit > 0 && maxVal > pacInfo.MaxKeepRunsUpperLimit {
logger.Infof("max-keep-run value in annotation (%v) is more than max-keep-run-upper-limit (%v), so using upper-limit", maxVal, pacInfo.MaxKeepRunsUpperLimit)
maxVal = pacInfo.MaxKeepRunsUpperLimit
}
err = r.kinteract.CleanupPipelines(ctx, logger, repo, pr, max)
err = r.kinteract.CleanupPipelines(ctx, logger, repo, pr, maxVal)
if err != nil {
return err
}
Expand All @@ -32,9 +32,9 @@ func (r *Reconciler) cleanupPipelineRuns(ctx context.Context, logger *zap.Sugare

// if annotation is not defined but default max-keep-run value is defined then use that
if pacInfo.DefaultMaxKeepRuns > 0 {
max := pacInfo.DefaultMaxKeepRuns
maxVal := pacInfo.DefaultMaxKeepRuns

err := r.kinteract.CleanupPipelines(ctx, logger, repo, pr, max)
err := r.kinteract.CleanupPipelines(ctx, logger, repo, pr, maxVal)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/webhook/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package webhook

import (
"context"
"fmt"

"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
pac "github.com/openshift-pipelines/pipelines-as-code/pkg/generated/listers/pipelinesascode/v1alpha1"
Expand Down Expand Up @@ -34,7 +33,7 @@ func (ac *reconciler) Admit(_ context.Context, request *v1.AdmissionRequest) *v1
}

if exist {
return webhook.MakeErrorStatus(fmt.Sprintf("repository already exist with url: %s", repo.Spec.URL))
return webhook.MakeErrorStatus("repository already exists with URL: %s", repo.Spec.URL)
}

if repo.Spec.ConcurrencyLimit != nil && *repo.Spec.ConcurrencyLimit == 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestReconciler_Admit(t *testing.T) {
URL: "https://pac.test/already/installed",
}),
allowed: false,
result: "repository already exist with url: https://pac.test/already/installed",
result: "repository already exists with URL: https://pac.test/already/installed",
},
{
name: "allow as it is be update to existing repo",
Expand All @@ -57,7 +57,7 @@ func TestReconciler_Admit(t *testing.T) {
URL: "https://pac.test/already/installed",
}),
allowed: false,
result: "repository already exist with url: https://pac.test/already/installed",
result: "repository already exists with URL: https://pac.test/already/installed",
},
}
for _, tt := range tests {
Expand Down
6 changes: 3 additions & 3 deletions test/github_tkn_pac_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ spec:
runcnx.Clients.Log.Infof("Check if we have the repository set as succeeded")

counter := 0
max := 5
maxVal := 5
for {
output, err = cli2.ExecCommand(runcnx, tknpaclist.Root, "-n", targetNS)
if err == nil && strings.Contains(output, "Succeeded") {
runcnx.Clients.Log.Infof("We have the repository set as succeeded: %s", output)
break
}
counter++
if counter > max {
if counter > maxVal {
runcnx.Clients.Log.Errorf("We have waited for 5 minutes and we still do not have the repository set as succeeded: %s", output)
t.Fail()
break
}
runcnx.Clients.Log.Infof("Waiting 30s for tkn pac show success, %d/%d", counter, max)
runcnx.Clients.Log.Infof("Waiting 30s for tkn pac show success, %d/%d", counter, maxVal)
time.Sleep(30 * time.Second)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/repository_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ func TestRepositoryCreation(t *testing.T) {
assert.NilError(t, err)
err = repository.CreateRepo(ctx, targetNsNew, runcnx, repo)
assert.Assert(t, err != nil)
assert.Equal(t, err.Error(), "admission webhook \"validation.pipelinesascode.tekton.dev\" denied the request: repository already exist with url: https://pac.test/pac/app")
assert.Equal(t, err.Error(), "admission webhook \"validation.pipelinesascode.tekton.dev\" denied the request: repository already exists with URL: https://pac.test/pac/app")
}

0 comments on commit a1e40f2

Please sign in to comment.