-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdsctl): manage workflow label (#5028)
* feat(cdsctl): manage workflow label close #5023 Signed-off-by: Yvonnick Esnault <[email protected]>
- Loading branch information
Showing
12 changed files
with
225 additions
and
32 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,84 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/ovh/cds/cli" | ||
"github.com/ovh/cds/sdk/cdsclient" | ||
) | ||
|
||
var workflowLabelCmd = cli.Command{ | ||
Name: "label", | ||
Aliases: []string{"labels"}, | ||
Short: "Manage Workflow Label", | ||
} | ||
|
||
func workflowLabel() *cobra.Command { | ||
return cli.NewCommand(workflowLabelCmd, nil, []*cobra.Command{ | ||
cli.NewListCommand(workflowLabelListCmd, workflowLabelListRun, nil, withAllCommandModifiers()...), | ||
cli.NewCommand(workflowLabelAddCmd, workflowLabelAddRun, nil, withAllCommandModifiers()...), | ||
cli.NewCommand(workflowLabelDeleteCmd, workflowLabelDeleteRun, nil, withAllCommandModifiers()...), | ||
}) | ||
} | ||
|
||
var workflowLabelListCmd = cli.Command{ | ||
Name: "list", | ||
Short: "List labels of one workflow", | ||
Ctx: []cli.Arg{ | ||
{Name: _ProjectKey}, | ||
{Name: _WorkflowName}, | ||
}, | ||
} | ||
|
||
func workflowLabelListRun(v cli.Values) (cli.ListResult, error) { | ||
wf, err := client.WorkflowGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName), cdsclient.WithLabels()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return cli.AsListResult(wf.Labels), nil | ||
} | ||
|
||
var workflowLabelAddCmd = cli.Command{ | ||
Name: "add", | ||
Short: "Add label on one workflow", | ||
Ctx: []cli.Arg{ | ||
{Name: _ProjectKey}, | ||
{Name: _WorkflowName}, | ||
{Name: "label"}, | ||
}, | ||
} | ||
|
||
func workflowLabelAddRun(v cli.Values) error { | ||
labelName := v.GetString("label") | ||
err := client.WorkflowLabelAdd(v.GetString(_ProjectKey), v.GetString(_WorkflowName), labelName) | ||
return err | ||
} | ||
|
||
var workflowLabelDeleteCmd = cli.Command{ | ||
Name: "delete", | ||
Aliases: []string{"rm"}, | ||
Short: "Delete label from one workflow", | ||
Ctx: []cli.Arg{ | ||
{Name: _ProjectKey}, | ||
{Name: _WorkflowName}, | ||
{Name: "label"}, | ||
}, | ||
} | ||
|
||
func workflowLabelDeleteRun(v cli.Values) error { | ||
labelName := v.GetString("label") | ||
wf, err := client.WorkflowGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName), cdsclient.WithLabels()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var labelID int64 | ||
for _, v := range wf.Labels { | ||
if v.Name == labelName { | ||
labelID = v.ID | ||
break | ||
} | ||
} | ||
|
||
return client.WorkflowLabelDelete(v.GetString(_ProjectKey), v.GetString(_WorkflowName), labelID) | ||
} |
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
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
Oops, something went wrong.