-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsync.go
More file actions
60 lines (50 loc) · 1.32 KB
/
sync.go
File metadata and controls
60 lines (50 loc) · 1.32 KB
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
package cmds
import (
"github.com/Betterment/testtrack-cli/schema"
"github.com/Betterment/testtrack-cli/serializers"
"github.com/Betterment/testtrack-cli/servers"
"github.com/Betterment/testtrack-cli/splits"
"github.com/spf13/cobra"
)
var syncDoc = `
Sync the local schema TestTrack assignments with the remote production TestTrack assignments.
`
func init() {
rootCmd.AddCommand(syncCommand)
}
var syncCommand = &cobra.Command{
Use: "sync",
Short: "Sync TestTrack assignments with production",
Long: syncDoc,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return Sync()
},
}
// Sync synchronizes the local schema TestTrack assignments with the remote production TestTrack assignments.
func Sync() error {
server, err := servers.New()
if err != nil {
return err
}
var splitRegistry serializers.RemoteRegistry
err = server.Get("api/v2/split_registry.json", &splitRegistry)
if err != nil {
return err
}
localSchema, err := schema.Read()
if err != nil {
return err
}
for ind, localSplit := range localSchema.Splits {
remoteSplit, exists := splitRegistry.Splits[localSplit.Name]
if exists {
remoteWeights := splits.Weights(remoteSplit.Weights)
localSchema.Splits[ind].Weights = remoteWeights
}
}
if err := schema.Write(localSchema); err != nil {
return err
}
return nil
}