Skip to content

Commit b7a0cb9

Browse files
authored
feat(cli): Workflow run can receive a status flag (#723)
Signed-off-by: Javier Rodriguez <[email protected]>
1 parent d0086d1 commit b7a0cb9

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

app/cli/cmd/workflow_workflow_run_list.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
3030
DefaultLimit: 20,
3131
}
3232

33-
var workflowID string
33+
var workflowID, status string
3434

3535
cmd := &cobra.Command{
3636
Use: "list",
@@ -44,6 +44,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
4444
Limit: paginationOpts.Limit,
4545
NextCursor: paginationOpts.NextCursor,
4646
},
47+
Status: status,
4748
},
4849
)
4950
if err != nil {
@@ -71,6 +72,7 @@ func newWorkflowWorkflowRunListCmd() *cobra.Command {
7172

7273
cmd.Flags().StringVar(&workflowID, "workflow", "", "workflow ID")
7374
cmd.Flags().BoolVar(&full, "full", false, "full report")
75+
cmd.Flags().StringVar(&status, "status", "", fmt.Sprintf("filter by workflow run status: %v", listAvailableWorkflowStatusFlag()))
7476
// Add pagination flags
7577
paginationOpts.AddFlags(cmd)
7678

@@ -108,3 +110,14 @@ func workflowRunListTableOutput(runs []*action.WorkflowRunItem) error {
108110

109111
return nil
110112
}
113+
114+
// listAvailableWorkflowStatusFlag returns a list of available workflow status flags
115+
func listAvailableWorkflowStatusFlag() []string {
116+
m := action.WorkflowRunStatus()
117+
r := make([]string, 0, len(m))
118+
for k := range m {
119+
r = append(r, k)
120+
}
121+
122+
return r
123+
}

app/cli/internal/action/workflow_run_list.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,24 @@ package action
1717

1818
import (
1919
"context"
20+
"strings"
2021
"time"
2122

2223
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
2324
v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
2425
)
2526

27+
// WorkflowRunStatus represents the status of a workflow run
28+
var WorkflowRunStatus = func() map[string]pb.RunStatus {
29+
res := make(map[string]pb.RunStatus)
30+
for k, v := range pb.RunStatus_value {
31+
if k != "RUN_STATUS_UNSPECIFIED" {
32+
res[strings.Replace(k, "RUN_STATUS_", "", 1)] = pb.RunStatus(v)
33+
}
34+
}
35+
return res
36+
}
37+
2638
type WorkflowRunList struct {
2739
cfg *ActionsOpts
2840
}
@@ -53,6 +65,7 @@ func NewWorkflowRunList(cfg *ActionsOpts) *WorkflowRunList {
5365
type WorkflowRunListOpts struct {
5466
WorkflowID string
5567
Pagination *PaginationOpts
68+
Status string
5669
}
5770
type PaginationOpts struct {
5871
Limit int
@@ -61,14 +74,19 @@ type PaginationOpts struct {
6174

6275
func (action *WorkflowRunList) Run(opts *WorkflowRunListOpts) (*PaginatedWorkflowRunItem, error) {
6376
client := pb.NewWorkflowRunServiceClient(action.cfg.CPConnection)
64-
resp, err := client.List(context.Background(),
65-
&pb.WorkflowRunServiceListRequest{
66-
WorkflowId: opts.WorkflowID,
67-
Pagination: &pb.CursorPaginationRequest{
68-
Limit: int32(opts.Pagination.Limit),
69-
Cursor: opts.Pagination.NextCursor,
70-
},
71-
})
77+
req := &pb.WorkflowRunServiceListRequest{
78+
WorkflowId: opts.WorkflowID,
79+
Pagination: &pb.CursorPaginationRequest{
80+
Limit: int32(opts.Pagination.Limit),
81+
Cursor: opts.Pagination.NextCursor,
82+
},
83+
}
84+
85+
if v, ok := WorkflowRunStatus()[opts.Status]; ok {
86+
req.Status = v
87+
}
88+
89+
resp, err := client.List(context.Background(), req)
7290
if err != nil {
7391
return nil, err
7492
}

app/cli/internal/action/workflow_run_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *workflowRunListSuite) TestHumanizedRunnerType() {
7979
)
8080

8181
for _, testCase := range testCases {
82-
s.T().Run(testCase.name, func(t *testing.T) {
82+
s.Run(testCase.name, func() {
8383
result := humanizedRunnerType(testCase.testInput)
8484
s.Equal(testCase.expectedOutput, result)
8585
})

0 commit comments

Comments
 (0)