diff --git a/internal/pkg/argocd/argocd.go b/internal/pkg/argocd/argocd.go index d279d2d0..461c6392 100644 --- a/internal/pkg/argocd/argocd.go +++ b/internal/pkg/argocd/argocd.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "os" + "strconv" cmdutil "github.com/argoproj/argo-cd/v2/cmd/util" "github.com/argoproj/argo-cd/v2/controller" @@ -263,10 +264,14 @@ func getEnv(key, fallback string) string { } func createArgoCdClient() (apiclient.Client, error) { - argoCdClientConfigPath := getEnv("ARGOCD_CLIENT_CONFIG_PATH", "argocd-client-config.yaml") + plaintext, _ := strconv.ParseBool(getEnv("ARGOCD_PLAINTEXT", "false")) + insecure, _ := strconv.ParseBool(getEnv("ARGOCD_INSECURE", "false")) opts := &apiclient.ClientOptions{ - ConfigPath: argoCdClientConfigPath, + ServerAddr: getEnv("ARGOCD_SERVER_ADDR", "localhost:8080"), + AuthToken: getEnv("ARGOCD_TOKEN", ""), + PlainText: plaintext, + Insecure: insecure, } clientset, err := apiclient.NewClient(opts) diff --git a/internal/pkg/githubapi/github.go b/internal/pkg/githubapi/github.go index 1ab93cf1..5abe893d 100644 --- a/internal/pkg/githubapi/github.go +++ b/internal/pkg/githubapi/github.go @@ -110,15 +110,19 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr if err != nil { prHandleError = err ghPrClientDetails.PrLogger.Errorf("Failed to get ArgoCD diff information: err=%s\n", err) - } else if noDiffsAndErrorsPR { - prLables, resp, err := ghPrClientDetails.GhClientPair.v3Client.Issues.AddLabelsToIssue(ghPrClientDetails.Ctx, ghPrClientDetails.Owner, ghPrClientDetails.Repo, *eventPayload.PullRequest.Number, []string{"noop"}) - prom.InstrumentGhCall(resp) - if err != nil { - ghPrClientDetails.PrLogger.Errorf("Could not label GitHub PR: err=%s\n%v\n", err, resp) - } else { - ghPrClientDetails.PrLogger.Debugf("PR %v labeled\n%+v", *eventPayload.PullRequest.Number, prLables) + } else { + ghPrClientDetails.PrLogger.Debugf("Successfully got ArgoCD diff\n") + if noDiffsAndErrorsPR { + ghPrClientDetails.PrLogger.Debugf("ArgoCD diff is empty, this PR will not change cluster state\n") + prLables, resp, err := ghPrClientDetails.GhClientPair.v3Client.Issues.AddLabelsToIssue(ghPrClientDetails.Ctx, ghPrClientDetails.Owner, ghPrClientDetails.Repo, *eventPayload.PullRequest.Number, []string{"noop"}) + prom.InstrumentGhCall(resp) + if err != nil { + ghPrClientDetails.PrLogger.Errorf("Could not label GitHub PR: err=%s\n%v\n", err, resp) + } else { + ghPrClientDetails.PrLogger.Debugf("PR %v labeled\n%+v", *eventPayload.PullRequest.Number, prLables) + } + // TODO Auto-merge PRs with no changes(optional) } - // TODO Auto-merge PRs with no changes(optional) } err, templateOutput := executeTemplate(ghPrClientDetails.PrLogger, "argoCdDiff", "argoCD-diff-pr-comment.gotmpl", diffOfChangedComponents)