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 package provider
import ( import (
"errors"
"fmt" "fmt"
"os"
"regexp" "regexp"
"github.com/Masterminds/semver/v3" "github.com/Masterminds/semver/v3"
...@@ -18,11 +20,29 @@ type GitLabRepository struct { ...@@ -18,11 +20,29 @@ type GitLabRepository struct {
func (repo *GitLabRepository) Init(config map[string]string) error { func (repo *GitLabRepository) Init(config map[string]string) error {
gitlabBaseUrl := config["gitlabBaseUrl"] gitlabBaseUrl := config["gitlabBaseUrl"]
if gitlabBaseUrl == "" {
gitlabBaseUrl = os.Getenv("CI_SERVER_URL")
}
token := config["token"] token := config["token"]
if token == "" {
token = os.Getenv("GITLAB_TOKEN")
}
if token == "" {
return errors.New("gitlab token missing")
}
branch := config["gitlabBranch"] branch := config["gitlabBranch"]
if branch == "" {
branch = os.Getenv("CI_COMMIT_BRANCH")
}
projectID := config["gitlabProjectID"] projectID := config["gitlabProjectID"]
if projectID == "" { 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 repo.projectID = projectID
......
...@@ -20,7 +20,7 @@ func TestNewGitlabRepository(t *testing.T) { ...@@ -20,7 +20,7 @@ func TestNewGitlabRepository(t *testing.T) {
var repo *GitLabRepository var repo *GitLabRepository
repo = &GitLabRepository{} repo = &GitLabRepository{}
err := repo.Init(map[string]string{}) err := repo.Init(map[string]string{})
require.EqualError(err, "project id is required") require.EqualError(err, "gitlab token missing")
repo = &GitLabRepository{} repo = &GitLabRepository{}
err = repo.Init(map[string]string{ 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