prime8dev

prime8dev
git clone https://git.prime8.dev/prime8dev.git
Log | Files | Refs | README | LICENSE

commit 469d6f7c1a8b7ea8bf337b19fd3b2d9a80f84832
parent 97885e8ab27e03d3c2706fc7d81a08b241027b10
Author: Damian Myrda <damian@prime8.dev>
Date:   Tue, 31 Mar 2026 23:34:53 -0500

fix: rewrite GitLab metadata URLs via configurable base

Diffstat:
Minternal/external/gitlab.go | 41++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/internal/external/gitlab.go b/internal/external/gitlab.go @@ -5,6 +5,8 @@ import ( "fmt" "io" "net/http" + "net/url" + "os" "regexp" "strings" "time" @@ -17,6 +19,7 @@ import ( type GitLab struct { cache *cache.Cache httpClient *http.Client + apiBaseURL string } const gitLabMetadataTTL = 15 * time.Minute @@ -27,6 +30,7 @@ func NewGitLab(cache *cache.Cache) *GitLab { httpClient: &http.Client{ Timeout: 10 * time.Second, }, + apiBaseURL: strings.TrimSpace(os.Getenv("GITLAB_API_BASE_URL")), } } @@ -63,7 +67,9 @@ func (s *GitLab) RefreshMetadata(project config.Project) error { } func (s *GitLab) fetchFromGitLab(project config.Project) (*GitMetadata, error) { - req, err := http.NewRequest("GET", project.APIURL, nil) + apiURL := s.rewriteGitLabURL(project.APIURL) + + req, err := http.NewRequest("GET", apiURL, nil) if err != nil { return nil, err } @@ -98,6 +104,7 @@ func (s *GitLab) fetchFromGitLab(project config.Project) (*GitMetadata, error) { readme := "" if repo.ReadmeURL != "" { readmeURL := strings.Replace(utils.EnsureHTTPS(repo.ReadmeURL), "/-/blob/", "/-/raw/", 1) + readmeURL = s.rewriteGitLabURL(readmeURL) readme = s.fetchReadme(webURL, repo.DefaultBranch, readmeURL) } @@ -108,6 +115,38 @@ func (s *GitLab) fetchFromGitLab(project config.Project) (*GitMetadata, error) { }, nil } +func (s *GitLab) rewriteGitLabURL(rawURL string) string { + if s.apiBaseURL == "" { + return rawURL + } + + base, err := url.Parse(s.apiBaseURL) + if err != nil || base.Scheme == "" || base.Host == "" { + return rawURL + } + + target, err := url.Parse(rawURL) + if err != nil || target.Scheme == "" || target.Host == "" { + return rawURL + } + + targetOrigin := fmt.Sprintf("%s://%s", target.Scheme, target.Host) + suffix := strings.TrimPrefix(rawURL, targetOrigin) + if suffix == "" { + suffix = "/" + } + + basePath := strings.TrimSuffix(base.EscapedPath(), "/") + if basePath != "" { + if !strings.HasPrefix(suffix, "/") { + suffix = fmt.Sprintf("/%s", suffix) + } + suffix = fmt.Sprintf("%s%s", basePath, suffix) + } + + return fmt.Sprintf("%s://%s%s", base.Scheme, base.Host, suffix) +} + func (s *GitLab) fetchReadme(webURL, branch, readmeURL string) string { resp, err := s.httpClient.Get(readmeURL) if err != nil {