Pull Requestを作成する際、Pull Requestの作成者をassigneesに指定する運用がある。
忘れてしまうことが多々あるので、GitHub Actionsを使ってアサインする作業を自動化する。
ただし次に該当するPull Requestには、アサインしないようにした。
- Dependabotが作成したPull Request
- 既にアサインされているPull Request
.github/workflows/assign-creator.yml
name: Assign creator
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 }}