GitHub CLIで作るPull RequestのDescriptionをVisual Studio Codeで書きたい

普段エディタとしてVisual Studio Codeを使っているので、Pull RequestのDescriptionもVisual Studio Codeで書きたい。
Visual Studio Codeを使えばGitHub CopilotによるサポートやVisual Studio Codeの拡張機能も利用できる。

Visual Studio CodeをGitHub CLIのエディタに設定する

GitHub CLI(ghコマンド)のエディタを設するには gh config set editor コマンドを使用する。

Visual Studio Codeをエディタに設定する場合、code --waitオプションを指定する。
--waitオプションは、VScodeでファイルを閉じるまでコマンドをブロック(待機)する。
--waitオプションを指定しないと、VScodeが起動した直後にコマンドが完了してしまう。

gh config set editor "code --wait"

このコマンドを実行すると~/.config/gh/config.ymlに以下のように設定が追加される。

editor: code --wait

Pull Requestのテンプレートを使う

Pull Requestのテンプレート.github/pull_request_template.mdを利用できる。 プロジェクトに.github/pull_request_template.mdを作成しておく。 gh pr createコマンドでPull Requestを作成する際、Bodyを空で作成する。 すると、VS Codeで開かれるファイルにテンプレートが展開される。