github-package-registry - 如何从 Github 包注册表中删除/删除/取消链接/取消版本包
问题描述
问题:如何让一个包从 Github 包注册表中“消失”?
- 文档说:当所有版本都被删除时,你不能“删除”但一个包“消失”。
背景:
- Gradle 发布任务中的拼写错误导致发布了不应发布的包。
到目前为止的步骤:
- 我在 Github Web App 上没有找到“删除”选项。
- 我尝试通过 Github 的 GraphQL API 删除,但我需要此命令的包 ID:
curl -X POST \
-H "Accept: application/vnd.github.package-deletes-preview+json" \
-H "Authorization: bearer ACCESS_TOKEN" \
-d '{"query":"mutation { deletePackageVersion(input:{packageVersionId:\"PACKAGE_ID==\"}) { success }}"}' \
https://api.github.com/graphql
- 我在 Github Web App 上没有找到完整的 packageVersionId。
- 我尝试在 API 中查询包 ID,但未能形成有效的查询:
curl -X POST \
-H "Accept: application/vnd.github.package-deletes-preview+json" \
-H "Authorization: bearer ACCESS_TOKEN" \
-d "query {
organization(login: "ORGANIZATION_ACCOUNT") {
registryPackages {
edges {
node {
name
id
}
}
}
}
}" \
https://api.github.com/graphql
# The API returns:
{
"message": "Problems parsing JSON",
"documentation_url": "https://developer.github.com/v4"
}
- 我尝试使用 GraphQL API Explorer,但自动设置的令牌错过了足够的权限:
# See query above - the API returns via the Explorer:
{
"errors": [
{
"type": "INSUFFICIENT_SCOPES",
"locations": [
{
"line": 6,
"column": 11
}
],
"message": "Your token has not been granted the required scopes to execute this query. The 'name' field requires one of the following scopes: ['read:packages'], but your token has only been granted the: ['read:gpg_key', 'read:org', 'read:public_key', 'read:repo_hook', 'repo', 'user'] scopes. Please modify your token's scopes at: https://github.com/settings/tokens."
},
{
"type": "INSUFFICIENT_SCOPES",
"locations": [
{
"line": 7,
"column": 11
}
],
"message": "Your token has not been granted the required scopes to execute this query. The 'id' field requires one of the following scopes: ['read:packages'], but your token has only been granted the: ['read:gpg_key', 'read:org', 'read:public_key', 'read:repo_hook', 'repo', 'user'] scopes. Please modify your token's scopes at: https://github.com/settings/tokens."
}
]
}
- 我没有在 Explorer Web App 上找到设置另一个访问令牌的选项。
所需的解决方案
- 我想知道是否有更简单的方法可以做到这一点,如果没有,如何获取取消链接包所需的 packageVersionIds 以便它们消失。
更新 1:它是关于发布到公共存储库的包。
解决方案
不允许从公共注册表中删除包,但是您可以从私有注册表中删除包的版本,如GitHub 文档中所述:
现在可以直接在 GitHub 上删除:
- 在 GitHub 上,导航到存储库的主页。
- 在文件列表的右侧,单击包。
- 单击要删除的包的名称。
- 在右侧,使用编辑包下拉菜单并选择“管理版本”。
- 在要删除的版本右侧,单击删除。
- 要确认删除,请输入包名并单击我了解后果,删除此版本。
GraphQL 是过去用于此目的的唯一方法:
$ curl -X POST https://api.github.com/graphql \
-H "Accept: application/vnd.github.package-deletes-preview+json" \
-H "Authorization: bearer <github_token>" \
-d '{"query":"mutation { deletePackageVersion(input:{packageVersionId:\"MDE0OlBhY2thZ2VWZXJzaW9uMzc5MTE0kFcA\"}) { success }}"}'
GitHub 包的版本 id 可以列出如下:
$ curl -sL -X POST https://api.github.com/graphql \
-H "Authorization: bearer <github_token>" \
-d '{"query":"query{repository(owner:\"<repo_owner>\",name:\"<repo_name>\"){packages(first:10){nodes{packageType,name,id,versions(first:10){nodes{id,version,readme}}}}}}"}' | jq .
用您的参数更新以下参数:
<github_token>
<repo_owner>
<repo_name>
它返回如下:
{
"data": {
"repository": {
"registryPackages": {
"nodes": [
{
"packageType": "DOCKER",
"registryPackageType": "docker",
"name": "demo_image_1",
"nameWithOwner": "aki***/demo_image_1",
"id": "MDc6UGFja2FnZTYzNjg3AkFc",
"versions": {
"nodes": [
{
"id": "MDE0OlBhY2thZ2VWZXJzaW9uMzc5MTE0kFcA",
"version": "0.1a",
"readme": null
},
{
"id": "MDE0OlBhY2thZ2VWZXJzaW9uMzYzNTY2FcAk",
"version": "0.1",
"readme": null
},
{
"id": "MDE0OlBhY2thZ2VWZXJzaW9uMzYzNTY0cAkF",
"version": "docker-base-layer",
"readme": null
}
]
}
},
]
}
}
}
推荐阅读
- docker - 在 Windows 上安装 Filebeat
- spring-cloud-gateway - 如何调试 Spring Cloud Gateway 内存泄漏?
- excel - 试图获取用户名,以便我可以在查询中使用它
- postgresql - 如何选择jsonb与整数和文本数组重叠的行?(PostgreSQL)
- powershell - 至少我认为PowerShell没有正确处理参数?
- node.js - 将格子与条纹一起使用
- python - 如何将元组列表从 Python 传递到 PHP 脚本?
- python - Python Soap 客户端调用 WCF 端点并返回对象列表而不显示类名
- javascript - $.ajax 帖子不发送任何正文?
- selenium-webdriver - 'Locust_plugins' webdriverex.py 的工作示例