Repository: supabase/cli
Pull request #867 (2023-02-15 08:24:39)

chore: specify CLI version in API request

coveralls: ## Pull Request Test Coverage Report for [Build 4182412314](https://coveralls.io/builds/56955149)

* **4** of **4**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.02%**) to **62.46%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/56955149/badge)](https://coveralls.io/builds/56955149) |
| :-- | --: |
| Change from base [Build 4182391363](https://coveralls.io/builds/56955026): |  0.02% |
| Covered Lines: | 3707 |
| Relevant Lines: | 5935 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 7c27ffc3..01a7a46a 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -6,7 +6,7 @@ builds:
   - id: supabase
     binary: supabase
     ldflags:
-      - -X github.com/supabase/cli/cmd.version={{.Version}}
+      - -X github.com/supabase/cli/internal/utils.Version={{.Version}}
     targets:
       - darwin_amd64
       - darwin_arm64
diff --git a/cmd/root.go b/cmd/root.go
index cc8433aa..5e67d71c 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -34,13 +34,10 @@ func IsExperimental(cmd *cobra.Command) bool {
 }
 
 var (
-	// Passed from `-ldflags`: https://stackoverflow.com/q/11354518.
-	version string
-
 	rootCmd = &cobra.Command{
 		Use:     "supabase",
-		Short:   "Supabase CLI " + version,
-		Version: version,
+		Short:   "Supabase CLI " + utils.Version,
+		Version: utils.Version,
 		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
 			if IsExperimental(cmd) && !viper.GetBool("experimental") {
 				return errors.New("must set the --experimental flag to run this command")
diff --git a/internal/utils/api.go b/internal/utils/api.go
index e765666a..4fcff08f 100644
--- a/internal/utils/api.go
+++ b/internal/utils/api.go
@@ -191,6 +191,10 @@ func GetSupabase() *supabase.ClientWithResponses {
 		apiClient, err = supabase.NewClientWithResponses(
 			GetSupabaseAPIHost(),
 			supabase.WithRequestEditorFn(provider.Intercept),
+			supabase.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
+				req.Header.Set("User-Agent", "SupabaseCLI/"+Version)
+				return nil
+			}),
 		)
 		if err != nil {
 			log.Fatalln(err)
diff --git a/internal/utils/misc.go b/internal/utils/misc.go
index 49459b4b..6a1578d5 100644
--- a/internal/utils/misc.go
+++ b/internal/utils/misc.go
@@ -23,6 +23,9 @@ import (
 	"github.com/supabase/cli/internal/utils/credentials"
 )
 
+// Passed from `-ldflags`: https://stackoverflow.com/q/11354518.
+var Version string
+
 const (
 	Pg13Image = "supabase/postgres:13.3.0"
 	Pg14Image = "supabase/postgres:14.1.0.89"


Test patch:
diff --git a/test/secrets_test.go b/test/secrets_test.go
index 7aed4492..8b8c5f95 100644
--- a/test/secrets_test.go
+++ b/test/secrets_test.go
@@ -57,7 +57,7 @@ func (suite *SecretsTestSuite) TestList() {
 	require.Contains(suite.T(), suite.headers, http.Header{
 		"Authorization":   []string{fmt.Sprintf("Bearer %s", supabase.AccessToken)},
 		"Accept-Encoding": []string{"gzip"},
-		"User-Agent":      []string{"Go-http-client/1.1"},
+		"User-Agent":      []string{"SupabaseCLI/"},
 	})
 
 	contents, err := os.ReadFile(tmpfile.Name())