-
Notifications
You must be signed in to change notification settings - Fork 3
feat: workflow list and trigger commands #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb893b7
feat: workflow list and trigger commands
adityachoudhari26 7865e05
reset client.gen.go to main
dacbd 7e7ce73
re generate files
dacbd 1b5ce05
Merge branch 'main' of github.com:ctrlplanedev/cli into ctrlc-workflo…
dacbd 601eb6b
improve parsing
dacbd 1568711
refactor GetWorkspaceID
dacbd 24743f3
nitpick
dacbd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
| package workflow | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ctrlplanedev/cli/internal/api" | ||
| "github.com/ctrlplanedev/cli/internal/cliutil" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func NewListCmd() *cobra.Command { | ||
| var limit int | ||
| var offset int | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List workflows", | ||
| Long: `List all workflows in the workspace.`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| apiURL := viper.GetString("url") | ||
| apiKey := viper.GetString("api-key") | ||
| workspace := viper.GetString("workspace") | ||
|
|
||
| client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create API client: %w", err) | ||
| } | ||
|
|
||
| workspaceID, err := client.GetWorkspaceID(cmd.Context(), workspace) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if limit < 0 { | ||
| return fmt.Errorf("invalid --limit %d, must be non-negative", limit) | ||
| } | ||
| if offset < 0 { | ||
| return fmt.Errorf("invalid --offset %d, must be non-negative", offset) | ||
| } | ||
|
|
||
| params := &api.ListWorkflowsParams{} | ||
| if limit > 0 { | ||
| params.Limit = &limit | ||
| } | ||
| if offset > 0 { | ||
| params.Offset = &offset | ||
| } | ||
|
|
||
| resp, err := client.ListWorkflows(cmd.Context(), workspaceID.String(), params) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to list workflows: %w", err) | ||
| } | ||
|
|
||
| return cliutil.HandleResponseOutput(cmd, resp) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().IntVarP(&limit, "limit", "l", 50, "Limit the number of results") | ||
| cmd.Flags().IntVarP(&offset, "offset", "o", 0, "Offset the results") | ||
|
|
||
| return cmd | ||
| } | ||
This file contains hidden or 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,66 @@ | ||
| package workflow | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/ctrlplanedev/cli/internal/api" | ||
| "github.com/ctrlplanedev/cli/internal/cliutil" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func NewTriggerCmd() *cobra.Command { | ||
| var inputFlags []string | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "trigger <workflow-id>", | ||
| Short: "Trigger a workflow run", | ||
| Long: `Trigger a workflow run with the given inputs.`, | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| workflowID := args[0] | ||
|
|
||
| apiURL := viper.GetString("url") | ||
| apiKey := viper.GetString("api-key") | ||
| workspace := viper.GetString("workspace") | ||
|
|
||
| client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create API client: %w", err) | ||
| } | ||
|
|
||
| workspaceID, err := client.GetWorkspaceID(cmd.Context(), workspace) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| inputs := make(map[string]interface{}) | ||
| for _, input := range inputFlags { | ||
| key, value, found := strings.Cut(input, "=") | ||
| if !found { | ||
| return fmt.Errorf("invalid input format %q, expected key=value", input) | ||
| } | ||
| if key == "" { | ||
| return fmt.Errorf("invalid input format %q, empty key, expected key=value", input) | ||
| } | ||
| inputs[key] = value | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| body := api.CreateWorkflowRunJSONRequestBody{ | ||
| Inputs: inputs, | ||
| } | ||
|
|
||
| resp, err := client.CreateWorkflowRun(cmd.Context(), workspaceID.String(), workflowID, body) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to trigger workflow: %w", err) | ||
| } | ||
|
|
||
| return cliutil.HandleResponseOutput(cmd, resp) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringArrayVarP(&inputFlags, "input", "i", nil, "Input key=value pair (can be specified multiple times)") | ||
|
|
||
| return cmd | ||
| } | ||
This file contains hidden or 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,21 @@ | ||
| package workflow | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewWorkflowCmd() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "workflow <subcommand>", | ||
| Short: "Manage workflows", | ||
| Long: `Commands for listing and triggering workflows.`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return cmd.Help() | ||
| }, | ||
| } | ||
|
|
||
| cmd.AddCommand(NewListCmd()) | ||
| cmd.AddCommand(NewTriggerCmd()) | ||
|
|
||
| return cmd | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.