LoginSignup
8
5

More than 3 years have passed since last update.

GitHub Actionsでプルリクエストのレビュワーを自動アサインする手順

Posted at

やりたいこと

以下の条件を満たす場合、Reviewers, Assigneesに指定のメンバーを自動で設定する。

  • Pull Requestの状態が Open, Ready for review になった時
  • かつ、Pull Requestに review request チーム名 のラベルが付与されている

使用したGitHub Actions

今回はこちらのActionを使用させていただきました。
https://github.com/marketplace/actions/auto-assign-action

手順

Usageをベースに条件を追加します。
ここではチーム名はgremlins、自分のユーザ名をgizmoとします。

yamlファイルの作成

.github/workflows/pull_request.yml

# labelに基づいてアサイン、レビュワーを設定する
name: auto-assign
on:
  pull_request:
    types: [opened, ready_for_review]
jobs:
  add-reviews:
    if: contains(github.event.pull_request.labels.*.name, 'gremlins') && contains(github.event.pull_request.labels.*.name, 'review request')
    runs-on: ubuntu-latest
    steps:
      - uses: kentaro-m/auto-assign-action@v1.1.0
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: ".github/auto_assign_gremlins.yml"

.github/auto_assign_gremlins.yml


# Set to true to add reviewers to pull requests
addReviewers: true

# Set to true to add assignees to pull requests
addAssignees: true

# A list of reviewers to be added to pull requests (GitHub user name)
reviewers:
  - gizmo
  - stripe
  - brownie
  - penny
  - greta


# A number of reviewers added to the pull request
# Set 0 to add all the reviewers (default: 0)
numberOfReviewers: 0

Personal Access Tokenを作成する

https://github.com/settings/tokens
※workflowにチェックをつけること

git push

$ curl -u {username}:{token} https://api.github.com/user
$ git push -u origin {branch_name}

Pull Requestを作成する

  • ラベルにreview request, gremlinsを設定する

Checksタブを確認

Run kentaro-m/auto-assign-action@v1.1.04s
Added assignees to PR #1: stripe, brownie, penny, greta
Run kentaro-m/auto-assign-action@v1.1.0
Added reviewers to PR #1: stripe, brownie, penny, greta
Added assignees to PR #1: stripe, brownie, penny, greta

このようにログが表示され、Reviewer, Assigneesに自分以外のメンバー全員が設定されたら成功です。
文法が間違っている等、問題がある場合はエラーが表示されます。

補足情報

現在Pull Requestに設定されているラベル情報(github.event.pull_request.labels.*.name)などのコンテキストは以下をpushすることでPull RequestのChecksタブから確認できます。
引用: https://help.github.com/ja/actions/reference/context-and-expression-syntax-for-github-actions#contexts

on: push

jobs:
  one:
    runs-on: ubuntu-16.04
    steps:
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"
      - name: Dump job context
        env:
          JOB_CONTEXT: ${{ toJson(job) }}
        run: echo "$JOB_CONTEXT"
      - name: Dump steps context
        env:
          STEPS_CONTEXT: ${{ toJson(steps) }}
        run: echo "$STEPS_CONTEXT"
      - name: Dump runner context
        env:
          RUNNER_CONTEXT: ${{ toJson(runner) }}
        run: echo "$RUNNER_CONTEXT"
      - name: Dump strategy context
        env:
          STRATEGY_CONTEXT: ${{ toJson(strategy) }}
        run: echo "$STRATEGY_CONTEXT"
      - name: Dump matrix context
        env:
          MATRIX_CONTEXT: ${{ toJson(matrix) }}
        run: echo "$MATRIX_CONTEXT"

他に使用できる関数などはこちらに記載されています。
https://help.github.com/ja/actions/reference/context-and-expression-syntax-for-github-actions#operators

8
5
0

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
8
5