実現したかったこと
プルリクエストを作成しレビュー依頼をする際、いつも特定の人にレビュー依頼をしている状況。
そのためプロジェクト内のdevelopブランチで、mainブランチ向けにプルリクエストが開かれた時には、いつもその特定の人を自動でレビュワーとして選択してくれるよう自動化したかった。
やったこと
使用したactionとしてはnecojackarc/auto-request-review
というものを使用した。
https://github.com/marketplace/actions/auto-request-review
コード
name: Auto Request Review
on:
pull_request:
branches:
- main
types: [opened, reopened]
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
auto-request-review:
name: Auto Request Review
runs-on: ubuntu-latest
steps:
- name: Request review based on files changes and/or groups the author belongs to
uses: necojackarc/auto-request-review@v0.13.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
config: .github/reviewers.yml # Config file location override
# Look for config locally during run instead of in repo.
# For instance, if you'd like to use a config file stored in external storage,
# you can fetch it before you run this action, then let this action pick it up with `use_local: true`.
# This defaults to false if not specified.
# See https://github.com/necojackarc/auto-request-review/issues/76 for more details.
use_local: false
jobsのあたりに関しては、このactionのドキュメントに書いてある通りに記載した。
このactionのトリガー(動くタイミングのようなもの)は、以下のようにした。
on:
pull_request: ## プルリクエスト
branches: ## ここにはtarget_branchを記載する
- main
types: [opened, reopened] # openしたとき、もしくは、リオープンしたとき
注意
ここが意外とハマった点だった。プルリクエストを作成したブランチ名を記載するのではなく、プルリクエストをマージしたいブランチ名を記載する。(branchesはtarget_branchを書きましょう)
あと、config: .github/reviewers.yml
でレビュワーの設定ファイルを用意している。それが以下。
reviewers:
# Reviewers per author.
# Keys are reviewees, each of which has an array of reviewers.
defaults:
- gorira-san
files:
# Keys are glob expressions.
# You can assign groups defined above as well as GitHub usernames.
'**':
- gorira-san
options:
ignore_draft: true
ignored_keywords:
- DO NOT REVIEW
これでいける。この.github/reviewers.yml
に関しては結構細かくパターンやレビュワーのグループを指定したりすることができる。機会があったら色々やってみようと思う。
がんばろうぜ。