Table: github_repository_content - Query File and Directory Contents in GitHub Repositories using SQL
The github_repository_content
table is designed to fetch the contents of files or directories within a GitHub repository. It provides a detailed view of file paths, types, contents, sizes, and other related information.
Table Usage Guide
To utilize this table effectively, specify the file path or directory within repository_content_path
. If repository_content_path
is not specified, the table will return the contents of the repository's root directory. This feature allows for comprehensive exploration of repository contents, from individual files to entire directories.
Important Notes
- It's mandatory to specify the
repository_full_name
(including the organization/user prefix) in thewhere
orjoin
clause when querying this table. - To enhance performance, this table supports the optional qualifier
repository_content_path
. Queries that utilize this qualifier are optimized to efficiently retrieve file contents from a sub-directory within a repository.
Examples
List the root directory contents of a repository
This query is useful for obtaining an overview of the root directory of a specific repository, helping users quickly identify the initial set of files and directories it contains.
select repository_full_name, path, content, type, size, shafrom github_repository_contentwhere repository_full_name = 'github/docs';
select repository_full_name, path, content, type, size, shafrom github_repository_contentwhere repository_full_name = 'github/docs';
Get file contents under a folder in a repository
This enables retrieval of the file contents within a specific directory.
select repository_full_name, name, type, path, contentfrom github_repository_contentwhere repository_full_name = 'turbot/steampipe-plugin-aws' and repository_content_path = 'aws-tests/tests';
select repository_full_name, name, type, path, contentfrom github_repository_contentwhere repository_full_name = 'turbot/steampipe-plugin-aws' and repository_content_path = 'aws-tests/tests';
List contents of a specific directory within a repository
This query facilitates a deeper inspection of a specific directory within a repository, enabling users to understand its structure and the types of files it contains.
select repository_full_name, path, content, type, size, shafrom github_repository_contentwhere repository_full_name = 'github/docs' and repository_content_path = 'docs';
select repository_full_name, path, content, type, size, shafrom github_repository_contentwhere repository_full_name = 'github/docs' and repository_content_path = 'docs';
Retrieve a specific file within a repository
Targeting a specific file within a repository, this query is particularly useful for extracting detailed information about a file, such as its content, type, and size, which is essential for analysis or integration purposes.
select repository_full_name, path, type, size, sha, contentfrom github_repository_contentwhere repository_full_name = 'github/docs' and repository_content_path = '.vscode/settings.json';
select repository_full_name, path, type, size, sha, contentfrom github_repository_contentwhere repository_full_name = 'github/docs' and repository_content_path = '.vscode/settings.json';
Schema for github_repository_content
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
abbreviated_oid | text | An abbreviated version of the Git object ID. | |
commit_url | text | Git URL (with SHA) of the file. | |
content | text | The decoded file content (if the element is a file). | |
is_binary | boolean | Indicates whether the Blob is binary or text. | |
is_generated | boolean | Whether or not this tree entry is generated. | |
line_count | bigint | The number of lines available in the file. | |
mode | bigint | The mode of the file. | |
name | text | The file name. | |
oid | text | The Git object ID. | |
path | text | = | The path of the file. |
path_raw | text | A Base64-encoded representation of the file's path. | |
repository_content_path | text | = | The requested path in repository search. |
repository_full_name | text | = | The full name of the repository (login/repo-name). |
size | bigint | The size of the file (in KB). | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. | |
type | text | The file type (directory or file). |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- github
You can pass the configuration to the command with the --config
argument:
steampipe_export_github --config '<your_config>' github_repository_content