-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'sync' command to sync remote split assignments with local schema (…
…#64) Sometimes we want to sync our local TestTrack assignments with the weights in the production environment. Creating a TestTrack CLI command to easily take all the assignments from remote json split registry and assign them to local yaml assignment file.
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
SHELL = /bin/sh | ||
|
||
VERSION=1.5.0 | ||
VERSION=1.6.0 | ||
BUILD=`git rev-parse HEAD` | ||
|
||
LDFLAGS=-ldflags "-w -s \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.ToYAML() | ||
} | ||
} | ||
|
||
if err := schema.Write(localSchema); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters