パブリックリポジトリの場合
curl -H "Accept: application/vnd.github.cloak-preview" https://api.github.com/search/issues?q=is:pr+repo:(オーナー名)/(リポジトリ名)+sha:(コミットハッシュ)
URIは.../search/issues
ですが、クエリストリングにis:pr
とすることで、PRの情報を取得できるところがポイントです。
例えば、
の
というコミットは、コミットハッシュ6f615b425c2647ed2c19c9a4e8f0513591a743dc
ですが、
curl -H "Accept: application/vnd.github.cloak-preview" https://api.github.com/search/issues?q=is:pr+repo:laravel/laravel+sha:6f615b425c2647ed2c19c9a4e8f0513591a743dc
とすると、以下の結果が返ってきます。
{
"total_count": 1,
"incomplete_results": false,
"items": [
{
"url": "https://api.github.com/repos/laravel/laravel/issues/5173",
"repository_url": "https://api.github.com/repos/laravel/laravel",
"labels_url": "https://api.github.com/repos/laravel/laravel/issues/5173/labels{/name}",
"comments_url": "https://api.github.com/repos/laravel/laravel/issues/5173/comments",
"events_url": "https://api.github.com/repos/laravel/laravel/issues/5173/events",
"html_url": "https://github.com/laravel/laravel/pull/5173",
"id": 535748469,
"node_id": "MDExOlB1bGxSZXF1ZXN0MzUxNDA1Mjk1",
"number": 5173,
"title": "[6.x] DRY up path to /home",
"user": {
"login": "taylorotwell",
// 以下略
- PRのURLは、
html_url
に(https://github.com/laravel/laravel/pull/5173) - PR名は、
title
に([6.x] DRY up path to /home)
にあります。
なお、リクエスト時に指定するコミットハッシュはフル桁でなくても構いません。
プライベートリポジトリの場合
-H "Authorization: token xxxx"
を追加します。
curl -H "Authorization: token xxxx" -H "Accept: application/vnd.github.cloak-preview" https://api.github.com/search/issues?q=is:pr+repo:(オーナー名)/(リポジトリ名)+sha:(コミットハッシュ)
トークンには、
- Settings > Developer settings > Personal access tokens
で、Full control of private repositories
の権限を付けておく必要があります。
