-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add new commands for prioritizing/deprioritizing a run and flag…
… to prioritize local-preview (#243)
- Loading branch information
1 parent
deba5a0
commit 146bf07
Showing
8 changed files
with
147 additions
and
3 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ key.* | |
completions | ||
|
||
*.csv | ||
.idea |
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
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
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,39 @@ | ||
package stack | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func runDeprioritize(cliCtx *cli.Context) error { | ||
stackID, err := getStackID(cliCtx) | ||
if err != nil { | ||
return err | ||
} | ||
runID := cliCtx.String(flagRequiredRun.Name) | ||
|
||
mutation, err := setRunPriority(cliCtx, stackID, runID, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Run ID %q has been successfully deprioritized\n", runID) | ||
fmt.Println("The live run can be visited at", authenticated.Client.URL( | ||
"/stack/%s/run/%s", | ||
stackID, | ||
mutation.SetRunPriority.ID, | ||
)) | ||
|
||
if !cliCtx.Bool(flagTail.Name) { | ||
return nil | ||
} | ||
|
||
terminal, err := runLogsWithAction(cliCtx.Context, stackID, mutation.SetRunPriority.ID, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return terminal.Error() | ||
} |
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,62 @@ | ||
package stack | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/shurcooL/graphql" | ||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func runPrioritize(cliCtx *cli.Context) error { | ||
stackID, err := getStackID(cliCtx) | ||
if err != nil { | ||
return err | ||
} | ||
runID := cliCtx.String(flagRequiredRun.Name) | ||
|
||
mutation, err := setRunPriority(cliCtx, stackID, runID, true) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Run ID %q has been successfully prioritized\n", runID) | ||
fmt.Println("The live run can be visited at", authenticated.Client.URL( | ||
"/stack/%s/run/%s", | ||
stackID, | ||
mutation.SetRunPriority.ID, | ||
)) | ||
|
||
if !cliCtx.Bool(flagTail.Name) { | ||
return nil | ||
} | ||
|
||
terminal, err := runLogsWithAction(cliCtx.Context, stackID, mutation.SetRunPriority.ID, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return terminal.Error() | ||
} | ||
|
||
type setRunPriorityMutation struct { | ||
SetRunPriority struct { | ||
ID string `graphql:"id"` | ||
} `graphql:"runPrioritizeSet(stack: $stackId, run: $runId, prioritize: $prioritize)"` | ||
} | ||
|
||
func setRunPriority(cliCtx *cli.Context, stackID, runID string, prioritize bool) (setRunPriorityMutation, error) { | ||
var mutation setRunPriorityMutation | ||
|
||
variables := map[string]interface{}{ | ||
"stackId": graphql.ID(stackID), | ||
"runId": graphql.ID(runID), | ||
"prioritize": graphql.Boolean(prioritize), | ||
} | ||
|
||
if err := authenticated.Client.Mutate(cliCtx.Context, &mutation, variables); err != nil { | ||
return setRunPriorityMutation{}, err | ||
} | ||
|
||
return mutation, 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