Skip to content
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

Add run_attempt as an optional key column for github_actions_repository_workflow_run get calls #464

Merged
merged 2 commits into from
Jan 2, 2025
Merged
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
23 changes: 20 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 All @@ -49,6 +54,7 @@ func tableGitHubActionsRepositoryWorkflowRun() *plugin.Table {
{Name: "jobs_url", Type: proto.ColumnType_STRING, Description: "The address for the workflow job GitHub web page."},
{Name: "logs_url", Type: proto.ColumnType_STRING, Description: "The address for the workflow logs GitHub web page."},
{Name: "rerun_url", Type: proto.ColumnType_STRING, Description: "The address for workflow rerun GitHub web page."},
{Name: "previous_attempt_url", Type: proto.ColumnType_STRING, Description: "The address for the previous attempt GitHub web page."},
{Name: "url", Type: proto.ColumnType_STRING, Description: "The address for the workflow run GitHub web page.", Transform: transform.FromField("URL")},
{Name: "workflow_url", Type: proto.ColumnType_STRING, Description: "The address for workflow GitHub web page."},

Expand All @@ -58,6 +64,7 @@ func tableGitHubActionsRepositoryWorkflowRun() *plugin.Table {
{Name: "head_repository", Type: proto.ColumnType_JSON, Description: "The head repository info for the workflow run."},
{Name: "pull_requests", Type: proto.ColumnType_JSON, Description: "The pull request details for the workflow run."},
{Name: "repository", Type: proto.ColumnType_JSON, Description: "The repository info for the workflow run."},
{Name: "run_attempt", Type: proto.ColumnType_INT, Description: "The attempt number of the workflow run."},
{Name: "run_started_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("RunStartedAt").Transform(convertTimestamp), Description: "Time when the workflow run was started."},
{Name: "updated_at", Type: proto.ColumnType_TIMESTAMP, Transform: transform.FromField("UpdatedAt").Transform(convertTimestamp), Description: "Time when the workflow run was updated."},
{Name: "actor", Type: proto.ColumnType_JSON, Description: "The user whom initiated the first instance of this workflow run."},
Expand Down Expand Up @@ -139,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 @@ -147,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
Loading