Skip to content

Commit

Permalink
feat(cdsctl): Add a flag to resynchronize workflow from command line #…
Browse files Browse the repository at this point in the history
…2469 (#3684)

close #2469
Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj authored and yesnault committed Dec 4, 2018
1 parent d6426ec commit 6cc85a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cli/cdsctl/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,20 @@ var workflowRunManualCmd = cli.Command{
Usage: "Open web browser on the workflow run",
Kind: reflect.Bool,
},
{
Name: "sync",
ShortHand: "s",
Usage: "Synchronise your pipelines with your last editions. Must be used with flag run-number",
Kind: reflect.Bool,
},
},
}

func workflowRunManualRun(v cli.Values) error {
if v.GetBool("sync") && v.GetString("run-number") == "" {
return fmt.Errorf("Could not use flag --sync without flag --run-number")
}

manual := sdk.WorkflowNodeRunManual{}
if strings.TrimSpace(v.GetString("data")) != "" {
data := map[string]interface{}{}
Expand Down Expand Up @@ -133,6 +143,12 @@ func workflowRunManualRun(v cli.Values) error {
}
}

if v.GetBool("sync") {
if _, err := client.WorkflowRunResync(v[_ProjectKey], v[_WorkflowName], runNumber); err != nil {
return fmt.Errorf("Cannot resync your workflow run %d : %v", runNumber, err)
}
}

if v.GetString("node-name") != "" {
if runNumber <= 0 {
return fmt.Errorf("You can use flag node-name without flag run-number")
Expand Down
9 changes: 9 additions & 0 deletions sdk/cdsclient/client_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func (c *client) WorkflowRunGet(projectKey string, workflowName string, number i
return &run, nil
}

func (c *client) WorkflowRunResync(projectKey string, workflowName string, number int64) (*sdk.WorkflowRun, error) {
url := fmt.Sprintf("/project/%s/workflows/%s/runs/%d/resync", projectKey, workflowName, number)
var run sdk.WorkflowRun
if _, err := c.PostJSON(context.Background(), url, nil, &run); err != nil {
return nil, err
}
return &run, nil
}

func (c *client) WorkflowRunSearch(projectKey string, offset, limit int64, filters ...Filter) ([]sdk.WorkflowRun, error) {
if offset < 0 {
offset = 0
Expand Down
1 change: 1 addition & 0 deletions sdk/cdsclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ type WorkflowClient interface {
WorkflowGet(projectKey, name string) (*sdk.Workflow, error)
WorkflowDelete(projectKey string, workflowName string) error
WorkflowRunGet(projectKey string, workflowName string, number int64) (*sdk.WorkflowRun, error)
WorkflowRunResync(projectKey string, workflowName string, number int64) (*sdk.WorkflowRun, error)
WorkflowRunSearch(projectKey string, offset, limit int64, filter ...Filter) ([]sdk.WorkflowRun, error)
WorkflowRunList(projectKey string, workflowName string, offset, limit int64) ([]sdk.WorkflowRun, error)
WorkflowRunArtifacts(projectKey string, name string, number int64) ([]sdk.WorkflowNodeRunArtifact, error)
Expand Down

0 comments on commit 6cc85a5

Please sign in to comment.