GitHub Projects へ draft issue を CLI から作成する gh projects item-create

GitHub Projects へ draft issue を CLI から作成する gh projects item-create コマンドをご紹介します。

GitHub | ギットハブ

事前準備 scopes: project の権限付与

scopes: project の権限が無いと gh projects コマンドを利用できないので gh auth refresh -s project で権限付与します。

$ gh auth status
github.com
  ✓ Logged in to github.com as shige (/Users/your_username/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: gho_************************************
  ✓ Token scopes: gist, read:org, repo, workflow
$ gh auth refresh -s project
? Authenticate Git with your GitHub credentials? Yes

! First copy your one-time code: XXXX-XXXX
Press Enter to open github.com in your browser... 
$ gh auth status
github.com
  ✓ Logged in to github.com as shige (/Users/your_username/.config/gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: gho_************************************
  ✓ Token scopes: gist, project, read:org, repo, workflow

gh-projects 拡張をインストール

gh extension install github/gh-projects

gh projects item-create でのヘルプ

$ gh projects item-create
Usage:
  projects item-create [number] [flags]

Examples:

# create a draft issue in the current user's project 1 with title "new item" and body "new item body"
gh projects item-create 1 --user "@me" --title "new item" --body "new item body"

# create a draft issue in user monalisa's project 1 with title "new item" and body "new item body"
gh projects item-create 1 --user monalisa --title "new item" --body "new item body"

# create a draft issue in org github's project 1 with title "new item" and body "new item body"
gh projects item-create 1 --org github --title "new item" --body "new item body"

# add --format=json to output in JSON format


Flags:
      --body string     Body of the draft issue item.
      --format string   Output format, must be 'json'.
  -h, --help            help for item-create
      --org string      Login of the organization owner.
      --title string    Title of the draft issue item.
      --user string     Login of the user owner. Use "@me" for the current user.

required flag(s) "title" not set

gh projects item-create で draft issue を作成

gh projects item-create コマンドで GitHub Projects へ draft issue を作成したサンプルスクリプトは以下の通りです。

YOUR_GH_PJ_NUM=1
gh projects item-create $YOUR_GH_PJ_NUM 
--org codenote-net 
--title "new item" 
--body "new item body"

以上、GitHub Projects へ draft issue を CLI から追加する gh projects item-create コマンドを活用していきたい、現場からお送りしました。

参考情報