概要
GitHubでPull requestのLabels機能を使ってPull requestを管理します。

このブログポストでは、GitHub Actionsの 1 つであるPR Labels Checkerを使ってPull requestのLabelsをチェックする方法について説明します。
ブログシリーズ
このブログはシリーズで作成されました。次のリンクを通じて他のブログポストも確認してください。
- [GitHub Actions] Pull request のタイトルチェック
- [GitHub Actions] Release notes の自動化
- [GitHub Actions] Pull request のラベルチェック
PR Labels Checker
PR Labels CheckerはGitHub Actionsの 1 つで、Pull requestのLabelsをチェックする機能を提供しています。
GitHub Actions の作成
PR Labels Checkerを使ってPull requestのLabelsをチェックするGitHub Actionsを作成してみます。.github/workflows/pr-labels-checker.ymlファイルを作成し、次のように修正します。
name: PR Labels Checker
on:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
jobs:
pr_labels_checker:
permissions:
pull-requests: write
checks: write
runs-on: ubuntu-latest
steps:
- uses: danielchabr/[email protected]
with:
hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
githubToken: $
このGitHub ActionsはPull requestが作成されたり、Pull requestのLabelが追加または削除されたときに実行されます。
on:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
PR Labels Checker를 사용하기 위해서는 Pull request와 checks에 대한 권한이 필요합니다.
jobs:
pr_labels_checker:
permissions:
pull-requests: write
checks: write
このPR Labels Checkerを使ってPull requestのLabelsをチェックします。Labelをチェックするときは次のような条件を使うことができます。
- hasSome: カンマで区切られた Label リストで、PR はこの中の 1 つを必ず含める必要があります。
- hasAll: カンマで区切られた Label リストで、PR はこのリスト全てを含める必要があります。
- hasNone: カンマで区切られた Label リストで、PR はこのリストのどれも含めてはいけません。
- hasNotAll: カンマで区切られた Label リストで、PR はこのリスト全てを含めてはいけません。
このブログポストではhasSome条件を使いました。
hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
条件に含まれるLabelはRelease notes 自動化のために必要なリストです。詳細は次のリンクを参照してください。
githubToken: $
Release Drafter
私はRelease notesの自動化のためにRelease Drafterを使っています。Release DrafterはPull requestのLabelsを使ってRelease notesを自動で作成します。また、Pull requestのタイトルを見て自動でLabelsを設定する機能もあります。
そのため、Pull requestのLabelsが重要であり、Release Drafterが自動で設定してくれますが、これを確実にするためにPR Labels Checkerを使ってPull requestのLabelsをもう一度チェックしています。
このためのGitHub Actionsは次のようになっています。
name: Release Drafter
on:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
permissions:
contents: read
jobs:
update_release_draft:
permissions:
contents: write
pull-requests: write
checks: write
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: $
- uses: danielchabr/[email protected]
with:
hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
githubToken: $
Release Drafterを使ってPull requestのLabelsを自動で設定して、自動で設定されたPull requestのLabelsをPR Labels Checkerを使ってもう一度チェックするようにしました。
Release Drafterについて詳しくは次のリンクを参照してください。
完了
これでGitHub ActionsのPR Labels Checkerを使ってPull requestのLabelsをチェックする方法について説明しました。
Pull requestをLabelsを使って管理する場合や、私のようにRelease notesを自動化するためにRelease Drafterを使う方はPR Labels Checkerの導入を検討してみてください。
私のブログが役に立ちましたか?下にコメントを残してください。それは私にとって大きな大きな力になります!
アプリ広報
Dekuが開発したアプリを使ってみてください。Dekuが開発したアプリはFlutterで開発されています。興味がある方はアプリをダウンロードしてアプリを使ってくれると本当に助かります。






