prコマンドに関しては量が多いので、前半、後半に分けます。
gh prコマンド
gh pr
コマンドは、プルリクの作成やマージ、ステータスを確認することができます。
gh pr <command> [flags]
で実行し、<command>
には以下の12個が利用できます。
checkout: Check out a pull request in git
checks: Show CI status for a single pull request
close: Close a pull request
create: Create a pull request
diff: View changes in a pull request
list: List and filter pull requests in this repository
merge: Merge a pull request
ready: Mark a pull request as ready for review
reopen: Reopen a pull request
review: Add a review to a pull request
status: Show status of relevant pull requests
view: View a pull request
prコマンドでは、基本的にブランチやPR番号を指定します。 ちなみに何も指定しないとカレントブランチを指定するようです。 https://github.com/cli/cli/blob/b2e36a0979a06b94bf364552a856c166cd415234/pkg/cmd/pr/shared/lookup.go#L34-L37
gh pr create
gh pr create
コマンドは、PRを作成することができるコマンドです。
gh pr create [flags]
で実行します。
フラグ
以下のフラグが利用できます。
flags short | flags long | 説明 |
---|---|---|
-a | --assignee | assigneeを指定 |
-B | --base | マージ先ブランチ |
-b | --body | PRのbody(説明) |
-d | --draft | draftでPRを作成 |
-f | --fill | titleとbodyを入力しない。commit情報を使って埋める。 |
-H | --head | PRを作成したいブランチを指定(デフォルトでカレントブランチ) |
-l | --label | ラベルを指定 |
-m | --milestone | マイルストーンを指定 |
-p | --project | プロジェクトを指定 |
-r | --reviewer | reviewerを指定 |
-t | --title | タイトルを指定 |
-w | --web | PR作成画面をブラウザで開く |
対話形式で作成
$ gh pr create
? Where should we push the 'feature/hoge' branch? [Use arrows to move, type to filter]
> JIIOryo/foo
Skip pushing the branch
Cancel
タイトルを入力します。
? Title (add hoge.txt) add HOGE
e
を押すとエディタが開き、PRの文章を記述できます。
? Body [(e) to launch vim, enter to skip]
submitするとPRが作成されます。
? What's next? [Use arrows to move, type to filter]
> Submit
Continue in browser
Add metadata
Cancel
コマンド一発で作成
$ gh pr create -t 'add FUGA' -b '# fugafuga' -m foo -l hoge -B feature/hoge -d
これで一発でこのPRができます。スゴい。
この例では-m
がマイルストーンで、-l
がラベル、-B
がマージ先ブランチ、-d
がドラフトPRです。 ラベルなど、複数ある場合は,
でつなげる。
pushしていない場合は対話形式同様pushする?って聞かれる。
? Where should we push the 'feature/foo' branch? JIIOryo/foo
help
$ gh pr create --help
Create a pull request on GitHub.
When the current branch isn't fully pushed to a git remote, a prompt will ask where
to push the branch and offer an option to fork the base repository. Use '--head' to
explicitly skip any forking or pushing behavior.
A prompt will also ask for the title and the body of the pull request. Use '--title'
and '--body' to skip this, or use '--fill' to autofill these values from git commits.
USAGE
gh pr create [flags]
FLAGS
-a, --assignee login Assign people by their login
-B, --base branch The branch into which you want your code merged
-b, --body string Body for the pull request
-d, --draft Mark pull request as a draft
-f, --fill Do not prompt for title/body and just use commit info
-H, --head branch The branch that contains commits for your pull request (default: current branch)
-l, --label name Add labels by name
-m, --milestone name Add the pull request to a milestone by name
-p, --project name Add the pull request to projects by name
-r, --reviewer login Request reviews from people by their login
-t, --title string Title for the pull request
-w, --web Open the web browser to create a pull request
INHERITED FLAGS
--help Show help for command
-R, --repo OWNER/REPO Select another repository using the OWNER/REPO format
EXAMPLES
$ gh pr create --title "The bug is fixed" --body "Everything works again"
$ gh pr create --reviewer monalisa,hubot
$ gh pr create --project "Roadmap"
$ gh pr create --base develop --head monalisa:feature
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
gh pr close
gh pr close
コマンドは、PRをクローズできるコマンドです。
gh pr close {<number> | <url> | <branch>} [flags]
で実行します。 PRの指定方法はbranch
, PR番号
, url
の3種類あります。
フラグ
以下のフラグが利用できます。
flags short | flags long | 説明 |
---|---|---|
-d | --delete-branch | ブランチを削除する |
ブランチ名で指定
これが一番直感的でわかりやすいです。
$ gh pr close feature/fuga
✔ Closed pull request #5 (add FUGA)
PR番号で指定
$ gh pr close 5
✔ Closed pull request #5 (add FUGA)
URLで指定
$ gh pr close https://github.com/JIIOryo/foo/pull/5
✔ Closed pull request #5 (add FUGA)
ブランチも消す
-d
オプションをつけることで、ブランチごと削除することが可能です。これは便利。
$ gh pr close feature/fuga -d
✔ Closed pull request #5 (add FUGA)
✔ Deleted branch feature/fuga and switched to branch master
help
$ gh pr close --help
Close a pull request
USAGE
gh pr close {<number> | <url> | <branch>} [flags]
FLAGS
-d, --delete-branch Delete the local and remote branch after close
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 reopen
gh pr reopen
コマンドは、クローズしたPRを再び開くができます。
gh pr reopen {<number> | <url> | <branch>} [flags]
で実行する。
ReopenするPRを指定方法はbranch
, PR番号
, url
の3種類あります。
PR番号でreopen
$ gh pr reopen 5
✔ Reopened pull request #5 (add FUGA)
URLで指定
$ gh pr reopen https://github.com/JIIOryo/foo/pull/5
✔ Reopened pull request #5 (add FUGA)
ブランチ名で指定
自分の場合ブランチ名で指定してもうまくいかなかったです。
$ gh pr reopen feature/fuga
no open pull requests found for branch "feature/fuga"
help
$ gh pr reopen --help
Reopen a pull request
USAGE
gh pr reopen {<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 list
gh pr list
コマンドは、PRの一覧を表示するコマンドです。
gh pr list [flags]
で実行する。
フラグ
以下のフラグが利用できます。
flags short | flags long | 説明 |
---|---|---|
-a | --assignee | assigneeでフィルタリング |
-B | --base | ベースブランチでフィルタリング |
-l | --label | ラベルでフィルタリング |
-L | --limit | 最大表示個数を指定(デフォルト30) |
-s | --state | 状態を指定 open ,closed ,merged ,all が指定可能 (デフォルトopen ) |
-w | --web | ブラウザでPR一覧のページを開く |
例
$ gh pr list
Showing 4 of 4 open pull requests in JIIOryo/foo
#13 add fugahoge feature/fugahoge
#9 add hogefuga feature/hogefuga
#6 add FOO feature/foo
#1 add HOGE feature/hoge
$ gh pr list -B master -l hoge -L 3
Showing 1 of 1 pull request in JIIOryo/foo that matches your search
#1 add HOGE feature/hoge
help
$ gh pr list --help
List and filter pull requests in this repository
USAGE
gh pr list [flags]
FLAGS
-a, --assignee string Filter by assignee
-B, --base string Filter by base branch
-l, --label strings Filter by labels
-L, --limit int Maximum number of items to fetch (default 30)
-s, --state string Filter by state: {open|closed|merged|all} (default "open")
-w, --web Open the browser to list the pull requests
INHERITED FLAGS
--help Show help for command
-R, --repo OWNER/REPO Select another repository using the OWNER/REPO format
EXAMPLES
$ gh pr list --limit 999
$ gh pr list --state closed
$ gh pr list --label "priority 1" --label "bug"
$ gh pr list --web
LEARN MORE
Use 'gh <command> <subcommand> --help' for more information about a command.
Read the manual at https://cli.github.com/manual
gh pr diff
gh pr diff
コマンドは、PRのdiffを確認することができるコマンドです。
gh pr diff [<number> | <url> | <branch>] [flags]
で実行する。
フラグ
以下のフラグが利用できます。
flags short | flags long | 説明 |
---|---|---|
--color | 色。always , never , auto のうちいずれかを選択。(デフォルトauto ) |
例
diffに関してはブラウザの方がわかりやすいので、これで-w
フラグが利用できたら便利なんですけどね。
help
$ gh pr diff --help
View changes in a pull request
USAGE
gh pr diff [<number> | <url> | <branch>] [flags]
FLAGS
--color string Use color in diff output: {always|never|auto} (default "auto")
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