「あー、あのブランチどのPullRequestだっけー?」をワンライナーで調べる
たまにあるよね。
出来上がったものがこちら
※見やすさのために3行に分けてます
curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com/repos/:owner/:repo/pulls \
| jq -r '.[]|{ url: .html_url, into: .base.ref, from: .head.ref }|@text' \
| grep my_branch
使い方
-
OAUTH-TOKEN
に Github のアクセストークン
を設定してね- https://qiita.com/kz800/items/497ec70bff3e555dacd0
- public なリポジトリの場合は Authorization ヘッダなしでもOKだよ
-
:owner
と:repo
に Github のオーナー
とリポジトリ
を入れてね -
my_branch
に探したいブランチ名
を入れてね
例
$ curl https://api.github.com/repos/facebook/react/pulls \
| jq -r '.[]|{ url: .html_url, into: .base.ref, from: .head.ref }|@text' \
| grep coverage
{"url":"https://github.com/facebook/react/pull/15159","into":"master","from":"increase-test-coverage"}
{"url":"https://github.com/facebook/react/pull/15130","into":"master","from":"test/eslint-deps-coverage"}
応用のアイディア
- jq のクエリを変えればいろいろ柔軟に対応できるよ。
-
.base.ref
,.head.ref
のかわりに.base.label
,.head.label
を使うと、fork元も表示されたり。
-
- https://api.github.com/repos/:owner/:repo/pulls?state=closed とすればクローズされたPRも見れるのでAPIドキュメントを参照すること。
参考
https://developer.github.com/v3/#authentication
https://developer.github.com/v3/pulls/#list-pull-requests
https://stedolan.github.io/jq/manual/
別解
curl "https://api.github.com/repos/facebook/react/pulls?state=closed&head=Jessidhia:useref-warning" \
| jq -r '.[]|{ url: .html_url, into: .base.label, from: .head.label }|@text'
{"url":"https://github.com/facebook/react/pull/14894","into":"facebook:master","from":"Jessidhia:useref-warning"}
curl "https://api.github.com/repos/facebook/react/pulls?state=closed&head=Jessidhia:useref-warning" \
| jq -r '.[]|{ url: .html_url, into: .base.label, from: .head.label }|@text'
{"url":"https://github.com/facebook/react/pull/14894","into":"facebook:master","from":"Jessidhia:useref-warning"}
https://developer.github.com/v3/pulls/#list-pull-requests には、そもそも head
, base
に対しての検索クエリが投げられるので、検索したいブランチが1個であればこちらのほうが早い。
Author And Source
この問題について(「あー、あのブランチどのPullRequestだっけー?」をワンライナーで調べる), 我々は、より多くの情報をここで見つけました https://qiita.com/yu0819ki/items/ed580514c0d0a920e623著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .