Skip to content

add status in workflow runs #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions pkg/github/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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)
}
Expand Down Expand Up @@ -281,7 +281,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
Expand All @@ -290,7 +290,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)
}
Expand All @@ -303,7 +303,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{}
Expand All @@ -317,18 +317,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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/github/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type Client interface {
Query(ctx context.Context, q interface{}, variables map[string]interface{}) error
ListWorkflows(ctx context.Context, owner, repo string, opts *googlegithub.ListOptions) (*googlegithub.Workflows, *googlegithub.Response, error)
GetWorkflowUsage(ctx context.Context, owner, repo, workflow string, timeRange backend.TimeRange) (WorkflowUsage, error)
GetWorkflowRuns(ctx context.Context, owner, repo, workflow string, branch string, timeRange backend.TimeRange) ([]*googlegithub.WorkflowRun, error)
GetWorkflowRuns(ctx context.Context, owner, repo, workflow string, branch string, status string, timeRange backend.TimeRange) ([]*googlegithub.WorkflowRun, error)
}
3 changes: 3 additions & 0 deletions pkg/models/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/views/QueryEditorWorkflowRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props extends WorkflowRunsOptions {
const QueryEditorWorkflowRuns = (props: Props) => {
const [workflow, setWorkflow] = useState<string | undefined>(props.workflow);
const [branch, setBranch] = useState<string | undefined>(props.branch);
const [status, setStatus] = useState<string | undefined>(props.status);

return (
<>
Expand Down Expand Up @@ -47,6 +48,23 @@ const QueryEditorWorkflowRuns = (props: Props) => {
}
/>
</InlineField>
<InlineField
labelWidth={LeftColumnWidth * 2}
label="Status"
tooltip="The status to filter on (e.g. completed, in_progress) - optional"
>
<Input
value={status}
width={RightColumnWidth * 2 + LeftColumnWidth}
onChange={(el) => setStatus(el.currentTarget.value)}
onBlur={(el) =>
props.onChange({
...props,
status: el.currentTarget.value,
})
}
/>
</InlineField>
</>
);
};
Expand Down