8000 fix(cdsctl): change to GetCommand + add silent (#4226) · ovh/cds@cedba97 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit cedba97

Browse files
sguiheuxbnjjj
authored andcommitted
fix(cdsctl): change to GetCommand + add silent (#4226)
Co-Authored-By: sguiheux <steven.guiheux+github@gmail.com>
1 parent df095d6 commit cedba97

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

cli/cdsctl/workflow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func workflow() *cobra.Command {
3030
cli.NewCommand(workflowPullCmd, workflowPullRun, nil, withAllCommandModifiers()...),
3131
cli.NewCommand(workflowPushCmd, workflowPushRun, nil, withAllCommandModifiers()...),
3232
cli.NewCommand(workflowFavoriteCmd, workflowFavoriteRun, nil, withAllCommandModifiers()...),
33-
cli.NewCommand(workflowTransformAsCodeCmd, workflowTransformAsCodeRun, nil, withAllCommandModifiers()...),
33+
cli.NewGetCommand(workflowTransformAsCodeCmd, workflowTransformAsCodeRun, nil, withAllCommandModifiers()...),
3434
workflowArtifact(),
3535
workflowLog(),
3636
workflowAdvanced(),

cli/cdsctl/workflow_transform_as_code.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"fmt"
5+
"strconv"
6+
"strings"
57
"time"
68

79
"github.com/ovh/cds/cli"
@@ -15,38 +17,53 @@ var workflowTransformAsCodeCmd = cli.Command{
1517
{Name: _ProjectKey},
1618
{Name: _WorkflowName},
1719
},
20+
Flags: []cli.Flag{
21+
{Name: "silent", Type: cli.FlagBool},
22+
},
1823
}
1924

20-
func workflowTransformAsCodeRun(v cli.Values) error {
25+
func workflowTransformAsCodeRun(v cli.Values) (interface{}, error) {
2126
w, err := client.WorkflowGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName))
2227
if err != nil {
23-
return err
28+
return nil, err
2429
}
2530
if w.FromRepository != "" {
26-
fmt.Println("Workflow is already as code.")
27-
return nil
31+
return nil, sdk.ErrWorkflowAlreadyAsCode
2832
}
2933

3034
ope, err := client.WorkflowTransformAsCode(v.GetString(_ProjectKey), v.GetString(_WorkflowName))
3135
if err != nil {
32-
return err
36+
return nil, err
3337
}
3438

35-
fmt.Printf("CDS is pushing files on your repository. A pull request will be created, please wait...\n")
39+
if !v.GetBool("silent") {
40+
fmt.Println("CDS is pushing files on your repository. A pull request will be created, please wait...")
41+
}
3642
for {
3743
if err := client.WorkflowTransformAsCodeFollow(v.GetString(_ProjectKey), v.GetString(_WorkflowName), ope); err != nil {
38-
return err
44+
return nil, err
3945
}
4046
if ope.Status > sdk.OperationStatusProcessing {
4147
break
4248
}
4349
time.Sleep(1 * time.Second)
4450
}
51+
52+
urlSplitted := strings.Split(ope.Setup.Push.PRLink, "/")
53+
id, err := strconv.Atoi(urlSplitted[len(urlSplitted)-1])
54+
if err != nil {
55+
return nil, fmt.Errorf("cannot read id from pull request URL %s: %v", ope.Setup.Push.PRLink, err)
56+
}
57+
reponse := struct {
58+
URL string `cli:"url" json:"url"`
59+
ID int `cli:"id" json:"id"`
60+
}{
61+
URL: ope.Setup.Push.PRLink,
62+
ID: id,
63+
}
4564
switch ope.Status {
46-
case sdk.OperationStatusDone:
47-
fmt.Println(cli.Blue(ope.Setup.Push.PRLink))
4865
case sdk.OperationStatusError:
49-
return fmt.Errorf("cannot perform operation: %s", ope.Error)
66+
return nil, fmt.Errorf("cannot perform operation: %s", ope.Error)
5067
}
51-
return nil
68+
return reponse, nil
5269
}

0 commit comments

Comments
 (0)
0