Skip to content

Instantly share code, notes, and snippets.

@heyhey1028
Last active May 22, 2023 07:59
Show Gist options
  • Save heyhey1028/ea2d60455d5bf01dab394f8fbce23063 to your computer and use it in GitHub Desktop.
Save heyhey1028/ea2d60455d5bf01dab394f8fbce23063 to your computer and use it in GitHub Desktop.
[ Github Actions ] Automatically assign assignee to dependabot PRs

What is this?

Github Actions workflow dedicated to automatically assign random assignee to PRs created by dependabot.

Context

Dependabot automatically creates PRs based on the updates of packages and libraries that project is depended on. When PRs are created, team members should check if upgrading the version will break the project or not. In case of breaking changes, member should refactor the project accordingly. Although PRs are created, often these PRs are left unchecked as team members become busy. In accordance to the situation, assigning members randomly would prevent PRs being unchecked.

How it works

on: pull_request_target runs on creation of pull request

if: ${{ github.actor == 'dependabot[bot]' }} allow actions to be run only PR is created by dependabot.

uses: actions/github-script@v6 action that allows running javascript inside the workflow

Reference

https://dev.classmethod.jp/articles/github-dependabot-auto-merge/ [JA]

https://zenn.dev/cumet04/articles/actions-firstparty-random-assign [JA]

version: 2
enable-beta-ecosystems: true
updates:
- package-ecosystem: "pub" # change to package ecosystem you are using.(ex. npm)
directory: "/"
schedule:
interval: weekly
name: Dependabot auto-assign
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
timeout-minutes: 5
steps:
- uses: actions/github-script@v6
with:
script: |
const names = [
// MEMO: change members accordingly
'foo-',
'bar-',
'baz-',
]
const index = Math.floor(Math.random() * names.length)
const assignee = names[index]
github.rest.issues.addAssignees({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
assignees: [assignee]
})
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ toJSON(github.event.pull_request.assignees) == '[]' }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment