summaryrefslogtreecommitdiff
path: root/internal/storage/seed.go
blob: 884292dd2eba645b094a07975a7be2cc52a5bbd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package storage

import (
	"os/exec"
	"strings"

	"github.com/thepeterstone/claudomator/internal/task"
)

// SeedProjects upserts the default project registry on startup.
func (s *DB) SeedProjects() error {
	projects := []*task.Project{
		{
			ID:           "claudomator",
			Name:         "claudomator",
			LocalPath:    "/workspace/claudomator",
			RemoteURL:    localBareRemote("/workspace/claudomator"),
			Type:         "web",
			DeployScript: "/workspace/claudomator/scripts/deploy",
		},
		{
			ID:        "nav",
			Name:      "nav",
			LocalPath: "/workspace/nav",
			RemoteURL: localBareRemote("/workspace/nav"),
			Type:      "android",
		},
		{
			ID:           "doot",
			Name:         "doot",
			LocalPath:    "/workspace/doot",
			RemoteURL:    localBareRemote("/workspace/doot"),
			Type:         "web",
			DeployScript: "/workspace/doot/scripts/deploy",
		},
	}
	for _, p := range projects {
		if err := s.UpsertProject(p); err != nil {
			return err
		}
	}
	return nil
}

// localBareRemote returns the URL of the "local" git remote for dir,
// falling back to dir itself if the remote is not configured.
func localBareRemote(dir string) string {
	out, err := exec.Command("git", "-C", dir, "remote", "get-url", "local").Output()
	if err == nil {
		if url := strings.TrimSpace(string(out)); url != "" {
			return url
		}
	}
	return dir
}