-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit.go
75 lines (70 loc) · 2.34 KB
/
commit.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
69
70
71
72
73
74
75
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() {
commitCommand.Flags().StringSliceP("workspace", "w", []string{}, "the name of the workspace(s) to commit in")
commitCommand.Flags().StringSliceP("tag", "t", []string{}, "the tags to filter the repositories by")
commitCommand.Flags().StringP("message", "m", "", "the message to commit with")
commitCommand.MarkFlagRequired("message")
root.AddCommand(commitCommand)
}
var commitCommand = &cobra.Command{
Use: "commit",
Short: "Commit the changes for each repository in the workspace.",
Long: "Commit the changes for each repository in the workspace.",
Run: func(cmd *cobra.Command, args []string) {
setup, err := Setup("workspace.commit", "", util.GetArg[string](cmd, "config"))
if err != nil {
multilog.Fatal("workspace.commit", "failed to setup", map[string]interface{}{
"error": err,
})
}
workspaces, err := setup.Config.GetWorkspaces(util.GetArg[[]string](cmd, "workspace"))
if err != nil {
multilog.Fatal("workspace.commit", "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()
result, errs := repositories.Commit(repositories.CommitArgs{
Workspace: setup.Workspace,
Repository: &repo,
Message: util.GetArg[string](cmd, "message"),
})
if err != nil {
multilog.Error(workspace.Name, fmt.Sprintf("failed to commit in %s", repo.Name), map[string]interface{}{
"workspace": setup.Workspace.Name,
"path": setup.Workspace.Path,
"errors": errs,
})
}
if len(*result.Messages) > 0 {
for _, msg := range *result.Messages {
multilog.Info(workspace.Name, fmt.Sprintf("committed %s in %s", msg, repo.Name), map[string]interface{}{
"change": msg,
"repo": repo.Name,
})
}
} else {
multilog.Info(workspace.Name, fmt.Sprintf("no pending changes in %s", repo.Name), map[string]interface{}{
"repo": repo.Name,
})
}
}()
}
}
wg.Wait()
},
}