-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ved misra <[email protected]>
- Loading branch information
Showing
3 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
title: "Steampipe Table: github_blob - Query GitHub blobs using SQL" | ||
description: "Allows users to query GitHub Repositories, specifically the blob content." | ||
--- | ||
|
||
# Table: github_blob - Query GitHub Repositories using SQL | ||
|
||
GitHub Repositories are a fundamental resource in GitHub. They allow users to host and manage their codebase, track changes, and collaborate with other users. Each repository contains a tree structure that represents the file and directory hierarchy. | ||
|
||
## Table Usage Guide | ||
|
||
The `github_blob` table provides the contents of files within GitHub Repositories. As a developer or project manager, explore each repository's contents. Utilize it to uncover information about specific files in the repository, such as configuration files. | ||
|
||
**Important Notes** | ||
- You must specify the `repository_full_name` and `blob_sha` columns in `where` or `join` clause to query the table. | ||
|
||
## Examples | ||
|
||
### List blob contents for a specific file | ||
Explore the specific elements within the 'turbot/steampipe' repository by pinpointing specific files using a unique identifier. This helps understand the contents of the repository and makes it easy to access and analyze the file's content. | ||
|
||
```sql+postgres | ||
select | ||
tree_sha, | ||
truncated, | ||
path, | ||
mode, | ||
type, | ||
sha, | ||
decode(content, encoding) as content | ||
from | ||
github_tree t | ||
left outer join | ||
github_blob b on b.repository_full_name = t.repository_full_name and b.blob_sha = t.sha | ||
where | ||
t.repository_full_name = 'turbot/steampipe' | ||
and tree_sha = '0f200416c44b8b85277d973bff933efa8ef7803a' | ||
and path = 'Makefile'; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
tree_sha, | ||
truncated, | ||
path, | ||
mode, | ||
type, | ||
sha, | ||
decode(content, encoding) as content | ||
from | ||
github_tree t | ||
left outer join | ||
github_blob b on b.repository_full_name = t.repository_full_name and b.blob_sha = t.sha | ||
where | ||
t.repository_full_name = 'turbot/steampipe' | ||
and tree_sha = '0f200416c44b8b85277d973bff933efa8ef7803a' | ||
and path = 'Makefile'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
|
||
"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" | ||
) | ||
|
||
func tableGitHubBlob() *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "github_blob", | ||
Description: "Gets a blob from a repository.", | ||
List: &plugin.ListConfig{ | ||
Hydrate: tableGitHubBlobList, | ||
ShouldIgnoreError: isNotFoundError([]string{"404"}), | ||
KeyColumns: []*plugin.KeyColumn{ | ||
{Name: "repository_full_name", Require: plugin.Required}, | ||
{Name: "blob_sha", Require: plugin.Required}, | ||
}, | ||
}, | ||
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 that contains the blob."}, | ||
{Name: "blob_sha", Type: proto.ColumnType_STRING, Transform: transform.FromField("Sha"), Description: "SHA1 of the blob."}, | ||
// Other columns | ||
{Name: "node_id", Type: proto.ColumnType_STRING, Transform: transform.FromField("NodeID"), Description: "The node ID of the blob."}, | ||
{Name: "url", Type: proto.ColumnType_STRING, Description: "URL of the blob."}, | ||
{Name: "content", Type: proto.ColumnType_STRING, Description: "The encoded content of the blob."}, | ||
{Name: "encoding", Type: proto.ColumnType_STRING, Description: "The encoding of the blob."}, | ||
{Name: "size", Type: proto.ColumnType_INT, Description: "Size of the blob."}, | ||
}, | ||
} | ||
} | ||
|
||
type blobRow struct { | ||
Sha string | ||
NodeID string | ||
Url string | ||
Content string | ||
Encoding string | ||
Size int | ||
} | ||
|
||
func tableGitHubBlobList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
logger := plugin.Logger(ctx) | ||
client := connect(ctx, d) | ||
|
||
quals := d.EqualsQuals | ||
fullName := quals["repository_full_name"].GetStringValue() | ||
sha := quals["blob_sha"].GetStringValue() | ||
owner, repo := parseRepoFullName(fullName) | ||
|
||
blob, _, err := client.Git.GetBlob(ctx, owner, repo, sha) | ||
if err != nil { | ||
logger.Error("github_blob.tableGitHubBlobList", "api_error", err) | ||
return nil, err | ||
} | ||
|
||
if blob != nil { | ||
d.StreamListItem(ctx, blobRow{ | ||
Sha: *blob.SHA, | ||
NodeID: *blob.NodeID, | ||
Content: *blob.Content, | ||
Encoding: *blob.Encoding, | ||
Size: *blob.Size, | ||
}) | ||
} | ||
|
||
return nil, nil | ||
} |