Skip to content
Snippets Groups Projects
Commit 7276f320 authored by Christoph Witzko's avatar Christoph Witzko
Browse files

feat: also use environment for configuration

parent 3728e6e4
No related branches found
No related tags found
No related merge requests found
package provider
import (
"errors"
"fmt"
"os"
"regexp"
"github.com/Masterminds/semver/v3"
......@@ -18,11 +20,29 @@ type GitLabRepository struct {
func (repo *GitLabRepository) Init(config map[string]string) error {
gitlabBaseUrl := config["gitlabBaseUrl"]
if gitlabBaseUrl == "" {
gitlabBaseUrl = os.Getenv("CI_SERVER_URL")
}
token := config["token"]
if token == "" {
token = os.Getenv("GITLAB_TOKEN")
}
if token == "" {
return errors.New("gitlab token missing")
}
branch := config["gitlabBranch"]
if branch == "" {
branch = os.Getenv("CI_COMMIT_BRANCH")
}
projectID := config["gitlabProjectID"]
if projectID == "" {
return fmt.Errorf("project id is required")
projectID = os.Getenv("CI_PROJECT_ID")
}
if projectID == "" {
return fmt.Errorf("gitlabProjectID is required")
}
repo.projectID = projectID
......
......@@ -20,7 +20,7 @@ func TestNewGitlabRepository(t *testing.T) {
var repo *GitLabRepository
repo = &GitLabRepository{}
err := repo.Init(map[string]string{})
require.EqualError(err, "project id is required")
require.EqualError(err, "gitlab token missing")
repo = &GitLabRepository{}
err = repo.Init(map[string]string{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment