-
Notifications
You must be signed in to change notification settings - Fork 30
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
GitHub tree #133
GitHub tree #133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||
package github | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
|
||||||
"github.com/google/go-github/v33/github" | ||||||
|
||||||
"github.com/turbot/steampipe-plugin-sdk/grpc/proto" | ||||||
"github.com/turbot/steampipe-plugin-sdk/plugin" | ||||||
"github.com/turbot/steampipe-plugin-sdk/plugin/transform" | ||||||
) | ||||||
|
||||||
//// TABLE DEFINITION | ||||||
|
||||||
func tableGitHubTree(ctx context.Context) *plugin.Table { | ||||||
return &plugin.Table{ | ||||||
Name: "github_tree", | ||||||
Description: "Tree in the given repository, lists files in the git tree", | ||||||
Get: &plugin.GetConfig{ | ||||||
KeyColumns: []*plugin.KeyColumn{ | ||||||
{Name: "repository_full_name", Require: plugin.Required}, | ||||||
{Name: "tree_sha", Require: plugin.Required}, | ||||||
{Name: "recursive", Require: plugin.Optional}, | ||||||
}, | ||||||
ShouldIgnoreError: isNotFoundError([]string{"404"}), | ||||||
Hydrate: tableGitHubTreeGet, | ||||||
}, | ||||||
Columns: []*plugin.Column{ | ||||||
// Top columns | ||||||
{Name: "repository_full_name", Type: proto.ColumnType_STRING, Transform: transform.FromQual("repository_full_name"), Description: "Full name of the repository"}, | ||||||
{Name: "tree_sha", Type: proto.ColumnType_STRING, Transform: transform.FromQual("tree_sha"), Description: "Tree SHA"}, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{Name: "recursive", Type: proto.ColumnType_BOOL, Transform: transform.FromQual("recursive"), Description: "Recursive tree content"}, | ||||||
{Name: "truncated", Type: proto.ColumnType_BOOL, Transform: transform.FromField("Truncated"), Description: "Whether results are truncated"}, | ||||||
{Name: "entries", Type: proto.ColumnType_JSON, Transform: transform.FromField("Entries"), Description: "Tree entries"}, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
//// GET FUNCTION | ||||||
|
||||||
func tableGitHubTreeGet(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||||||
logger := plugin.Logger(ctx) | ||||||
logger.Trace("Connecting to client") | ||||||
client := connect(ctx, d) | ||||||
|
||||||
if h.Item != nil { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this if-else block for hydrate data, as it is not required here. |
||||||
item := h.Item | ||||||
logger.Trace("Got hydrate data", item) | ||||||
} else { | ||||||
logger.Trace("No hydrate data") | ||||||
} | ||||||
quals := d.KeyColumnQuals | ||||||
logger.Trace("Parsing key column quals", quals) | ||||||
fullName := quals["repository_full_name"].GetStringValue() | ||||||
sha := quals["tree_sha"].GetStringValue() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a check for empty values like below -
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
recursive := quals["recursive"].GetBoolValue() | ||||||
owner, repo := parseRepoFullName(fullName) | ||||||
|
||||||
type GetResponse struct { | ||||||
tree *github.Tree | ||||||
resp *github.Response | ||||||
} | ||||||
|
||||||
getTree := func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||||||
logger.Trace("Getting tree", "owner", owner, "repo", repo, "sha", sha) | ||||||
tree, resp, err := client.Git.GetTree(ctx, owner, repo, sha, recursive) | ||||||
return GetResponse{ | ||||||
tree: tree, | ||||||
resp: resp, | ||||||
}, err | ||||||
} | ||||||
getResponse, err := plugin.RetryHydrate(ctx, d, h, getTree, &plugin.RetryConfig{ShouldRetryError: shouldRetryError}) | ||||||
|
||||||
if err != nil { | ||||||
logger.Error("Error getting tree", err) | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
getResp := getResponse.(GetResponse) | ||||||
tree := getResp.tree | ||||||
if tree != nil { | ||||||
logger.Trace("Returning tree", tree) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return tree, nil | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
logger.Error("Nothing found") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return nil, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please replace get with the list as below -