🐕

自分のプルリクエストに自分を自動でアサインするGithub Actionが便利

2024/03/15に公開

自分が出したプルリクエストに自分を毎回アサインするのだけど、その作業が面倒だしときどき忘れちゃうので自動でやってくれるGitHub Actionを書きました。
Dependabotの場合はスキップされるようになっています。コピペで使えると思います。

.github/workflows/auto-assign.yml

name: Auto assign

on:
  pull_request:
    types: ["opened"]

permissions:
  pull-requests: write
  repository-projects: read

jobs:
  assign:
    if: ${{ github.event.pull_request.user.login != 'dependabot[bot]' || toJSON(github.event.pull_request.assignees) == '[]' }}
    runs-on: ubuntu-latest
    timeout-minutes: 1
    steps:
      - run: gh pr edit "$PULL_NUMBER" --repo "$REPOSITORY" --add-assignee "$CREATOR"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REPOSITORY: ${{ github.repository }}
          PULL_NUMBER: ${{ github.event.pull_request.number }}
          CREATOR: ${{ github.event.pull_request.user.login }}

以下の箇所で、Dependabotによって作られたプルリクエストは自動アサインはスキップしている。また、プルリクエストのアサイニーが誰もいない場合にプルリクエストの作成者をアサイニーに自動アサインするようにしている。

if: ${{ github.event.pull_request.user.login != 'dependabot[bot]' || toJSON(github.event.pull_request.assignees) == '[]' }}

これ、GitHubが公式で用意してもいいくらいの機能だと思うんですが・・・🤔

Discussion