-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull.go
64 lines (60 loc) · 1.92 KB
/
pull.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
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"sync"
"github.com/mateothegreat/go-multilog/multilog"
"github.com/polyrepopro/api/repositories"
"github.com/polyrepopro/polyrepo/util"
"github.com/spf13/cobra"
)
func init() {
pullCommand.Flags().StringSliceP("workspace", "w", []string{}, "the name of the workspace(s) to commit in")
pullCommand.Flags().StringSliceP("tag", "t", []string{}, "the tags to filter the repositories by")
root.AddCommand(pullCommand)
}
var pullCommand = &cobra.Command{
Use: "pull",
Short: "pull the latest changes for each repository in the workspace",
Long: "pull the latest changes for each repository in the workspace",
Run: func(cmd *cobra.Command, args []string) {
setup, err := Setup("workspace.pull", "", util.GetArg[string](cmd, "config"))
if err != nil {
multilog.Fatal("workspace.pull", "failed to setup", map[string]interface{}{
"error": err,
})
}
workspaces, err := setup.Config.GetWorkspaces(util.GetArg[[]string](cmd, "workspace"))
if err != nil {
multilog.Fatal("workspace.pull", "failed to get workspaces", map[string]interface{}{
"error": err,
})
}
wg := sync.WaitGroup{}
for _, workspace := range *workspaces {
repos := workspace.GetRepositories(util.GetArg[[]string](cmd, "tag"))
for _, repo := range *repos {
wg.Add(1)
go func() {
defer wg.Done()
err := repositories.Pull(repositories.PullArgs{
Workspace: setup.Workspace,
Repository: &repo,
})
if err != nil {
multilog.Error(workspace.Name, fmt.Sprintf("failed to pull in %s", repo.Name), map[string]interface{}{
"workspace": setup.Workspace.Name,
"path": setup.Workspace.Path,
"errors": err,
})
} else {
multilog.Info(workspace.Name, fmt.Sprintf("pulled in %s", repo.Name), map[string]interface{}{
"workspace": setup.Workspace.Name,
"path": setup.Workspace.Path,
})
}
}()
}
}
wg.Wait()
},
}