diff --git a/pkg/github/client/client.go b/pkg/github/client/client.go index 9565d15d..d176b52a 100644 --- a/pkg/github/client/client.go +++ b/pkg/github/client/client.go @@ -202,7 +202,7 @@ func (client *Client) GetWorkflowUsage(ctx context.Context, owner, repo, workflo } var workflowRuns []*googlegithub.WorkflowRun var err error - workflowRuns, page, err = client.getWorkflowRuns(ctx, owner, repo, workflow, "", timeRange, page) + workflowRuns, page, err = client.getWorkflowRuns(ctx, owner, repo, workflow, "", timeRange, page, runStatusCompleted) if err != nil { return models.WorkflowUsage{}, fmt.Errorf("fetching workflow runs: %w", err) } @@ -308,7 +308,7 @@ func (client *Client) getWorkflowUsage(ctx context.Context, owner, repo string, return client.restClient.Actions.GetWorkflowUsageByFileName(ctx, owner, repo, workflow) } -func (client *Client) GetWorkflowRuns(ctx context.Context, owner, repo, workflow string, branch string, timeRange backend.TimeRange) ([]*googlegithub.WorkflowRun, error) { +func (client *Client) GetWorkflowRuns(ctx context.Context, owner, repo, workflow string, branch string, status string, timeRange backend.TimeRange) ([]*googlegithub.WorkflowRun, error) { workflowRuns := []*googlegithub.WorkflowRun{} page := 1 @@ -317,7 +317,7 @@ func (client *Client) GetWorkflowRuns(ctx context.Context, owner, repo, workflow break } - workflowRunsPage, nextPage, err := client.getWorkflowRuns(ctx, owner, repo, workflow, branch, timeRange, page) + workflowRunsPage, nextPage, err := client.getWorkflowRuns(ctx, owner, repo, workflow, branch, status, timeRange, page) if err != nil { return nil, fmt.Errorf("fetching workflow runs: %w", err) } @@ -330,7 +330,7 @@ func (client *Client) GetWorkflowRuns(ctx context.Context, owner, repo, workflow return workflowRuns, nil } -func (client *Client) getWorkflowRuns(ctx context.Context, owner, repo, workflow string, branch string, timeRange backend.TimeRange, page int) ([]*googlegithub.WorkflowRun, int, error) { +func (client *Client) getWorkflowRuns(ctx context.Context, owner, repo, workflow string, branch string, status string, timeRange backend.TimeRange, page int) ([]*googlegithub.WorkflowRun, int, error) { workflowID, _ := strconv.ParseInt(workflow, 10, 64) workflowRuns := []*googlegithub.WorkflowRun{} @@ -344,18 +344,19 @@ func (client *Client) getWorkflowRuns(ctx context.Context, owner, repo, workflow err error ) + listOptions := &googlegithub.ListWorkflowRunsOptions{ + Created: created, + ListOptions: googlegithub.ListOptions{Page: page, PerPage: 100}, + Branch: branch, + } + if status != "" { + listOptions.Status = status + } + if workflowID > 0 { - runs, response, err = client.restClient.Actions.ListWorkflowRunsByID(ctx, owner, repo, workflowID, &googlegithub.ListWorkflowRunsOptions{ - Created: created, - ListOptions: googlegithub.ListOptions{Page: page, PerPage: 100}, - Branch: branch, - }) + runs, response, err = client.restClient.Actions.ListWorkflowRunsByID(ctx, owner, repo, workflowID, listOptions) } else { - runs, response, err = client.restClient.Actions.ListWorkflowRunsByFileName(ctx, owner, repo, workflow, &googlegithub.ListWorkflowRunsOptions{ - Created: created, - ListOptions: googlegithub.ListOptions{Page: page, PerPage: 100}, - Branch: branch, - }) + runs, response, err = client.restClient.Actions.ListWorkflowRunsByFileName(ctx, owner, repo, workflow, listOptions) } if err != nil { diff --git a/pkg/github/datasource.go b/pkg/github/datasource.go index 574d5245..bf8670d6 100644 --- a/pkg/github/datasource.go +++ b/pkg/github/datasource.go @@ -197,6 +197,7 @@ func (d *Datasource) HandleWorkflowRunsQuery(ctx context.Context, query *models. Owner: query.Owner, Workflow: query.Options.Workflow, Branch: query.Options.Branch, + Status: query.Options.Status, } return GetWorkflowRuns(ctx, d.client, opt, req.TimeRange) diff --git a/pkg/github/workflows.go b/pkg/github/workflows.go index 2588edae..be4b39a2 100644 --- a/pkg/github/workflows.go +++ b/pkg/github/workflows.go @@ -237,7 +237,7 @@ func GetWorkflowRuns(ctx context.Context, client models.Client, opts models.Work return nil, nil } - workflowRuns, err := client.GetWorkflowRuns(ctx, opts.Owner, opts.Repository, opts.Workflow, opts.Branch, timeRange) + workflowRuns, err := client.GetWorkflowRuns(ctx, opts.Owner, opts.Repository, opts.Workflow, opts.Branch, opts.Status, timeRange) if err != nil { return nil, err } diff --git a/pkg/models/workflows.go b/pkg/models/workflows.go index 6afdaccf..bc07ff08 100644 --- a/pkg/models/workflows.go +++ b/pkg/models/workflows.go @@ -37,6 +37,9 @@ type WorkflowUsageOptions struct { // Branch is the branch to filter the runs by. Branch string `json:"branch"` + + // Status is the status to filter the runs by (e.g. completed, in_progress, etc.) + Status string `json:"status"` } type WorkflowRunsOptions = WorkflowUsageOptions diff --git a/src/views/QueryEditorWorkflowRuns.tsx b/src/views/QueryEditorWorkflowRuns.tsx index 55072671..8f3a99cd 100644 --- a/src/views/QueryEditorWorkflowRuns.tsx +++ b/src/views/QueryEditorWorkflowRuns.tsx @@ -10,6 +10,7 @@ interface Props extends WorkflowRunsOptions { const QueryEditorWorkflowRuns = (props: Props) => { const [workflow, setWorkflow] = useState(props.workflow); const [branch, setBranch] = useState(props.branch); + const [status, setStatus] = useState(props.status); return ( <> @@ -47,6 +48,23 @@ const QueryEditorWorkflowRuns = (props: Props) => { } /> + + setStatus(el.currentTarget.value)} + onBlur={(el) => + props.onChange({ + ...props, + status: el.currentTarget.value, + }) + } + /> + ); };