mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 13:21:00 +00:00
fix(gitlab): hardcoded project id (#51)
The GitLab project ID was still hardcoded to my playground project on GitLab.com. This commit instead reads from the predefined GitLab CI/CD variable for the projects ID (`CI_PROJECT_ID`).
This commit is contained in:
parent
48d9ede0a2
commit
2fba5414e5
1 changed files with 10 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"log/slog"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/blang/semver/v4"
|
||||
|
|
@ -25,6 +26,7 @@ const (
|
|||
PRStateMerged = "merged"
|
||||
PRStateEventClose = "close"
|
||||
EnvAPIToken = "GITLAB_TOKEN" // nolint:gosec // Not actually a hardcoded credential
|
||||
EnvProjectID = "CI_PROJECT_ID"
|
||||
)
|
||||
|
||||
type GitLab struct {
|
||||
|
|
@ -390,14 +392,17 @@ func gitlabMRToReleasePullRequest(pr *gitlab.MergeRequest) *releasepr.ReleasePul
|
|||
}
|
||||
}
|
||||
|
||||
func (g *Options) autodiscover() {
|
||||
func (g *Options) autodiscover(log *slog.Logger) {
|
||||
// Read settings from GitLab-CI env vars
|
||||
if apiToken := os.Getenv(EnvAPIToken); apiToken != "" {
|
||||
g.APIToken = apiToken
|
||||
}
|
||||
|
||||
// TODO: Replace hardcode project-id with a better alternative
|
||||
g.ProjectID = 60698565
|
||||
if projectID := os.Getenv(EnvProjectID); projectID != "" {
|
||||
var err error
|
||||
g.ProjectID, err = strconv.ParseInt(projectID, 10, 64)
|
||||
log.Error("failed to parse environment variable as integer", "env.name", EnvProjectID, "env.value", projectID, "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
|
|
@ -405,14 +410,14 @@ type Options struct {
|
|||
|
||||
Path string
|
||||
Repo string
|
||||
ProjectID int
|
||||
ProjectID int64
|
||||
|
||||
APIToken string
|
||||
}
|
||||
|
||||
func New(log *slog.Logger, options *Options) (*GitLab, error) {
|
||||
log = log.With("forge", "gitlab")
|
||||
options.autodiscover()
|
||||
options.autodiscover(log)
|
||||
|
||||
client, err := gitlab.NewClient(options.APIToken)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue