diff --git a/pkg/provider/gitlab.go b/pkg/provider/gitlab.go index ed53fd542f91f592e278971ba9898dfde1ec191c..3e114606470a47be92032a4b0441d1224978ccae 100644 --- a/pkg/provider/gitlab.go +++ b/pkg/provider/gitlab.go @@ -1,7 +1,9 @@ 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 diff --git a/pkg/provider/gitlab_test.go b/pkg/provider/gitlab_test.go index 09faa49dfb5e0649069ce67162ccea77ad9bf7f4..11e883a6b3fc77fc7711c4f110a76df2644e9554 100644 --- a/pkg/provider/gitlab_test.go +++ b/pkg/provider/gitlab_test.go @@ -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{