-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.go
68 lines (63 loc) · 2.04 KB
/
push.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
65
66
67
68
package main
import (
"fmt"
"log"
"sync"
"github.com/mateothegreat/go-multilog/multilog"
"github.com/polyrepopro/api/repositories"
"github.com/polyrepopro/polyrepo/util"
"github.com/spf13/cobra"
)
func init() {
pushCommand.Flags().StringP("workspace", "w", "", "the name of the workspace(s) to commit in")
pushCommand.Flags().StringSliceP("tag", "t", []string{}, "the tags to filter the repositories by")
root.AddCommand(pushCommand)
}
var pushCommand = &cobra.Command{
Use: "push",
Short: "push changes for each repository in the workspace",
Long: "push changes for each repository in the workspace",
Run: func(cmd *cobra.Command, args []string) {
workspace := cmd.Flag("workspace").Value.String()
log.Printf("pushCommand workspace: %s", workspace)
setup, err := Setup("workspace.push", util.GetArg[string](cmd, "workspace"), util.GetArg[string](cmd, "config"))
if err != nil {
multilog.Fatal("workspace.push", "failed to setup", map[string]interface{}{
"error": err,
})
}
workspaces, err := setup.Config.GetWorkspaces([]string{util.GetArg[string](cmd, "workspace")})
if err != nil {
multilog.Fatal("workspace.push", "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()
errs := repositories.Push(repositories.PushArgs{
Workspace: setup.Workspace,
Repository: &repo,
})
if err != nil {
multilog.Error(workspace.Name, fmt.Sprintf("failed to push in %s", repo.Name), map[string]interface{}{
"workspace": setup.Workspace.Name,
"path": setup.Workspace.Path,
"errors": errs,
})
} else {
multilog.Info(workspace.Name, fmt.Sprintf("pushed in %s", repo.Name), map[string]interface{}{
"workspace": setup.Workspace.Name,
"path": setup.Workspace.Path,
})
}
}()
}
}
wg.Wait()
},
}