-
Notifications
You must be signed in to change notification settings - Fork 5
/
repo.go
52 lines (43 loc) · 1.05 KB
/
repo.go
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
package main
import (
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/extism/cli"
)
type repo struct {
Url string `json:"url"`
Category string `json:"category"`
}
func (r repo) path() string {
a, b := r.split()
return filepath.Join(Root, a, b)
}
func (r repo) split() (string, string) {
split := strings.Split(r.Url, "/")
userName := split[len(split)-2]
repoName := split[len(split)-1]
if strings.HasPrefix(r.Url, "git@") {
x := strings.Split(userName, ":")
userName = x[1]
}
return userName, repoName
}
func (repo repo) clone() bool {
cli.Log("Initializing", repo.Url)
userName, repoName := repo.split()
os.MkdirAll(userName, 0o755)
full := filepath.Join(Root, userName, repoName)
cli.Print("Cloning", repo.Url, "to", full)
_, err := os.Stat(full)
if err == nil {
cli.Print("Warning:", repo.Url, "already exists")
return true
}
cli.Log("Running git clone", repo.Url, full)
if err := exec.Command("git", "clone", repo.Url, full).Run(); err != nil {
cli.Print("Warning: git clone", repo.Url, "failed:", err)
}
return false
}