gh pr merge

gh pr mergeコマンドは、PRをマージすることができます。

gh pr merge [<number> | <url> | <branch>] [flags]で実行する。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-d --delete-branch ブランチを削除するか(デフォルト true)
-m --merge マージコミットを作成
-r --rebase リベース
-s --squash スカッシュマージ

対話形式で試す

mergeは、マージコミットを作成、リベース、スカッシュマージの3種類が利用できます。

$ gh pr merge
? What merge method would you like to use?  [Use arrows to move, type to filter]
> Create a merge commit
  Rebase and merge
  Squash and merge

ブランチを削除するか聞かれます。

? Delete the branch locally and on GitHub? (Y/n)

Done

✔ Merged pull request #7 (add baz)
✔ Deleted branch feature/baz and switched to branch master

コマンド一発でマージする

$ gh pr merge --squash feature/piyo
✔ Squashed and merged pull request #8 (add piyo)
✔ Deleted branch feature/piyo and switched to branch master

help

$ gh pr merge --help
Merge a pull request on GitHub.

By default, the head branch of the pull request will get deleted on both remote and local repositories.
To retain the branch, use '--delete-branch=false'.


USAGE
  gh pr merge [<number> | <url> | <branch>] [flags]

FLAGS
  -d, --delete-branch   Delete the local and remote branch after merge (default true)
  -m, --merge           Merge the commits with the base branch
  -r, --rebase          Rebase the commits onto the base branch
  -s, --squash          Squash the commits into one commit and merge it into the base branch

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh pr ready

gh pr readyコマンドは、draftPRをreview可能状態に変更するコマンドです。

gh pr ready [<number> | <url> | <branch>] [flags]で実行する。

最初はドラフト状態(グレーの状態)です。

スクリーンショット 2020-09-20 11.53.46.png

gh pr readyしてみます。 ReopenするPRを指定方法はbranch, PR番号, urlの3種類あります。 指定しない場合はカレントブランチを指定したことになります。

スクリーンショット 2020-09-20 11.53.53.png

PRのstatusがレビュー可能状態(緑)に変わりました。

スクリーンショット 2020-09-20 11.54.00.png

help

$ gh pr ready --help
Mark a pull request as ready for review

USAGE
  gh pr ready [<number> | <url> | <branch>] [flags]

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh pr status

gh pr statusコマンドは、PRのステータスを確認することができるコマンドです。

gh pr status [flags]で実行します。

draftはグレー、レビュー可能は緑色、Closedは赤に表示されました。

スクリーンショット 2020-09-20 23.02.57.png

help

$ gh pr status --help
Show status of relevant pull requests

USAGE
  gh pr status [flags]

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh pr review

gh pr reviewコマンドは、レビューをすることができるコマンドです。

gh pr review [<number> | <url> | <branch>] [flags]で実行します。

PRの指定方法はbranch, PR番号, urlの3種類あります。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-a --approve PRをapproveする
-b --body レビューのメッセージを指定
-c --comment PRのコメント (-bが必要)
-r --request-changes 変更依頼

対話形式でレビューする

coment, approve, request changesの3つから選ぶことができます。コメントしてみましょう。

$ gh pr review feature/foo
? What kind of review do you want to give?  [Use arrows to move, type to filter]
> Comment
  Approve
  Request changes

eを押すとエディタが開いてコメントを書くことができます。

? Review body [(e) to launch vim]

確認があるので、submitしましょう。

? Review body <Received>
Got:

  hoge

? Submit? (Y/n)

無事にレビューできました。

? Submit? Yes
- Reviewed pull request #6

対話形式でapproveする

approveを選択します。

$ gh pr review feature/foo
? What kind of review do you want to give?  [Use arrows to move, type to filter]
  Comment
> Approve
  Request changes

eを押すとエディタが開いてコメントを書くことができます。

? Review body [(e) to launch vim, enter to skip]

Approveのときのメッセージが確認できます。Submitしましょう。

? Review body <Received>
Got:

  LGTM🎉

? Submit? (Y/n)

コマンド一発でレビューする

-cはコメント、-aでapproveすることができます。 これらのメッセージは-bで指定します。

$ gh pr review feature/foo -c -b 'hoge'
- Reviewed pull request #6

help

$ gh pr review --help
Add a review to a pull request.

Without an argument, the pull request that belongs to the current branch is reviewed.


USAGE
  gh pr review [<number> | <url> | <branch>] [flags]

FLAGS
  -a, --approve           Approve pull request
  -b, --body string       Specify the body of a review
  -c, --comment           Comment on a pull request
  -r, --request-changes   Request changes on a pull request

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

EXAMPLES
  # approve the pull request of the current branch
  $ gh pr review --approve

  # leave a review comment for the current branch
  $ gh pr review --comment -b "interesting"

  # add a review for a specific pull request
  $ gh pr review 123

  # request changes on a specific pull request
  $ gh pr review 123 -r -b "needs more ASCII art"

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh pr checks

gh pr checksコマンドは、CIのステータスを取得できるコマンドです。

gh pr checks [flags]で実行します。

$ gh pr checks
All checks were successful
0 failing, 1 successful, and 0 pending checks

✓  ci/circleci: run    https://circleci.com/gh/JIIOryo/foo/2...

help

$ gh pr checks --help
Show CI status for a single pull request

USAGE
  gh pr checks [flags]

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh pr view

gh pr viewコマンドは、PRのタイトルやbodyの内容などの情報を表示するコマンドです。

gh pr view [<number> | <url> | <branch>] [flags]で実行します。 PRの指定方法はbranch, PR番号, urlの3種類あります。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
-w --web ブラウザで開く

今回はブランチ名から指定します。

$ gh pr view feature/hogefuga

スクリーンショット 2020-09-20 12.45.06.png

ブラウザで開く

カレントブランチ(指定なし)のPRをブラウザで開きたいときは-wフラグを利用します。

$ gh pr view -w
Opening github.com/JIIOryo/foo/pull/9 in your browser.
(ブラウザが開く)

これは便利。使えそう。

help

$ gh pr view --help
Display the title, body, and other information about a pull request.

Without an argument, the pull request that belongs to the current branch
is displayed.

With '--web', open the pull request in a web browser instead.


USAGE
  gh pr view [<number> | <url> | <branch>] [flags]

FLAGS
  -w, --web   Open a pull request in the browser

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual

gh pr checkout

gh pr checkoutコマンドは、指定したPR(ブランチ)にcheckoutするコマンドです。

gh pr checkout {<number> | <url> | <branch>} [flags]で実行します。

フラグ

以下のフラグが利用できます。

flags short flags long 説明
  --recurse-submodules 再帰的に全てのアクティブなサブモジュールを更新する

$ gh pr checkout feature/hogefuga
Switched to branch 'feature/hogefuga'
Already up to date.

ちなみに実装を見ると、ローカルにブランチがある場合、fetch checkout mergeを行い、そうでない場合はcheckout -bで新しいブランチを作成してくれているようですね。 https://github.com/cli/cli/blob/b2e36a0979a06b94bf364552a856c166cd415234/pkg/cmd/pr/checkout/checkout.go#L118-L133

help

$ gh pr checkout --help
Check out a pull request in git

USAGE
  gh pr checkout {<number> | <url> | <branch>} [flags]

FLAGS
  --recurse-submodules   Update all active submodules (recursively)

INHERITED FLAGS
      --help              Show help for command
  -R, --repo OWNER/REPO   Select another repository using the OWNER/REPO format

LEARN MORE
  Use 'gh <command> <subcommand> --help' for more information about a command.
  Read the manual at https://cli.github.com/manual