|
| 1 | +--- |
| 2 | +title: "Steampipe Table: github_package - Query GitHub Packages using SQL" |
| 3 | +description: "Allows users to query GitHub Packages, including package metadata, versions, owner details, and associated repositories, providing insights into the package management within GitHub repositories." |
| 4 | +folder: "Package" |
| 5 | +--- |
| 6 | + |
| 7 | +# Table: github_package - Query GitHub Packages using SQL |
| 8 | + |
| 9 | +GitHub Packages allow you to store and manage container images and other packages directly within your GitHub repositories. With this table, you can query details about GitHub packages within an organization, including information about the package itself, its owner, associated repositories, and visibility. |
| 10 | + |
| 11 | +## Table Usage Guide |
| 12 | + |
| 13 | +The `github_package` table provides detailed insights into packages hosted in GitHub's container registry or other package managers like npm. You can retrieve information about the package owner, repository, creation time, versioning details, and more. This is particularly useful for monitoring and managing package versions and repository associations in an organization. |
| 14 | + |
| 15 | +**Important Notes** |
| 16 | +- You must specify the `organization` column in the `where` clause to query the table. |
| 17 | +- OAuth app tokens and personal access tokens (classic) need the `read:packages` scope to use this endpoint. If the package_type belongs to a GitHub Packages registry that only supports repository-scoped permissions, the `repo` scope is also required. Please refer [Permissions for repository-scoped packages](https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages#permissions-for-repository-scoped-packages) for more information. |
| 18 | + |
| 19 | +## Examples |
| 20 | + |
| 21 | +### List all packages for a specific organization |
| 22 | +Retrieve the details of all packages available in a specified GitHub organization, including information about the owner, repository, and package type. |
| 23 | + |
| 24 | +```sql+postgres |
| 25 | +select |
| 26 | + id, |
| 27 | + name, |
| 28 | + package_type, |
| 29 | + repository_full_name, |
| 30 | + visibility, |
| 31 | + created_at, |
| 32 | + updated_at, |
| 33 | + url |
| 34 | +from |
| 35 | + github_package |
| 36 | +where |
| 37 | + organization = 'turbot'; |
| 38 | +``` |
| 39 | + |
| 40 | +```sql+sqlite |
| 41 | +select |
| 42 | + id, |
| 43 | + name, |
| 44 | + package_type, |
| 45 | + repository_full_name, |
| 46 | + visibility, |
| 47 | + created_at, |
| 48 | + updated_at, |
| 49 | + url |
| 50 | +from |
| 51 | + github_package |
| 52 | +where |
| 53 | + organization = 'turbot'; |
| 54 | +``` |
| 55 | + |
| 56 | +### List all public packages for an organization |
| 57 | +Filter and list only the packages that are publicly visible in a specific GitHub organization. This is helpful for managing public packages in your organization. |
| 58 | + |
| 59 | +```sql+postgres |
| 60 | +select |
| 61 | + id, |
| 62 | + name, |
| 63 | + package_type, |
| 64 | + repository_full_name, |
| 65 | + visibility, |
| 66 | + html_url |
| 67 | +from |
| 68 | + github_package |
| 69 | +where |
| 70 | + organization = 'turbot' |
| 71 | + and visibility = 'public'; |
| 72 | +``` |
| 73 | + |
| 74 | +```sql+sqlite |
| 75 | +select |
| 76 | + id, |
| 77 | + name, |
| 78 | + package_type, |
| 79 | + repository_full_name, |
| 80 | + visibility, |
| 81 | + html_url |
| 82 | +from |
| 83 | + github_package |
| 84 | +where |
| 85 | + organization = 'turbot' |
| 86 | + and visibility = 'public'; |
| 87 | +``` |
| 88 | + |
| 89 | +### Find packages associated with private repositories |
| 90 | +Identify packages that are tied to private repositories within a GitHub organization, allowing you to manage internal packages. |
| 91 | + |
| 92 | +```sql+postgres |
| 93 | +select |
| 94 | + name, |
| 95 | + repository_full_name, |
| 96 | + (repository ->> 'private') as repository_private |
| 97 | +from |
| 98 | + github_package |
| 99 | +where |
| 100 | + organization = 'turbot' |
| 101 | + and (repository ->> 'private')::bool = true; |
| 102 | +``` |
| 103 | + |
| 104 | +```sql+sqlite |
| 105 | +select |
| 106 | + name, |
| 107 | + repository_full_name, |
| 108 | + json_extract(repository, '$.private') as repository_private |
| 109 | +from |
| 110 | + github_package |
| 111 | +where |
| 112 | + organization = 'turbot' |
| 113 | + and json_extract(repository, '$.private') = true; |
| 114 | +``` |
| 115 | + |
| 116 | +### Get the details of a specific package by name |
| 117 | +Retrieve comprehensive details about a specific package by filtering based on the package name. It is useful for analyzing a single package's metadata, owner, and repository association. |
| 118 | + |
| 119 | +```sql+postgres |
| 120 | +select |
| 121 | + id, |
| 122 | + name, |
| 123 | + package_type, |
| 124 | + repository_full_name, |
| 125 | + created_at, |
| 126 | + updated_at, |
| 127 | + url |
| 128 | +from |
| 129 | + github_package |
| 130 | +where |
| 131 | + organization = 'turbot' |
| 132 | + and name = 'steampipe/plugin/turbot/aws'; |
| 133 | +``` |
| 134 | + |
| 135 | +```sql+sqlite |
| 136 | +select |
| 137 | + id, |
| 138 | + name, |
| 139 | + package_type, |
| 140 | + repository_full_name, |
| 141 | + created_at, |
| 142 | + updated_at, |
| 143 | + url |
| 144 | +from |
| 145 | + github_package |
| 146 | +where |
| 147 | + organization = 'turbot' |
| 148 | + and name = 'steampipe/plugin/turbot/aws'; |
| 149 | +``` |
| 150 | + |
| 151 | +### List all versions of a package for an organization |
| 152 | +Explore the versioning details for a specific package, showing the available versions and metadata for each version. |
| 153 | + |
| 154 | +```sql+postgres |
| 155 | +select |
| 156 | + name, |
| 157 | + jsonb_array_elements_text(package_version->'versions') as version |
| 158 | +from |
| 159 | + github_package |
| 160 | +where |
| 161 | + organization = 'turbot' |
| 162 | + and name = 'steampipe/plugin/turbot/aws'; |
| 163 | +``` |
| 164 | + |
| 165 | +```sql+sqlite |
| 166 | +select |
| 167 | + name, |
| 168 | + json_extract(package_version, '$.versions[0]') as version |
| 169 | +from |
| 170 | + github_package |
| 171 | +where |
| 172 | + organization = 'turbot' |
| 173 | + and name = 'steampipe/plugin/turbot/aws'; |
| 174 | +``` |
| 175 | + |
| 176 | +### Get owner information for the packages |
| 177 | +Retrieve package names along with owner information (login, ID, URL, and HTML URL) for all GitHub packages under the turbot organization. |
| 178 | + |
| 179 | +```sql+postgres |
| 180 | +select |
| 181 | + name, |
| 182 | + (owner ->> 'login') as owner_login, |
| 183 | + (owner ->> 'id') as owner_id, |
| 184 | + (owner ->> 'url') as owner_url, |
| 185 | + (owner ->> 'html_url') as owner_html_url |
| 186 | +from |
| 187 | + github_package |
| 188 | +where |
| 189 | + organization = 'turbot'; |
| 190 | +``` |
| 191 | + |
| 192 | +```sql+sqlite |
| 193 | +select |
| 194 | + name, |
| 195 | + json_extract(owner, '$.login') as owner_login, |
| 196 | + json_extract(owner, '$.id') as owner_id, |
| 197 | + json_extract(owner, '$.url') as owner_url, |
| 198 | + json_extract(owner, '$.html_url') as owner_html_url |
| 199 | +from |
| 200 | + github_package |
| 201 | +where |
| 202 | + organization = 'turbot'; |
| 203 | +``` |
| 204 | + |
| 205 | +### Get repository info for the packages |
| 206 | +Extract key fields (like repository name, full name, visibility, URL, and owner login) from the nested repository object in each GitHub package. This provides a flat, queryable view of essential repository information per package. |
| 207 | + |
| 208 | +```sql+postgres |
| 209 | +select |
| 210 | + name, |
| 211 | + repository ->> 'name' as repository_name, |
| 212 | + repository ->> 'id' as repository_id, |
| 213 | + repository ->> 'private' as repository_private, |
| 214 | + repository ->> 'html_url' as repository_html_url, |
| 215 | + repository ->> 'description' as repository_description, |
| 216 | + repository ->> 'fork' as repository_fork, |
| 217 | + repository -> 'owner' ->> 'login' as repository_owner_login, |
| 218 | + repository ->> 'stargazers_url' as repository_stargazers_url, |
| 219 | + repository ->> 'contents_url' as repository_contents_url |
| 220 | +from |
| 221 | + github_package |
| 222 | +where |
| 223 | + organization = 'turbot'; |
| 224 | +``` |
| 225 | + |
| 226 | +```sql+sqlite |
| 227 | +select |
| 228 | + name, |
| 229 | + json_extract(repository, '$.name') as repository_name, |
| 230 | + json_extract(repository, '$.id') as repository_id, |
| 231 | + json_extract(repository, '$.private') as repository_private, |
| 232 | + json_extract(repository, '$.html_url') as repository_html_url, |
| 233 | + json_extract(repository, '$.description') as repository_description, |
| 234 | + json_extract(repository, '$.fork') as repository_fork, |
| 235 | + json_extract(repository, '$.owner.login') as repository_owner_login, |
| 236 | + json_extract(repository, '$.stargazers_url') as repository_stargazers_url, |
| 237 | + json_extract(repository, '$.contents_url') as repository_contents_url |
| 238 | +from |
| 239 | + github_package |
| 240 | +where |
| 241 | + organization = 'turbot'; |
| 242 | +``` |
0 commit comments