423 words, 3 min read

When you’re the only maintainer of a repository, every new issue and pull request is yours anyway. Still, I like having the assignee field filled in. It makes GitHub’s “assigned to me” filters useful and keeps things working if more people join later. Doing this by hand is the kind of chore I forget, so I automated it with a small GitHub Actions workflow.

The workflow

I used gustavofreze/auto-assign. It assigns the issue or pull request that triggered the workflow to the logins you specify. Create .github/workflows/auto-assign.yml:

name: Auto assign

on:
  issues:
    types:
      - opened
  pull_request:
    types:
      - opened

jobs:
  run:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      pull-requests: write
    steps:
      - name: Auto assigns assignees
        uses: gustavofreze/auto-assign@3.0.0
        with:
          assignees: 'your-github-login'
          assignment_options: 'ISSUE,PULL_REQUEST'

How it works

  • Triggers: The workflow runs when an issue or pull request is opened. For these events, the action only touches the item that triggered the run, and only if it has no assignee yet. A pull request event never assigns issues, and an issue event never assigns pull requests.
  • assignment_options: The default is ISSUE. Set it to ISSUE,PULL_REQUEST to cover both.
  • Permissions: The job needs issues: write and pull-requests: write. The default workflow token is enough, so there’s no secret to create or rotate.
  • Pinning: I pinned the action to the 3.0.0 tag. For stricter supply-chain hygiene, you can pin it to a commit SHA instead.

Options worth knowing about

The action has a few inputs I didn’t need but you might:

Input Default What it does
skip_bots false Skips items opened by bots such as dependabot[bot]
skip_drafts false Skips draft pull requests
assign_author false Also assigns the author of the item
allow_no_assignees false Lets the run succeed when nobody can be assigned

Caveats

  • Forks: On the pull_request event, pull requests from forks get a read-only token, so assignment will fail for them. That doesn’t matter for a personal repo. If you accept outside contributions, you would need pull_request_target, which has its own security trade-offs.
  • Default branch: The issues trigger only fires once the workflow file is on the default branch. The pull_request trigger uses the workflow file from the pull request itself, so the PR that introduces the workflow is its first test.

It’s a 23-line file that removes one small manual step. I opened the pull request that adds it on a branch of its own so I could see whether it assigned itself.