LoginSignup
0
1

GitHub Actionsを使ってPR時に自動でreviewersアサインと担当者アサインをする

Last updated at Posted at 2023-12-21

はじめに

GitLab時には、MRテンプレートにて、reviewersアサインをしていました。

やり方はいたくシンプルで、

.gitlab/merge_request_templates/default_template.md
.....


/assign_reviewer @hogehogehogehogehogehogehogehogeho

とユーザー名を指定するだけです。

ですが、GitHubではPRテンプレートに指定をすることができません。
調査した結果、GitHub Actionsでのやり方が判明したので、ここにメモ書きします。

やり方

こちらが参考になりました。

エラーが出たので少し手直ししました。
他に、専用ボットがあるのでそれを使っても良いと思います。

私は、github actionsを使いました。
理由としては、pull request時の条件文を少し変更したかったのと、初めてのactionsなので触ってみたかったことです。

とりあえず、コードを見ちゃおう

設定ファイルはymlで書きます。

.github/workflows/hogehoge.yml
# レビュワーの自動アサイン
name: auto-assign
on:
  pull_request:
    # どんなときに実行するか
    types: [opened, ready_for_review, reopened]
jobs:
  add-reviews:
    runs-on: ubuntu-latest
    # Actionsが必要とするpermissions
    permissions:
      pull-requests: write
      contents: read
    steps:
      # Node.js関連のエラーが出た。バージョン上げた。
      - uses: kentaro-m/auto-assign-action@v1.2.5
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: ".github/auto_assign.yml" # 呼び出し
.github/auto_assign.yml

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

# PR出した人を担当者にする
addAssignees: author

# PRのreviewersを指定
reviewers:
  - hogeo1
  - hogeo2
  - hogeo3

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

これらを配置すると、PRを出したときに、自動で動いてくれます。
Slackと連携していれば、通知時にメンションもされます。非常に便利です。

トラブルシューティング

スクリーンショット 2023-12-20 14.03.52.png

エラーが3つ出ました。

The following actions uses node12 which is deprecated and will be forced to run on node16: kentaro-m/auto-assign-action@v1.1.0. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/

Node.jsのバージョンが古いから、適用するkentaro-m/auto-assign-action@v1.1.0.のバージョンを上げてくれ ということだそうです。あげたところエラーは消えました。
ちなみに、chatgptに聞いたら即解決。

# Node.js関連のエラーが出た。バージョン上げた。
      - uses: kentaro-m/auto-assign-action@v1.2.5

Warning: Resource not accessible by integration

これはGitHub Actionsではよくあるエラーらしいです。
権限回りのエラーとのこと。

調べたところ、repositoryのsettingsにあるActionsの権限をread and write permissionsにすれば良い、という情報も出てきたのですが、ここで権限をいじるのはあまり良くないようです。

pull requests時の権限をread, writeにするだとかそういう権限設定が必要です。
今回は、pull requestsおよびcontentsの権限をactionsのymlに記載しました。

    # Actionsが必要とするpermissions
    permissions:
      pull-requests: write
      contents: read

詳細は以下のページで確認できます。

0
1
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
0
1