13

问题:如何让一个包从 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:它是关于发布到公共存储库的包。

4

4 回答 4

18

不允许从公共注册表中删除包,但是您可以从私有注册表中删除包的版本,如GitHub 文档中所述:

现在可以直接在 GitHub 上删除:

  1. 在 GitHub 上,导航到存储库的主页。
  2. 在文件列表的右侧,单击包。
  3. 单击要删除的包的名称。
  4. 在右侧,使用编辑包下拉菜单并选择“管理版本”。
  5. 在要删除的版本右侧,单击删除。
  6. 要确认删除,请输入包名并单击我了解后果,删除此版本。

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
                }
              ]
            }
          },
        ]
      }
    }
  }
于 2019-12-03T09:22:50.793 回答
11

维护者可以删除私有的包版本:

  • 通过 Github API,查看@Akif 的回答
  • 通过 Github 支持
  • 通过 Web 应用程序 Github.com
    • 转到您的存储库的包https://github.com/orgs/YOUR_ACCOUNT/packages?repo_name=YOUR_REPO

    • 选择一个包https://github.com/YOUR_ACCOUNT/YOUR_REPO/packages/PACKAGE_ID

    • 显示该软件包的所有版本https://github.com/cyface-de/backend/packages/81398/versions

    • 使用DELETE按钮删除此私人包

      在此处输入图像描述

公共存储库的包版本不能被维护者删除,即:

  • 需要联系 Github 支持以删除软件包或版本。

  • 解决方法:将您的存储库临时设为私有以供删除:

    • 注意:这会导致损失stars等,请参阅Github警告!
    • Repository Settings> Danger Zone>Make private
    • 要删除软件包版本:
      • 通过 API:按照@Akif 回答的说明进行操作
      • 通过网络应用程序:见上文
    • Repository Settings> Danger Zone>Make public
于 2019-11-29T13:17:22.580 回答
6

我找到了如何删除包的解决方案。

  1. 转到存储库设置并将可见性更改为“私有”。
  2. 转到存储库,单击“包”>>“管理版本”
  3. 在页面上,我们看到“删除”按钮。
  4. 删除后,返回存储库设置并将可见性更改为“公共”。
  5. 利润!
于 2020-09-21T09:42:42.127 回答
0

在测试(私人包)时,我多次发布了相同的版本并将其删除。直到它以某种方式卡住并且我无法单击 UI 上的“管理版本”,因为按钮改为“包设置”。以前提供的 GraphQL 没有帮助,但我能够通过以下方式识别GraphQL Explorer上的版本:

query {
  repository(owner: "<org>", name: "<repo>") {
    packages(first: 10) {
      edges {
        node {
          latestVersion {
            id
            version
          }
        }
      }
    }
  }
}

这返回了一个稍微不同步的节点列表,类似于:

{
  "data": {
    "repository": {
      "packages": {
        "edges": [
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": null
            }
          },
          {
            "node": {
              "latestVersion": {
                "id": "MDE0OlBhY2thZ2VWZXJzaW9uNTYxMjQyOQ=="
                "version": "0.1.0"
              }
            }
          }
        ]
      }
    }
  }
}

有了这个,我可以通过以下方式一一删除它们:

curl -X POST https://api.github.com/graphql \
-H "Accept: application/vnd.github.package-deletes-preview+json" \
-H "Authorization: bearer $TOKEN" \
-d '{"query":"mutation { deletePackageVersion(input:{packageVersionId:\"MDE0OlBhY2thZ2VWZXJzaW9uNTYxMjQyOQ==\"}) { success }}"}'
于 2020-12-07T21:57:05.003 回答