Skip to content

Commit

Permalink
Address linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Oded-B committed Jun 28, 2024
1 parent 1a0b2dc commit d22f30a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
19 changes: 12 additions & 7 deletions internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -146,8 +145,6 @@ func getEnv(key, fallback string) string {
}

func createArgoCdClients() (appClient application.ApplicationServiceClient, projClient projectpkg.ProjectServiceClient, settingClient settings.SettingsServiceClient, err error) {
var conn io.Closer

plaintext, _ := strconv.ParseBool(getEnv("ARGOCD_PLAINTEXT", "false"))
insecure, _ := strconv.ParseBool(getEnv("ARGOCD_INSECURE", "false"))

Expand All @@ -163,21 +160,23 @@ func createArgoCdClients() (appClient application.ApplicationServiceClient, proj
return nil, nil, nil, fmt.Errorf("Error creating ArgoCD API client: %v", err)
}

conn, appClient, err = client.NewApplicationClient()
appClntConn, appClient, err := client.NewApplicationClient()
if err != nil {
return nil, nil, nil, fmt.Errorf("Error creating ArgoCD app client: %v", err)
}
defer argoio.Close(appClntConn)

conn, projClient, err = client.NewProjectClient()
projClntConn, projClient, err := client.NewProjectClient()
if err != nil {
return nil, nil, nil, fmt.Errorf("Error creating ArgoCD project client: %v", err)
}
defer argoio.Close(projClntConn)

conn, settingClient, err = client.NewSettingsClient()
setClntConn, settingClient, err := client.NewSettingsClient()
if err != nil {
return nil, nil, nil, fmt.Errorf("Error creating ArgoCD settings client: %v", err)
}
defer argoio.Close(conn)
defer argoio.Close(setClntConn)
return
}

Expand Down Expand Up @@ -254,11 +253,17 @@ func SetArgoCDAppRevision(ctx context.Context, componentPath string, revision st
var foundApp *argoappv1.Application
var err error
appClient, _, _, err := createArgoCdClients()
if err != nil {
return fmt.Errorf("Error creating ArgoCD clients: %v", err)
}
if useSHALabelForArgoDicovery {
foundApp, err = findArgocdAppBySHA1Label(ctx, componentPath, repo, appClient)
} else {
foundApp, err = findArgocdAppByManifestPathAnnotation(ctx, componentPath, repo, appClient)
}
if err != nil {
return fmt.Errorf("Error finding ArgoCD application for component path %s: %v", componentPath, err)
}
if foundApp.Spec.Source.TargetRevision == revision {
log.Infof("App %s already has revision %s", foundApp.Name, revision)
return nil
Expand Down
5 changes: 0 additions & 5 deletions internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (pm prMetadata) serialize() (string, error) {
}

func (ghPrClientDetails *GhPrClientDetails) getPrMetadata(prBody string) {

prMetadataRegex := regexp.MustCompile(`<!--\|.*\|(.*)\|-->`)
serializedPrMetadata := prMetadataRegex.FindStringSubmatch(prBody)
if len(serializedPrMetadata) == 2 {
Expand All @@ -83,11 +82,9 @@ func (ghPrClientDetails *GhPrClientDetails) getPrMetadata(prBody string) {
}
}
}

}

func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPrClientDetails, mainGithubClientPair GhClientPair, approverGithubClientPair GhClientPair, ctx context.Context) {

ghPrClientDetails.getPrMetadata(eventPayload.PullRequest.GetBody())
// wasCommitStatusSet and the placement of SetCommitStatus in the flow is used to ensure an API call is only made where it needed
wasCommitStatusSet := false
Expand Down Expand Up @@ -161,7 +158,6 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr
}

if len(diffOfChangedComponents) > 0 {

diffCommentData := struct {
diffOfChangedComponents []argocd.DiffResult
hasSyncableComponens bool
Expand Down Expand Up @@ -414,7 +410,6 @@ func handleCommentPrEvent(ghPrClientDetails GhPrClientDetails, ce *github.IssueC
ghPrClientDetails.PrLogger.Errorf("Failed to sync ArgoCD app from branch: err=%s\n", err)
}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/githubapi/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ foobar`
t.Error("Expected isCheckedNow to be true")
}
if wasCheckedBefore {
t.Errorf("Expected wasCheckedBeforeto be false, actaully got %t", wasCheckedBefore)
t.Errorf("Expected wasCheckedBeforeto be false, got %t", wasCheckedBefore)
}
}

Expand Down

0 comments on commit d22f30a

Please sign in to comment.