From b868ffdcdd1fce688fa7d5fdf31a23cb735c079d Mon Sep 17 00:00:00 2001 From: Jordan McClintock Date: Wed, 16 Oct 2024 21:32:59 +0000 Subject: [PATCH] feat: add token flag to gitlab release command --- src/cmd/release.go | 5 ++++- src/gitlab/release.go | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cmd/release.go b/src/cmd/release.go index 84d6e80..ecc1509 100644 --- a/src/cmd/release.go +++ b/src/cmd/release.go @@ -21,6 +21,8 @@ import ( "github.com/spf13/cobra" ) +var tokenVarName string + // gitlabCmd represents the gitlab command var gitlabCmd = &cobra.Command{ Use: "gitlab flavor", @@ -39,7 +41,7 @@ var gitlabCmd = &cobra.Command{ rootCmd.SilenceUsage = true - return gitlab.TagAndRelease(currentFlavor) + return gitlab.TagAndRelease(currentFlavor, tokenVarName) }, } @@ -52,4 +54,5 @@ var releaseCmd = &cobra.Command{ func init() { rootCmd.AddCommand(releaseCmd) releaseCmd.AddCommand(gitlabCmd) + gitlabCmd.Flags().StringVarP(&tokenVarName, "token-var-name", "t", "GITLAB_RELEASE_TOKEN", "Environment variable name for GitLab token") } diff --git a/src/gitlab/release.go b/src/gitlab/release.go index 7408e17..4dd474f 100644 --- a/src/gitlab/release.go +++ b/src/gitlab/release.go @@ -17,7 +17,7 @@ var openRepo = utils.OpenRepo var getPackageName = utils.GetPackageName -func TagAndRelease(flavor types.Flavor) error { +func TagAndRelease(flavor types.Flavor, tokenVarName string) error { repo, err := openRepo() if err != nil { return err @@ -47,7 +47,7 @@ func TagAndRelease(flavor types.Flavor) error { fmt.Printf("Default branch: %s\n", defaultBranch) // Create a new GitLab client - gitlabClient, err := newGitlabClient(os.Getenv("GITLAB_RELEASE_TOKEN"), gitlab.WithBaseURL(gitlabBaseURL)) + gitlabClient, err := newGitlabClient(os.Getenv(tokenVarName), gitlab.WithBaseURL(gitlabBaseURL)) if err != nil { return err }