-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Command to set current stack commit (#13)
- Loading branch information
1 parent
b06a203
commit 4df338d
Showing
3 changed files
with
56 additions
and
0 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
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,44 @@ | ||
package stack | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/shurcooL/graphql" | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
) | ||
|
||
func setCurrentCommit(cliCtx *cli.Context) error { | ||
var mutation struct { | ||
SetCurrentCommmit struct { | ||
TrackedCommit *struct { | ||
Hash string `graphql:"hash"` | ||
Message string `graphql:"message"` | ||
} `grapqhl:"trackedCommit"` | ||
} `graphql:"stackSetCurrentCommit(id: $stack, sha: $sha)"` | ||
} | ||
|
||
variables := map[string]interface{}{ | ||
"sha": graphql.String(cliCtx.String(flagRequiredCommitSHA.Name)), | ||
"stack": graphql.ID(stackID), | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
if err := authenticated.Client.Mutate(ctx, &mutation, variables); err != nil { | ||
return err | ||
} | ||
|
||
commit := mutation.SetCurrentCommmit.TrackedCommit | ||
if commit == nil { | ||
return errors.New("no tracked commit set on the Stack") | ||
} | ||
|
||
_, err := fmt.Fprintf(os.Stdout, "Current commit set to %q: (SHA %s)", commit.Message, commit.Hash) | ||
|
||
return err | ||
} |
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