0
0

GitHub Actionsでコードレビュー依頼を自動化する [Auto Request Review]

Last updated at Posted at 2024-05-24

実現したかったこと

プルリクエストを作成しレビュー依頼をする際、いつも特定の人にレビュー依頼をしている状況。
そのためプロジェクト内のdevelopブランチで、mainブランチ向けにプルリクエストが開かれた時には、いつもその特定の人を自動でレビュワーとして選択してくれるよう自動化したかった。

やったこと

使用したactionとしてはnecojackarc/auto-request-reviewというものを使用した。
https://github.com/marketplace/actions/auto-request-review

コード

.github/workflows/auto_request_review.yml
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でレビュワーの設定ファイルを用意している。それが以下。

.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に関しては結構細かくパターンやレビュワーのグループを指定したりすることができる。機会があったら色々やってみようと思う。

がんばろうぜ。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0