Skip to content

Commit

Permalink
fix: Allow specify job token as token in config
Browse files Browse the repository at this point in the history
  • Loading branch information
asmfreak authored Jul 23, 2024
1 parent 096eca3 commit e16b58b
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions pkg/provider/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,32 @@ func (repo *GitLabRepository) Init(config map[string]string) error {
token := config["token"]
if token == "" {
token = os.Getenv("GITLAB_TOKEN")
ci_job_token := os.Getenv("CI_JOB_TOKEN")
if token == "" {
if ci_job_token == "" {
return errors.New("gitlab token missing")
}
token = ci_job_token
}
ciJobToken := os.Getenv("CI_JOB_TOKEN")
if token == "" {
if ciJobToken == "" {
return errors.New("gitlab token missing")
}
// use the same strategy as goreleaser
if token == ci_job_token {
repo.useJobToken = true
if os.Getenv("GIT_STRATEGY") == "none" {
return errors.New("can not use job token with sparse-checkout repository")
}
repo.localRepo = &GitProvider.Repository{}
err := repo.localRepo.Init(map[string]string{
"remote_name": "origin",
"git_path": os.Getenv("CI_PROJECT_DIR"),
"log_order": config["log_order"],
})
if err != nil {
return errors.New("failed to initialize local git repository: " + err.Error())
}
token = ciJobToken
}
// use the same strategy as goreleaser
if token == ciJobToken {
repo.useJobToken = true
if os.Getenv("GIT_STRATEGY") == "none" {
return errors.New("can not use job token with sparse-checkout repository")
}
repo.localRepo = &GitProvider.Repository{}
err := repo.localRepo.Init(map[string]string{
"remote_name": "origin",
"git_path": os.Getenv("CI_PROJECT_DIR"),
"log_order": config["log_order"],
})
if err != nil {
return errors.New("failed to initialize local git repository: " + err.Error())
}
}

Check failure on line 65 in pkg/provider/gitlab.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)

Check failure on line 66 in pkg/provider/gitlab.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
branch := config["gitlab_branch"]
if branch == "" {
branch = os.Getenv("CI_COMMIT_BRANCH")
Expand Down

0 comments on commit e16b58b

Please sign in to comment.