如何从Github程序包注册表中删除/删除/取消链接/取消版本包

问题:如何从Github软件包注册表中使软件包“消失”?

  • Documentation说:删除所有版本后,您无法“删除”,但程序包“消失”。

背景

  • Gradle发布任务中的错字导致发布了不应发布的软件包。

到目前为止的步骤:

  • 我在Github Web应用程序上找不到“删除”选项。
  • 我试图通过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应用程序上找不到完整的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,"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'],'user'] scopes. Please modify your token's scopes at: https://github.com/settings/tokens."
    }
  ]
}
  • 我没有在Explorer Web App上找到设置另一个访问令牌的选项。

所需的解决方案

  • 我想知道是否有更简单的方法来执行此操作,否则,如何获取取消链接包以使其消失所需的packageVersionIds。

更新1::关于发布到公共存储库的软件包。

charlestri 回答:如何从Github程序包注册表中删除/删除/取消链接/取消版本包

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

  1. 转到存储库设置,并将可见性更改为“私人”。
  2. 转到存储库,单击“程序包” >>“管理版本”
  3. 在页面上,我们看到“删除”按钮。
  4. 删除后,返回到存储库设置,并将可见性更改为“公开”。
  5. 利润!
,

不允许从公共注册表中删除软件包,但是您可以按照GitHub docs中所述从私有注册表中删除软件包:

$ 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>\"){registryPackages(first:10){nodes{packageType,registryPackageType,name,nameWithOwner,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",{
                  "id": "MDE0OlBhY2thZ2VWZXJzaW9uMzYzNTY0cAkF","version": "docker-base-layer","readme": null
                }
              ]
            }
          },]
      }
    }
  }
,

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

  • 通过Github API,请参见@Akif的答案
  • 通过Github支持
    • Github将很快通过Web App添加一种轻松实现此目的的方法。 (来源:支持)

维护者对公共存储库cannot be deleted的打包版本,即:

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

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

    • 注意:这会导致星星丢失等,请参阅Github警告!
    • Repository Settings> Danger Zone> Make private
    • 按照说明执行@Akif的答案以删除软件包版本
    • Repository Settings> Danger Zone> Make public
,

在测试(私有软件包)时,我多次发布了相同的版本并将其删除。直到它以某种方式卡住并且我无法在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": {
                "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 }}"}'
本文链接:https://www.f2er.com/3008223.html

大家都在问