From cac0408f94f9e0fc61d16213dfd5d9eb9bc1d9df Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Thu, 2 Jan 2025 02:00:04 -0500 Subject: [PATCH] Add `run_attempt` as an optional key column for `github_actions_repository_workflow_run` get calls (#464) --- ..._github_actions_repository_workflow_run.go | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/github/table_github_actions_repository_workflow_run.go b/github/table_github_actions_repository_workflow_run.go index 122e26f..68cd5d0 100644 --- a/github/table_github_actions_repository_workflow_run.go +++ b/github/table_github_actions_repository_workflow_run.go @@ -9,6 +9,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 { @@ -28,7 +29,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, }, @@ -163,6 +168,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 @@ -171,11 +177,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 }