13

質問: Github Package Registry からパッケージを「非表示」にするにはどうすればよいですか?

  • ドキュメントには、「削除」することはできませんが、すべてのバージョンが削除されるとパッケージは「消えます」。

バックグラウンド:

  • 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 が見つかりませんでした。
  • パッケージ ID の API をクエリしようとしましたが、有効なクエリを形成できませんでした:
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 を取得する方法を知りたいです。

Update1:パブリック リポジトリに公開されたパッケージについてです。

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 に答える