fix provisioning
This commit is contained in:
parent
f14bdb39d1
commit
90dc1bd963
5 changed files with 28 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
|
@ -117,13 +118,14 @@ func (a *App) buildProjectBinary(p Project) error {
|
|||
|
||||
func (a *App) syncProjectRepoFromMain(p Project, projectDir string) error {
|
||||
repoDir := filepath.Join(projectDir, "repo")
|
||||
repoCloneURL := a.repoURLForGitAuth(p.RepoURL)
|
||||
if _, err := os.Stat(repoDir); os.IsNotExist(err) {
|
||||
if err := runCmd("git", "clone", "--branch", "main", "--single-branch", p.RepoURL, repoDir); err != nil {
|
||||
if err := runCmd("git", "clone", "--branch", "main", "--single-branch", repoCloneURL, repoDir); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := runCmd("git", "-C", repoDir, "remote", "set-url", "origin", p.RepoURL); err != nil {
|
||||
if err := runCmd("git", "-C", repoDir, "remote", "set-url", "origin", repoCloneURL); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := runCmd("git", "-C", repoDir, "fetch", "origin", "main", "--prune"); err != nil {
|
||||
|
|
@ -134,3 +136,23 @@ func (a *App) syncProjectRepoFromMain(p Project, projectDir string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) repoURLForGitAuth(repoURL string) string {
|
||||
if repoURL == "" || a.cfg.ForgejoBaseURL == "" || a.cfg.ForgejoToken == "" {
|
||||
return repoURL
|
||||
}
|
||||
ru, err := url.Parse(repoURL)
|
||||
if err != nil || ru.Scheme != "https" {
|
||||
return repoURL
|
||||
}
|
||||
fu, err := url.Parse(a.cfg.ForgejoBaseURL)
|
||||
if err != nil {
|
||||
return repoURL
|
||||
}
|
||||
if !strings.EqualFold(ru.Hostname(), fu.Hostname()) {
|
||||
return repoURL
|
||||
}
|
||||
u := *ru
|
||||
u.User = url.UserPassword(a.cfg.ForgejoGitUsername, a.cfg.ForgejoToken)
|
||||
return u.String()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue