-
Notifications
You must be signed in to change notification settings - Fork 6
/
cache.go
44 lines (40 loc) · 1.07 KB
/
cache.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
package templates
import (
"github.com/charmbracelet/log"
"github.com/geowa4/servicelogger/pkg/config"
"os"
"os/exec"
)
func cacheGitRepo(dirName, gitURL string) {
cloneTarget, err := config.GetCacheDir(dirName)
if err != nil {
log.Error("failed to load cache directory", "error", err)
return
}
log.Info("syncing", "repo", gitURL, "directory", cloneTarget)
_, statErr := os.Stat(cloneTarget)
var cmdErr error
if statErr != nil {
cmd := exec.Command("git", "clone", gitURL, cloneTarget)
cmdErr = cmd.Run()
if cmdErr != nil {
log.Error("failed to clone", "error", cmdErr)
return
}
} else {
cmd := exec.Command("git", "pull")
cmd.Dir = cloneTarget
cmdErr = cmd.Run()
if cmdErr != nil {
log.Error("failed to pull updates", "error", cmdErr)
return
}
}
log.Info("sync complete", "repo", gitURL, "directory", cloneTarget)
}
func CacheManagedNotifications() {
cacheGitRepo(managedNotificationsDirName, "git@github.com:openshift/managed-notifications.git")
}
func CacheOpsSOP() {
cacheGitRepo(opsSOPDirName, "git@github.com:openshift/ops-sop.git")
}