Skip to content

Github Action that forces authors to add labels to their PR before it is merged.

Notifications You must be signed in to change notification settings

Optimal-AI/PR-Label-Checker

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

PR Label Checker

The PR Label Checker is a Github Action created by Tara AI that Checks for Labels in a Pull Request and asks Engineers/Developers to add relevant labels to their PR before before it is merged.

Customize Labels

To customize labels, simply add/remove from the list:

      if: >
        contains(github.event.pull_request.labels.*.name, 'bug') == false && 
        contains(github.event.pull_request.labels.*.name, 'documentation') == false && 
        contains(github.event.pull_request.labels.*.name, 'enhancement') == false &&
        contains(github.event.pull_request.labels.*.name, 'newlabel1') == false &&
        contains(github.event.pull_request.labels.*.name, 'newlabel2') == false
      run: exit 1

This will require either bug, documentation, enhancement, newlabel1, or newlabel2 to be attached to a PR.

Required Labels

To have multiple required labels on a single PR you can use ||:

      if: >
        contains(github.event.pull_request.labels.*.name, 'bug') == false ||
        contains(github.event.pull_request.labels.*.name, 'allocations') == false ||
        contains(github.event.pull_request.labels.*.name, 'fe') == false
      run: exit 1

Related Labels

To require labels related to other labels you can use needs on a specific job.

jobs:
  check-bug:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Labels not added (bug)
      if: >
        contains(github.event.pull_request.labels.*.name, 'bug') == false && 
      run: exit 1

  check-sev:
    runs-on: ubuntu-latest
    needs: check-bug
    steps:
    - uses: actions/checkout@v3
    - name: Labels not added (sev1, sev2, sev3)
      if: >
        contains(github.event.pull_request.labels.*.name, 'sev1') == false && 
        contains(github.event.pull_request.labels.*.name, 'sev2') == false && 
        contains(github.event.pull_request.labels.*.name, 'sev3') == false
      run: exit 1