From 151c93dae98eb34bc1fdb3cd6ff7d1532497e1a3 Mon Sep 17 00:00:00 2001 From: Jordan McClintock Date: Wed, 16 Oct 2024 17:41:05 -0400 Subject: [PATCH] Gitlab-token-env-var (#18) --- README.md | 4 ++++ src/cmd/release.go | 5 ++++- src/gitlab/release.go | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e3b6342..0810206 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,10 @@ uds-releaser update-yaml uds-releaser release ``` +### Gitlab + +When running `uds-releaser release gitlab ` you are expected to have an environment variable set to a GitLab token that has write permissions for your current project. This defaults to `GITLAB_RELEASE_TOKEN` but can be changed with the `--token-var-name` flag. + ## Configuration UDS-Releaser can be configured using a YAML file named uds-releaser.yaml in your project's root directory. 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 }