From 7b9218e2d5964a0508a354e589777779301a19ed Mon Sep 17 00:00:00 2001 From: Jakub Date: Fri, 17 Jan 2025 08:30:43 +0100 Subject: [PATCH] feat: added stack sync-commit subcommand Signed-off-by: Jakub --- internal/cmd/stack/stack.go | 11 +++++++++++ internal/cmd/stack/sync.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 internal/cmd/stack/sync.go diff --git a/internal/cmd/stack/stack.go b/internal/cmd/stack/stack.go index 002ac3f..f93b480 100644 --- a/internal/cmd/stack/stack.go +++ b/internal/cmd/stack/stack.go @@ -405,6 +405,17 @@ func Command() *cli.Command { Before: authenticated.Ensure, ArgsUsage: cmd.EmptyArgsUsage, }, + { + Category: "Stack management", + Name: "sync-commit", + Usage: "Syncs the tracked stack commit", + Flags: []cli.Flag{ + flagStackID, + }, + Action: syncCommit, + Before: authenticated.Ensure, + ArgsUsage: cmd.EmptyArgsUsage, + }, { Name: "resources", Usage: "Manage and view resources for stacks", diff --git a/internal/cmd/stack/sync.go b/internal/cmd/stack/sync.go new file mode 100644 index 0000000..64d35b3 --- /dev/null +++ b/internal/cmd/stack/sync.go @@ -0,0 +1,31 @@ +package stack + +import ( + "fmt" + + "github.com/shurcooL/graphql" + "github.com/spacelift-io/spacectl/internal/cmd/authenticated" + "github.com/urfave/cli/v2" +) + +func syncCommit(cliCtx *cli.Context) error { + stackID, err := getStackID(cliCtx) + if err != nil { + return err + } + + if nArgs := cliCtx.NArg(); nArgs != 0 { + return fmt.Errorf("expected zero arguments but got %d", nArgs) + } + + var mutation struct { + Stack struct { + ID string `graphql:"id"` + } `graphql:"stackSyncCommit(id: $stack)"` + } + variables := map[string]interface{}{ + "stack": graphql.ID(stackID), + } + + return authenticated.Client.Mutate(cliCtx.Context, &mutation, variables) +}