From dcbe154b0d29a611eedf7944e56c2007a3ea70ad Mon Sep 17 00:00:00 2001 From: "Philip K. Warren" Date: Fri, 13 Jun 2025 09:29:53 -0500 Subject: [PATCH 1/3] Use GitHub client instead of http client Use the higher level GitHub client to make requests to ensure we correctly handle rate limit errors. --- cmd/download-plugins/main.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/download-plugins/main.go b/cmd/download-plugins/main.go index ca31de8df..a0859eb03 100644 --- a/cmd/download-plugins/main.go +++ b/cmd/download-plugins/main.go @@ -125,7 +125,7 @@ func run() error { return err } if !exists { - if err := downloadReleaseToDir(ctx, client.GitHub.Client(), pluginRelease, downloadDir); err != nil { + if err := downloadReleaseToDir(ctx, client.GitHub, pluginRelease, downloadDir); err != nil { return err } } @@ -166,7 +166,7 @@ func pluginExistsMatchingDigest(plugin release.PluginRelease, downloadDir string return digest == plugin.PluginZipDigest, nil } -func downloadReleaseToDir(ctx context.Context, client *http.Client, plugin release.PluginRelease, downloadDir string) error { +func downloadReleaseToDir(ctx context.Context, client *github.Client, plugin release.PluginRelease, downloadDir string) error { expectedDigest, err := parseDigest(plugin.PluginZipDigest) if err != nil { return fmt.Errorf("failed to parse digest for plugin: %w", err) @@ -184,11 +184,11 @@ func downloadReleaseToDir(ctx context.Context, client *http.Client, plugin relea } }() log.Printf("downloading: %v", plugin.URL) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, plugin.URL, nil) + req, err := client.NewRequest(http.MethodGet, plugin.URL, nil) if err != nil { return fmt.Errorf("failed to make HTTP request: %w", err) } - resp, err := client.Do(req) + resp, err := client.BareDo(ctx, req) if err != nil { return fmt.Errorf("failed to perform HTTP request: %w", err) } @@ -197,9 +197,6 @@ func downloadReleaseToDir(ctx context.Context, client *http.Client, plugin relea log.Printf("failed to close response: %v", err) } }() - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("failed to download %s: %s", plugin.URL, resp.Status) - } digest := sha256.New() w := io.MultiWriter(f, digest) if _, err := io.Copy(w, resp.Body); err != nil { From eef776c2f17964b9d8aa74a41e0d09a3c765fa1b Mon Sep 17 00:00:00 2001 From: "Philip K. Warren" Date: Fri, 13 Jun 2025 09:31:21 -0500 Subject: [PATCH 2/3] Bump golangci-lint --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 28d13de53..e7a5ab035 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ DOCKER_BUILD_EXTRA_ARGS ?= DOCKER_BUILDER := bufbuild-plugins DOCKER_CACHE_DIR ?= $(TMP)/dockercache GO ?= go -GOLANGCI_LINT_VERSION ?= v2.1.2 +GOLANGCI_LINT_VERSION ?= v2.1.6 GOLANGCI_LINT := $(TMP)/golangici-lint-$(GOLANGCI_LINT_VERSION) GO_TEST_FLAGS ?= -race -count=1 From 7fbfe084bc359d78433a3e2f0907914da4533968 Mon Sep 17 00:00:00 2001 From: "Philip K. Warren" Date: Fri, 13 Jun 2025 09:40:07 -0500 Subject: [PATCH 3/3] Switch to client.Do --- cmd/download-plugins/main.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cmd/download-plugins/main.go b/cmd/download-plugins/main.go index a0859eb03..967890128 100644 --- a/cmd/download-plugins/main.go +++ b/cmd/download-plugins/main.go @@ -188,20 +188,12 @@ func downloadReleaseToDir(ctx context.Context, client *github.Client, plugin rel if err != nil { return fmt.Errorf("failed to make HTTP request: %w", err) } - resp, err := client.BareDo(ctx, req) - if err != nil { - return fmt.Errorf("failed to perform HTTP request: %w", err) - } - defer func() { - if err := resp.Body.Close(); err != nil { - log.Printf("failed to close response: %v", err) - } - }() digest := sha256.New() w := io.MultiWriter(f, digest) - if _, err := io.Copy(w, resp.Body); err != nil { - return fmt.Errorf("failed to copy file: %w", err) + if _, err := client.Do(ctx, req, w); err != nil { + return fmt.Errorf("failed to perform HTTP request: %w", err) } + sha256Digest := hex.EncodeToString(digest.Sum(nil)) if sha256Digest != expectedDigest { return fmt.Errorf("checksum mismatch for %s: %q (expected) != %q (actual)", plugin.URL, expectedDigest, sha256Digest)