Skip to content

Commit

Permalink
Add run_attempt as an optional key column for `github_actions_repos…
Browse files Browse the repository at this point in the history
…itory_workflow_run` get calls

This is the bare minimum to allow previous run attempts to be queried,
which is useful for comparisons between attempts.  User queries must
explicitly iterate over a run's multiple attempts as necessary, e.g. by
parsing `previous_attempt_url` in a `with recursive` CTE or simply
presuming the series of attempts is `generate_series(1, run_attempt)`.

A future improvement for this plugin might be exposing a new table, e.g.
`github_actions_repository_workflow_run_attempt`, with the same list key
columns of `repository_full_name` and `id`, and handling the iteration
internally.  GitHub's API unfortunately provides no listing endpoints
for run attempts.
  • Loading branch information
tsibley committed Dec 31, 2024
1 parent 069c406 commit fc3ed5f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions github/table_github_actions_repository_workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
"github.com/turbot/steampipe-plugin-sdk/v5/query_cache"
)

func tableGitHubActionsRepositoryWorkflowRun() *plugin.Table {
Expand All @@ -26,7 +27,11 @@ func tableGitHubActionsRepositoryWorkflowRun() *plugin.Table {
},
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"repository_full_name", "id"}),
KeyColumns: []*plugin.KeyColumn{
{Name: "repository_full_name", Require: plugin.Required, Operators: []string{"="}},
{Name: "id", Require: plugin.Required, Operators: []string{"="}},
{Name: "run_attempt", Require: plugin.Optional, Operators: []string{"="}, CacheMatch: query_cache.CacheMatchExact},
},
ShouldIgnoreError: isNotFoundError([]string{"404"}),
Hydrate: tableGitHubRepoWorkflowRunGet,
},
Expand Down Expand Up @@ -141,6 +146,7 @@ func tableGitHubRepoWorkflowRunList(ctx context.Context, d *plugin.QueryData, h

func tableGitHubRepoWorkflowRunGet(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
runId := d.EqualsQuals["id"].GetInt64Value()
runAttempt := int(d.EqualsQuals["run_attempt"].GetInt64Value())
orgName := d.EqualsQuals["repository_full_name"].GetStringValue()

// Empty check for the parameters
Expand All @@ -149,11 +155,20 @@ func tableGitHubRepoWorkflowRunGet(ctx context.Context, d *plugin.QueryData, h *
}

owner, repo := parseRepoFullName(orgName)
plugin.Logger(ctx).Trace("tableGitHubRepoWorkflowRunGet", "owner", owner, "repo", repo, "runId", runId)
plugin.Logger(ctx).Trace("tableGitHubRepoWorkflowRunGet", "owner", owner, "repo", repo, "runId", runId, "runAttempt", runAttempt)

client := connect(ctx, d)

workflowRun, _, err := client.Actions.GetWorkflowRunByID(ctx, owner, repo, runId)
var (
workflowRun *github.WorkflowRun
err error
)
if runAttempt != 0 {
opts := &github.WorkflowRunAttemptOptions{}
workflowRun, _, err = client.Actions.GetWorkflowRunAttempt(ctx, owner, repo, runId, runAttempt, opts)
} else {
workflowRun, _, err = client.Actions.GetWorkflowRunByID(ctx, owner, repo, runId)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit fc3ed5f

Please sign in to comment.