diff --git a/src/internal/agent/hooks/flux.go b/src/internal/agent/hooks/flux.go index 599762afce..d9854aa6cb 100644 --- a/src/internal/agent/hooks/flux.go +++ b/src/internal/agent/hooks/flux.go @@ -81,7 +81,10 @@ func mutateGitRepo(r *v1.AdmissionRequest) (result *operations.Result, err error // Mutate the git URL if necessary if isCreate || (isUpdate && !isPatched) { // Mutate the git URL so that the hostname matches the hostname in the Zarf state - patchedURL = git.New(state.GitServer).MutateGitURLsInText(patchedURL) + patchedURL, err = git.New(state.GitServer).TransformURL(patchedURL) + if err != nil { + message.Warnf("Unable to transform the git url, using the original url we have: %s", patchedURL) + } message.Debugf("original git URL of (%s) got mutated to (%s)", src.Spec.URL, patchedURL) } diff --git a/src/internal/packager/git/push.go b/src/internal/packager/git/push.go index 7e84964a8e..9e93922a12 100644 --- a/src/internal/packager/git/push.go +++ b/src/internal/packager/git/push.go @@ -76,7 +76,7 @@ func (g *Git) prepRepoForPush() (*git.Repository, error) { } remoteURL := remote.Config().URLs[0] - targetURL, err := g.transformURL(remoteURL) + targetURL, err := g.TransformURL(remoteURL) if err != nil { return nil, fmt.Errorf("unable to transform the git url: %w", err) } diff --git a/src/internal/packager/git/url.go b/src/internal/packager/git/url.go index 662f504efa..d66f6e829b 100644 --- a/src/internal/packager/git/url.go +++ b/src/internal/packager/git/url.go @@ -19,10 +19,9 @@ var gitURLRegex = regexp.MustCompile(`^(?P[a-z]+:\/\/)(?P.+?)\/ func (g *Git) MutateGitURLsInText(text string) string { extractPathRegex := regexp.MustCompilePOSIX(`https?://[^/]+/(.*\.git)`) output := extractPathRegex.ReplaceAllStringFunc(text, func(match string) string { - output, err := g.transformURL(match) + output, err := g.TransformURL(match) if err != nil { message.Warnf("Unable to transform the git url, using the original url we have: %s", match) - output = match } return output }) @@ -52,10 +51,11 @@ func (g *Git) TransformURLtoRepoName(url string) (string, error) { return newRepoName, nil } -func (g *Git) transformURL(url string) (string, error) { +// TransformURL takes a git url and returns a Zarf-compatible url. +func (g *Git) TransformURL(url string) (string, error) { repoName, err := g.TransformURLtoRepoName(url) if err != nil { - return "", err + return url, err } output := fmt.Sprintf("%s/%s/%s", g.Server.Address, g.Server.PushUsername, repoName) message.Debugf("Rewrite git URL: %s -> %s", url, output)