fix provisioning
This commit is contained in:
parent
f14bdb39d1
commit
90dc1bd963
5 changed files with 28 additions and 2 deletions
|
|
@ -19,6 +19,7 @@ func loadConfig() (Config, error) {
|
|||
AuthHeaderEmail: getenv("AUTH_HEADER_EMAIL", "X-authentik-email"),
|
||||
ForgejoBaseURL: strings.TrimRight(getenv("FORGEJO_BASE_URL", ""), "/"),
|
||||
ForgejoToken: getenv("FORGEJO_TOKEN", ""),
|
||||
ForgejoGitUsername: getenv("FORGEJO_GIT_USERNAME", "oauth2"),
|
||||
ForgejoOrg: getenv("FORGEJO_ORG", ""),
|
||||
DBProvisionAdminURL: getenv("DB_PROVISION_ADMIN_URL", ""),
|
||||
DBProvisionEnabled: getenvBool("DB_PROVISION_ENABLED", true),
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ type Config struct {
|
|||
AuthHeaderEmail string
|
||||
ForgejoBaseURL string
|
||||
ForgejoToken string
|
||||
ForgejoGitUsername string
|
||||
ForgejoOrg string
|
||||
DBProvisionAdminURL string
|
||||
DBProvisionEnabled bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue