Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically apply labels to github pull requests

Tags:

github

I'm trying to find some resources on how to add a label automatically when creating a new pull request. So far, I haven't found any documentation on this. Any pointers?

like image 653
jamesvphan Avatar asked May 02 '26 20:05

jamesvphan


1 Answers

It really depends on what and when you want to label those pull requests. Since there is no rule engine directly on GitHub for this to auto-label issues or pull requests, you have two options:

  1. Find something on the GitHub Marketplace tagged with label. The most used (and Verified) option is Labeler. Here is what a simple setup might look like:
# .github/workflows/auto-labeler.yml
name: Auto Label PRs

on:
  workflow_dispatch:
  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - name: Auto Label PR
        uses: actions/labeler@v5
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"

Then define your logic for how you want labels to be applied. In the case below add the db-migration label anytime a file is created/modified in the db/migrate/* directory

# .github/labeler.yml
db-migration:
  - "db/migrate/*"
  1. Or of course you could write your own script, GitHub Application or GitHub Action that interfaces with the GitHub API to set those labels based on your specific requirements.
like image 174
bitoiu Avatar answered May 05 '26 00:05

bitoiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!