GitHubのラベルをコマンド一つでセットアップ

はじめに

GitHubのラベルをリポジトリごとに追加・変更するのは非常に手間がかかります。
本エントリではラベルの一覧をJSONファイルで管理し、コマンド一つで指定のリポジトリに反映する方法をまとめます。

github-label-setupのインストール

github-label-setup を使用します。

github.com

次のコマンドでインストールしてください。

$ npm install @azu/github-label-setup -g

GitHubアクセストークンの作成

以下のURLからアクセストークンを作成します。

https://github.com/settings/tokens

repo スコープにチェックを入れてください。

f:id:hiroki-sawano:20200713222508p:plain

ラベル一覧の作成

標準提供のラベル一覧を参考に labels.json を作成します。
このファイルはラベルセットアップ用のリポジトリでバージョン管理しておくと良いと思います。

[
  {
    "name": "duplicate",
    "color": "ededed",
    "description": "This issue or Pull Request already exists"
  },
  ...
  {
    "name": "Type: Question",
    "color": "cc317c",
    "description": "Further information is requested",
    "aliases": [
      "question"
    ]
  }
]

ラベルのセットアップ

ラベルのセットアップをしたいリポジトリをクローンしたディレクトリに移動します。

$ cd <your-repository>

実際に変更を加える前にドライラン( -d オプション)で変更内容を確認しておきます。
--tokenGitHubアクセストークンの作成で作成したトークンを指定し、 --labelsラベル一覧の作成で作成した lables.json を指定します。

$ github-label-setup -d -A --token <access-token> --labels /path/to/labels.json
Fetching labels from GitHub
Changed: the "duplicate" label in the repo is out of date. It will be updated to "duplicate" with color "#ededed" and description "This issue or Pull Request already exists".
Changed: the "help wanted" label in the repo is out of date. It will be updated to "help wanted" with color "#e99695" and description "Extra attention is needed".
Missing: the "Priority: Critical" label is missing from the repo. It will be created.
...

変更内容が期待通りであれば -d オプションを外し、実際に変更を加えます。

$ github-label-setup -A --token <access-token> --labels /path/to/labels.json

これでラベルの変更ができました。

f:id:hiroki-sawano:20200713224956p:plain