Skip to content

Commit 97e6d06

Browse files
authored
feat(cli): add delete workflow run command (#6273)
1 parent dbb9889 commit 97e6d06

File tree

5 files changed

+89
-19
lines changed

5 files changed

+89
-19
lines changed

cli/cdsctl/workflow.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func workflow() *cobra.Command {
2020
return cli.NewCommand(workflowCmd, nil, []*cobra.Command{
2121
cli.NewCommand(workflowInitCmd, workflowInitRun, nil),
2222
cli.NewCommand(templateApplyCmd("applyTemplate"), templateApplyRun, nil, withAllCommandModifiers()...),
23+
cli.NewDeleteCommand(workflowRunDeleteCmd, workflowRunDelete, nil, withAllCommandModifiers()...),
2324
cli.NewListCommand(workflowListCmd, workflowListRun, nil, withAllCommandModifiers()...),
2425
cli.NewListCommand(workflowHistoryCmd, workflowHistoryRun, nil, withAllCommandModifiers()...),
2526
cli.NewGetCommand(workflowShowCmd, workflowShowRun, nil, withAllCommandModifiers()...),

cli/cdsctl/workflow_run.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,35 @@ func workflowRunManualRun(v cli.Values) error {
213213

214214
return workflowRunInteractive(v, w, configUser.URLUI)
215215
}
216+
217+
var workflowRunDeleteCmd = cli.Command{
218+
Name: "run-delete",
219+
Short: "Delete a workflow run",
220+
Aliases: []string{"remove", "rm"},
221+
Ctx: []cli.Arg{
222+
{Name: _ProjectKey},
223+
{Name: _WorkflowName},
224+
},
225+
VariadicArgs: cli.Arg{
226+
Name: "run-number",
227+
IsValid: func(s string) bool {
228+
match, _ := regexp.MatchString(`[0-9]?`, s)
229+
return match
230+
},
231+
},
232+
}
233+
234+
func workflowRunDelete(v cli.Values) error {
235+
runNumbers := v.GetStringSlice("run-number")
236+
for _, runNumber := range runNumbers {
237+
num, err := strconv.Atoi(runNumber)
238+
if err != nil {
239+
return err
240+
}
241+
fmt.Printf("Deleting run %d\n", num)
242+
if err := client.WorkflowRunDelete(v.GetString(_ProjectKey), v.GetString(_WorkflowName), int64(num)); err != nil {
243+
return err
244+
}
245+
}
246+
return nil
247+
}

sdk/cdsclient/client_workflow.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ func (c *client) WorkflowRunSearch(projectKey string, offset, limit int64, filte
122122
return runs, nil
123123
}
124124

125+
func (c *client) WorkflowRunDelete(projectKey string, workflowName string, runNumber int64) error {
126+
url := fmt.Sprintf("/project/%s/workflows/%s/runs/%d", projectKey, workflowName, runNumber)
127+
if _, err := c.DeleteJSON(context.Background(), url, nil); err != nil {
128+
return err
129+
}
130+
return nil
131+
}
132+
125133
func (c *client) WorkflowRunList(projectKey string, workflowName string, offset, limit int64) ([]sdk.WorkflowRun, error) {
126134
if offset < 0 {
127135
offset = 0

sdk/cdsclient/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ type WorkflowClient interface {
348348
WorkflowRunsDeleteByBranch(projectKey string, workflowName string, branch string) error
349349
WorkflowRunSearch(projectKey string, offset, limit int64, filter ...Filter) ([]sdk.WorkflowRun, error)
350350
WorkflowRunList(projectKey string, workflowName string, offset, limit int64) ([]sdk.WorkflowRun, error)
351+
WorkflowRunDelete(projectKey string, workflowName string, runNumber int64) error
351352
WorkflowRunArtifactsLinks(projectKey string, name string, number int64) (sdk.CDNItemLinks, error)
352353
WorkflowRunResultsList(ctx context.Context, projectKey string, name string, number int64) ([]sdk.WorkflowRunResult, error)
353354
WorkflowRunFromHook(projectKey string, workflowName string, hook sdk.WorkflowNodeRunHookEvent) (*sdk.WorkflowRun, error)

sdk/cdsclient/mock_cdsclient/interface_mock.go

Lines changed: 47 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)