asf
This commit is contained in:
parent
07522043b4
commit
22c2f68c2a
3 changed files with 30 additions and 11 deletions
|
|
@ -457,12 +457,26 @@ func printCLIProject(action string, p Project) {
|
|||
}
|
||||
if p.RepoURL != "" {
|
||||
fmt.Printf("repo_url=%s\n", p.RepoURL)
|
||||
fmt.Printf("clone_url=%s\n", normalizeCloneURL(p.RepoURL))
|
||||
}
|
||||
if p.WebhookURL != "" {
|
||||
fmt.Printf("webhook_url=%s\n", p.WebhookURL)
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeCloneURL(repoURL string) string {
|
||||
u := strings.TrimSpace(repoURL)
|
||||
if u == "" {
|
||||
return ""
|
||||
}
|
||||
if strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://") {
|
||||
if !strings.HasSuffix(strings.ToLower(u), ".git") {
|
||||
return u + ".git"
|
||||
}
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
func cliStatePath() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil || home == "" {
|
||||
|
|
|
|||
|
|
@ -110,10 +110,24 @@ func (a *App) provisionProject(ctx context.Context, p *Project) error {
|
|||
}
|
||||
repoURL, err := a.createForgejoRepo(ctx, p.Slug, p.Description, p.RepoPrivate)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "status=409") {
|
||||
owner := strings.TrimSpace(a.cfg.ForgejoOrg)
|
||||
if owner == "" {
|
||||
owner = p.UserID
|
||||
}
|
||||
repoURL = strings.TrimRight(a.cfg.ForgejoBaseURL, "/") + "/" + owner + "/" + p.Slug
|
||||
} else {
|
||||
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
||||
p.ProvisionState = "failed"
|
||||
p.ProvisionError = err.Error()
|
||||
return err
|
||||
}
|
||||
}
|
||||
if strings.TrimSpace(repoURL) == "" {
|
||||
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
||||
p.ProvisionState = "failed"
|
||||
p.ProvisionError = err.Error()
|
||||
return err
|
||||
return errors.New("forgejo repo url is empty after provisioning")
|
||||
}
|
||||
p.RepoURL = repoURL
|
||||
if _, err := a.db.ExecContext(ctx, `UPDATE projects SET repo_url=$1 WHERE id=$2`, repoURL, p.ID); err != nil {
|
||||
|
|
@ -129,15 +143,6 @@ func (a *App) provisionProject(ctx context.Context, p *Project) error {
|
|||
p.ProvisionError = err.Error()
|
||||
return err
|
||||
}
|
||||
if p.RepoURL != "" {
|
||||
if err := a.buildProjectBinary(*p); err != nil {
|
||||
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
||||
p.ProvisionState = "failed"
|
||||
p.ProvisionError = err.Error()
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.renderSystemdForProject(ctx, *p); err != nil {
|
||||
_ = a.updateProvisioningState(ctx, p.ID, "failed", err.Error())
|
||||
p.ProvisionState = "failed"
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ WantedBy=default.target
|
|||
if err := runSystemctlUser(p.UnixUser, "daemon-reload"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := runSystemctlUser(p.UnixUser, "enable", "--now", p.ServiceName); err != nil {
|
||||
if err := runSystemctlUser(p.UnixUser, "enable", p.ServiceName); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue