-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for external run dependencies. (#146)
* Add support for run external dependencies. Signed-off-by: Jakub Martin <[email protected]> * Refactor graphql schema. Signed-off-by: Jakub Martin <[email protected]> * Rename command. Signed-off-by: Jakub Martin <[email protected]> * Fixes. Signed-off-by: Jakub Martin <[email protected]> * Fix lint. Signed-off-by: Jakub Martin <[email protected]> * Fix lint Signed-off-by: Jakub Martin <[email protected]> * Fix lint? Signed-off-by: Jakub Martin <[email protected]> --------- Signed-off-by: Jakub Martin <[email protected]>
- Loading branch information
Showing
6 changed files
with
89 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
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,15 @@ | ||
package runexternaldependency | ||
|
||
import "github.com/urfave/cli/v2" | ||
|
||
var flagRunExternalDependencyID = &cli.StringFlag{ | ||
Name: "id", | ||
Usage: "[Required] ID of the external dependency", | ||
Required: true, | ||
} | ||
|
||
var flagStatus = &cli.StringFlag{ | ||
Name: "status", | ||
Usage: "[Required] Status of the external dependency (one of: 'finished', 'failed')", | ||
Required: true, | ||
} |
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,40 @@ | ||
package runexternaldependency | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/urfave/cli/v2" | ||
"golang.org/x/exp/slices" | ||
|
||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
) | ||
|
||
func markRunExternalDependencyAsCompleted(cliCtx *cli.Context) error { | ||
externalDependencyID := cliCtx.String(flagRunExternalDependencyID.Name) | ||
status := cliCtx.String(flagStatus.Name) | ||
|
||
var mutation struct { | ||
RunExternalDependencyMarkAsFinished struct { | ||
Phantom bool `graphql:"phantom"` | ||
} `graphql:"runExternalDependencyMarkAsCompleted(dependency: $dependency, status: $status)"` | ||
} | ||
|
||
if !slices.Contains([]string{"finished", "failed"}, status) { | ||
return fmt.Errorf("status must be one of: finished, failed") | ||
} | ||
|
||
type RunExternalDependencyStatus string | ||
variables := map[string]interface{}{ | ||
"dependency": externalDependencyID, | ||
"status": RunExternalDependencyStatus(strings.ToUpper(status)), | ||
} | ||
|
||
if err := authenticated.Client.Mutate(cliCtx.Context, &mutation, variables); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Marked external dependency as %s\n", status) | ||
|
||
return nil | ||
} |
30 changes: 30 additions & 0 deletions
30
internal/cmd/run_external_dependency/run_external_dependency.go
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,30 @@ | ||
package runexternaldependency | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/spacelift-io/spacectl/internal/cmd" | ||
"github.com/spacelift-io/spacectl/internal/cmd/authenticated" | ||
) | ||
|
||
// Command encapsulates the run external dependency command subtree. | ||
func Command() *cli.Command { | ||
return &cli.Command{ | ||
Name: "run-external-dependency", | ||
Usage: "Manage Spacelift Run external dependencies", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Category: "Run external dependency management", | ||
Name: "mark-completed", | ||
Usage: "Mark Run external dependency as completed", | ||
Flags: []cli.Flag{ | ||
flagRunExternalDependencyID, | ||
flagStatus, | ||
}, | ||
Action: markRunExternalDependencyAsCompleted, | ||
Before: authenticated.Ensure, | ||
ArgsUsage: cmd.EmptyArgsUsage, | ||
}, | ||
}, | ||
} | ||
} |
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