-
Notifications
You must be signed in to change notification settings - Fork 6
add 'sync' command to sync remote split assignments with local schema #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4c93ad2
ce1fb99
b46c43b
fd208c9
ce19592
cddbe65
ed30cb1
038b2b6
5718199
de2bcdd
f1bdc53
9686b98
32d6c0f
54f9285
2b4d074
d3c9d06
f9845ce
d6cae25
f0e85c6
8c3ffdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 \ | ||
|
|
||
| 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() | ||
| } | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically we unmarshal both remote JSON and local YAML files. Then we match split names, and whatever split names match we assign the "weights" from the JSON to the YAML file. Then we write and marshal the YAML object back.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything that can be reused from (or incorporated into) the existing schema.go module?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah i'm kinda learning this project and go as i go... i've refactored it to use schema
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smudge i think it's at a good place now for another review |
||
|
|
||
| if err := schema.Write(localSchema); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.