時々使うのですが、全然覚えられないのでメモすることにしました。
覚えられないし、どこに書いてあるかも見つけられなかったり…。
特定のリポジトリの、releaseやtagを取得するという話です。
Releases | GitHub Developer Guide
Repositories | GitHub Developer Guide
TerraformのGitHubリポジトリをお題にしてみましょう。
latest releaseを取得する
個人的には、1番使います。latest releaseの取得。
URLは、こんな感じ。
https://api.github.com/repos/:owner/:repo/releases/latest
Terraformでの例。このエントリの時点では、v0.13.5
です。
$ curl https://api.github.com/repos/hashicorp/terraform/releases/latest { "url": "https://api.github.com/repos/hashicorp/terraform/releases/32883332", "assets_url": "https://api.github.com/repos/hashicorp/terraform/releases/32883332/assets", "upload_url": "https://uploads.github.com/repos/hashicorp/terraform/releases/32883332/assets{?name,label}", "html_url": "https://github.com/hashicorp/terraform/releases/tag/v0.13.5", "id": 32883332, "node_id": "MDc6UmVsZWFzZTMyODgzMzMy", "tag_name": "v0.13.5", "target_commitish": "master", "name": "v0.13.5", "draft": false, "prerelease": false, "created_at": "2020-10-21T18:48:54Z", "published_at": "2020-10-21T19:33:54Z", "assets": [ ], "tarball_url": "https://api.github.com/repos/hashicorp/terraform/tarball/v0.13.5", "zipball_url": "https://api.github.com/repos/hashicorp/terraform/zipball/v0.13.5", "author": { "login": "hashicorp-ci", "id": 37350809, "node_id": "MDQ6VXNlcjM3MzUwODA5", "avatar_url": "https://avatars1.githubusercontent.com/u/37350809?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hashicorp-ci", "html_url": "https://github.com/hashicorp-ci", "followers_url": "https://api.github.com/users/hashicorp-ci/followers", "following_url": "https://api.github.com/users/hashicorp-ci/following{/other_user}", "gists_url": "https://api.github.com/users/hashicorp-ci/gists{/gist_id}", "starred_url": "https://api.github.com/users/hashicorp-ci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hashicorp-ci/subscriptions", "organizations_url": "https://api.github.com/users/hashicorp-ci/orgs", "repos_url": "https://api.github.com/users/hashicorp-ci/repos", "events_url": "https://api.github.com/users/hashicorp-ci/events{/privacy}", "received_events_url": "https://api.github.com/users/hashicorp-ci/received_events", "type": "User", "site_admin": false }, "body": "## 0.13.5 (October 21, 2020)\n\nBUG FIXES:\n* terraform: fix issue where the provider configuration was not properly attached to the configured provider source address by localname ([#26567](https://github.com/hashicorp/terraform/issues/26567))\n* core: fix a performance issue when a resource contains a very large and deeply nested schema ([#26577](https://github.com/hashicorp/terraform/issues/26577))\n* backend/azurerm: fix an issue when using the metadata host to lookup environments ([#26463](https://github.com/hashicorp/terraform/issues/26463))\n\n" }
jq
を使って、tag_name
だけ取得。
$ curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | jq .tag_name "v0.13.5"
クォートも外すとコマンドで使えそうですね。
$ curl -s https://api.github.com/repos/hashicorp/terraform/releases/latest | jq -r .tag_name v0.13.5
特定のreleaseを取得する
特定のreleaseをid指定で取得します。
https://api.github.com/repos/:owner/:repo/releases/:release_id
この場合のidは、こんな感じです。これでTerraform 0.13.0を指します。
$ curl https://api.github.com/repos/hashicorp/terraform/releases/29526969 { "url": "https://api.github.com/repos/hashicorp/terraform/releases/29526969", "assets_url": "https://api.github.com/repos/hashicorp/terraform/releases/29526969/assets", "upload_url": "https://uploads.github.com/repos/hashicorp/terraform/releases/29526969/assets{?name,label}", "html_url": "https://github.com/hashicorp/terraform/releases/tag/v0.13.0", "id": 29526969, "node_id": "MDc6UmVsZWFzZTI5NTI2OTY5", "tag_name": "v0.13.0", "target_commitish": "master", "name": "v0.13.0", "draft": false, "prerelease": false, "created_at": "2020-08-10T17:46:08Z", "published_at": "2020-08-10T18:03:34Z", "assets": [ ], "tarball_url": "https://api.github.com/repos/hashicorp/terraform/tarball/v0.13.0", "zipball_url": "https://api.github.com/repos/hashicorp/terraform/zipball/v0.13.0", "author": { "login": "hashicorp-ci", "id": 37350809, "node_id": "MDQ6VXNlcjM3MzUwODA5", "avatar_url": "https://avatars1.githubusercontent.com/u/37350809?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hashicorp-ci", "html_url": "https://github.com/hashicorp-ci", "followers_url": "https://api.github.com/users/hashicorp-ci/followers", "following_url": "https://api.github.com/users/hashicorp-ci/following{/other_user}", "gists_url": "https://api.github.com/users/hashicorp-ci/gists{/gist_id}", "starred_url": "https://api.github.com/users/hashicorp-ci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hashicorp-ci/subscriptions", "organizations_url": "https://api.github.com/users/hashicorp-ci/orgs", "repos_url": "https://api.github.com/users/hashicorp-ci/repos", "events_url": "https://api.github.com/users/hashicorp-ci/events{/privacy}", "received_events_url": "https://api.github.com/users/hashicorp-ci/received_events", "type": "User", "site_admin": false }, "body": "...省略..." }
releaseをtag名で取得する
id指定ではさすがにちょっと…なので、tag名指定で。
https://api.github.com/repos/:owner/:repo/releases/tags/:tag
v0.13.2
での例。
$ curl https://api.github.com/repos/hashicorp/terraform/releases/tags/v0.13.2 { "url": "https://api.github.com/repos/hashicorp/terraform/releases/30591217", "assets_url": "https://api.github.com/repos/hashicorp/terraform/releases/30591217/assets", "upload_url": "https://uploads.github.com/repos/hashicorp/terraform/releases/30591217/assets{?name,label}", "html_url": "https://github.com/hashicorp/terraform/releases/tag/v0.13.2", "id": 30591217, "node_id": "MDc6UmVsZWFzZTMwNTkxMjE3", "tag_name": "v0.13.2", "target_commitish": "master", "name": "v0.13.2", "draft": false, "prerelease": false, "created_at": "2020-09-02T14:36:55Z", "published_at": "2020-09-02T14:51:01Z", "assets": [ ], "tarball_url": "https://api.github.com/repos/hashicorp/terraform/tarball/v0.13.2", "zipball_url": "https://api.github.com/repos/hashicorp/terraform/zipball/v0.13.2", "author": { "login": "hashicorp-ci", "id": 37350809, "node_id": "MDQ6VXNlcjM3MzUwODA5", "avatar_url": "https://avatars1.githubusercontent.com/u/37350809?v=4", "gravatar_id": "", "url": "https://api.github.com/users/hashicorp-ci", "html_url": "https://github.com/hashicorp-ci", "followers_url": "https://api.github.com/users/hashicorp-ci/followers", "following_url": "https://api.github.com/users/hashicorp-ci/following{/other_user}", "gists_url": "https://api.github.com/users/hashicorp-ci/gists{/gist_id}", "starred_url": "https://api.github.com/users/hashicorp-ci/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/hashicorp-ci/subscriptions", "organizations_url": "https://api.github.com/users/hashicorp-ci/orgs", "repos_url": "https://api.github.com/users/hashicorp-ci/repos", "events_url": "https://api.github.com/users/hashicorp-ci/events{/privacy}", "received_events_url": "https://api.github.com/users/hashicorp-ci/received_events", "type": "User", "site_admin": false }, "body": "## 0.13.2 (September 02, 2020)\n\nNEW FEATURES:\n\n* **Network-based Mirrors for [Provider Installation](https://www.terraform.io/docs/commands/cli-config.html#provider-installation)**: As an addition to the existing capability of \"mirroring\" providers into the local filesystem, a network mirror allows publishing copies of providers on an HTTP server and using that as an alternative source for provider packages, for situations where directly accessing the origin registries is impossible or undesirable. ([#25999](https://github.com/hashicorp/terraform/issues/25999))\n\nENHANCEMENTS:\n\n* backend/http: add support for configuration by environment variable. ([#25439](https://github.com/hashicorp/terraform/issues/25439))\n* command: Add support for provider redirects to `0.13upgrade`. If a provider in the Terraform Registry has moved to a new namespace, the `0.13upgrade` subcommand now detects this and follows the redirect where possible. ([#26061](https://github.com/hashicorp/terraform/issues/26061))\n* command: Improve `init` error diagnostics when encountering what appears to be an in-house provider required by a pre-0.13 state file. Terraform will now display suggested `terraform state replace-provider` commands which will fix this specific problem. ([#26066](https://github.com/hashicorp/terraform/issues/26066))\n\nBUG FIXES:\n\n* command: Warn instead of error when the `output` subcommand with no arguments results in no outputs. This aligns the UI to match the 0 exit code in this situation, which is notable but not necessarily an error. ([#26036](https://github.com/hashicorp/terraform/issues/26036))\n* terraform: Fix crashing bug when reading data sources during plan with blocks backed by objects, not collections ([#26028](https://github.com/hashicorp/terraform/issues/26028))\n* terraform: Fix bug where variables values were asked for twice on the command line and provider input values were asked for but not saved ([#26063](https://github.com/hashicorp/terraform/issues/26063))\n\n" }
releaseやtagの一覧を取得
一覧取得。
release。
https://api.github.com/repos/:owner/:repo/releases
$ curl https://api.github.com/repos/hashicorp/terraform/releases
tags。
https://api.github.com/repos/:owner/:repo/tags
$ curl https://api.github.com/repos/hashicorp/terraform/tags