LoginSignup
0
0

More than 5 years have passed since last update.

「あー、あのブランチどのPullRequestだっけー?」をワンライナーで調べる

Last updated at Posted at 2019-03-26

たまにあるよね。

出来上がったものがこちら

※見やすさのために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 の アクセストークン を設定してね
  • :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"}

https://developer.github.com/v3/pulls/#list-pull-requests には、そもそも head, base に対しての検索クエリが投げられるので、検索したいブランチが1個であればこちらのほうが早い。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0