Skip to main content
The REST API is now versioned. For more information, see "About API versioning."

包

使用 REST API 与 GitHub Packages 交互。

关于 GitHub Packages

可以使用 REST API 管理 GitHub 存储库和组织中的包。 有关详细信息,请参阅“还原和删除包”。

若要使用 REST API 管理 GitHub Packages,必须使用 personal access token (classic) 进行身份验证。

  • 要访问包元数据,令牌必须包含 read:packages 范围。
  • 要删除包和包版本,令牌必须包含 read:packages 和 delete:packages 范围。
  • 要还原包和包版本,令牌必须包含 read:packages 和 write:packages 范围。

如果包位于支持精细权限的注册表中,则令牌不需要 repo 范围即可访问或管理此包。 如果包位于仅支持存储库范围权限的注册表中,则令牌还必须包括 repo 范围,因为包继承了 GitHub 存储库的权限。 有关仅支持存储库范围权限的注册表列表,请参阅“关于 GitHub Packages 的权限”。

若要访问启用了 SSO 的组织中的资源,必须为 personal access token (classic) 启用 SSO。 有关详细信息,请参阅 GitHub Enterprise Cloud 文档中的“授权 personal access token 以用于 SAML 单一登录”。

List packages for an organization

Lists all packages in an organization readable by the user.

To use this endpoint, you must authenticate using an access token with the packages:read scope. If the package_type belongs to a registry that only supports repository-scoped permissions, your token must also include the repo scope. For the list of GitHub Packages registries that only support repository-scoped permissions, see "About permissions for GitHub Packages."

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
orgstringRequired

The organization name. The name is not case sensitive.

Query parameters
Name, Type, Description
package_typestringRequired

The type of supported package. Packages in GitHub's Gradle registry have the type maven. Docker images pushed to GitHub's Container registry (ghcr.io) have the type container. You can use the type docker to find images that were pushed to GitHub's Docker registry (docker.pkg.github.com), even if these have now been migrated to the Container registry.

Can be one of: npm, maven, rubygems, docker, nuget, container

visibilitystring

The selected visibility of the packages. This parameter is optional and only filters an existing result set.

The internal visibility is only supported for GitHub Packages registries that allow for granular permissions. For other ecosystems internal is synonymous with private. For the list of GitHub Packages registries that support granular permissions, see "About permissions for GitHub Packages."

Can be one of: public, private, internal

HTTP 响应状态代码

状态代码说明
200

OK

401

Requires authentication

403

Forbidden

代码示例

get/orgs/{org}/packages
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>"\ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/orgs/ORG/packages?package_type=container

Response

Status: 200
[ { "id": 197, "name": "hello_docker", "package_type": "container", "owner": { "login": "github", "id": 9919, "node_id": "MDEyOk9yZ2FuaXphdGlvbjk5MTk=", "avatar_url": "https://avatars.githubusercontent.com/u/