mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-07 18:27:03 +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"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/blang/semver/v4"
|
"github.com/blang/semver/v4"
|
||||||
|
|
@ -25,6 +26,7 @@ const (
|
||||||
PRStateMerged = "merged"
|
PRStateMerged = "merged"
|
||||||
PRStateEventClose = "close"
|
PRStateEventClose = "close"
|
||||||
EnvAPIToken = "GITLAB_TOKEN" // nolint:gosec // Not actually a hardcoded credential
|
EnvAPIToken = "GITLAB_TOKEN" // nolint:gosec // Not actually a hardcoded credential
|
||||||
|
EnvProjectID = "CI_PROJECT_ID"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitLab struct {
|
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
|
// Read settings from GitLab-CI env vars
|
||||||
if apiToken := os.Getenv(EnvAPIToken); apiToken != "" {
|
if apiToken := os.Getenv(EnvAPIToken); apiToken != "" {
|
||||||
g.APIToken = apiToken
|
g.APIToken = apiToken
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Replace hardcode project-id with a better alternative
|
if projectID := os.Getenv(EnvProjectID); projectID != "" {
|
||||||
g.ProjectID = 60698565
|
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 {
|
type Options struct {
|
||||||
|
|
@ -405,14 +410,14 @@ type Options struct {
|
||||||
|
|
||||||
Path string
|
Path string
|
||||||
Repo string
|
Repo string
|
||||||
ProjectID int
|
ProjectID int64
|
||||||
|
|
||||||
APIToken string
|
APIToken string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(log *slog.Logger, options *Options) (*GitLab, error) {
|
func New(log *slog.Logger, options *Options) (*GitLab, error) {
|
||||||
log = log.With("forge", "gitlab")
|
log = log.With("forge", "gitlab")
|
||||||
options.autodiscover()
|
options.autodiscover(log)
|
||||||
|
|
||||||
client, err := gitlab.NewClient(options.APIToken)
|
client, err := gitlab.NewClient(options.APIToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue