8000 fix(cli): workflow init and workflow status (#4323) · ovh/cds@ab0d0c6 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit ab0d0c6

Browse files
sguiheuxrichardlt
authored andcommitted
fix(cli): workflow init and workflow status (#4323)
1 parent 2226719 commit ab0d0c6

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

cli/cdsctl/workflow.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,5 @@ func workflowNodeForCurrentRepo(projectKey, workflowName string) (int64, error)
7373
return runs[0].Number, nil
7474
}
7575

76-
// If no run number, get the latest
77-
runs, err = client.WorkflowRunList(projectKey, workflowName, 0, 1)
78-
if err != nil {
79-
return 0, err
80-
}
81-
82-
if len(runs) != 1 {
83-
return 0, fmt.Errorf("workflow run not found")
84-
}
85-
86-
return runs[0].Number, nil
76+
return 0, nil
8777
}

cli/cdsctl/workflow_init.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ func workflowInitRun(c cli.Values) error {
490490
}
491491
}
492492

493+
workflowName := repoShortname
494+
if c.GetString("workflow") != "" {
495+
workflowName = c.GetString("workflow")
496+
}
497+
493498
if len(files) == 0 {
494499
repoManagerName, err := interactiveChooseVCSServer(proj, gitRepo)
495500
if err != nil {
@@ -515,11 +520,6 @@ func workflowInitRun(c cli.Values) error {
515520
return err
516521
}
517522

518-
workflowName := repoShortname
519-
if c.GetString("workflow") != "" {
520-
workflowName = c.GetString("workflow")
521-
}
522-
523523
wFilePath, err := craftWorkflowFile(workflowName, appName, pipName, dotCDS)
524524
if err != nil {
525525
return err
@@ -582,7 +582,7 @@ func workflowInitRun(c cli.Values) error {
582582
fmt.Printf("error: unable to setup git local config to store cds project key: %v\n", err)
583583
}
584584

585-
if err := gitRepo.LocalConfigSet("cds", "workflow", repoShortname); err != nil {
585+
if err := gitRepo.LocalConfigSet("cds", "workflow", workflowName); err != nil {
586586
fmt.Printf("error: unable to setup git local config to store cds workflow name: %v\n", err)
587587
}
588588

cli/cdsctl/workflow_status.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"strings"
99
"time"
1010

11-
dump "github.com/fsamin/go-dump"
12-
repo "github.com/fsamin/go-repo"
11+
"github.com/fsamin/go-dump"
12+
"github.com/fsamin/go-repo"
1313

1414
"github.com/ovh/cds/cli"
1515
"github.com/ovh/cds/sdk"
@@ -63,6 +63,17 @@ func workflowStatusRunWithTrack(v cli.Values) (interface{}, error) {
6363
time.Sleep(500 * time.Millisecond)
6464
}
6565

66+
if runNumber == 0 {
67+
runs, err := client.WorkflowRunList(v.GetString(_ProjectKey), v.GetString(_WorkflowName), 0, 1)
68+
if err != nil {
69+
return nil, err
70+
}
71+
if len(runs) != 1 {
72+
return nil, fmt.Errorf("workflow run not found")
73+
}
74+
runNumber = runs[0].Number
75+
}
76+
6677
run, err := client.WorkflowRunGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName), runNumber)
6778
if err != nil {
6879
return nil, err
@@ -136,6 +147,16 @@ func workflowStatusRunWithoutTrack(v cli.Values) (interface{}, error) {
136147
if errRunNumber != nil {
137148
return nil, errRunNumber
138149
}
150+
if runNumber == 0 {
151+
runs, err := client.WorkflowRunList(v.GetString(_ProjectKey), v.GetString(_WorkflowName), 0, 1)
152+
if err != nil {
153+
return nil, err
154+
}
155+
if len(runs) != 1 {
156+
return 0, fmt.Errorf("workflow run not found")
157+
}
158+
runNumber = runs[0].Number
159+
}
139160

140161
run, err := client.WorkflowRunGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName), runNumber)
141162
if err != nil {

0 commit comments

Comments
 (0)
0