Skip to content

🏷️ GitHub Action for running a label validation on Pull Requests

License

Notifications You must be signed in to change notification settings

klaasnicolaas/action-pr-labels

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

Repository files navigation

🏷️ PR Label Checker

GitHub Release Project Stage Project Maintenance License

Test Status Code Coverage

This GitHub Action is created to validate pull requests based on predefined labels.

By specifying valid and/or invalid labels, this action ensures that pull requests are labeled consistently according to your project standards. If a pull request does not contain at least one valid label or if it contains any invalid labels, the action will fail and providing clear error messages.

Features

  • Label Validation: Ensures that a pull request has at least one valid label and no invalid labels.
  • Detailed Error Messages: Provides clear error messages when no valid labels are found or when invalid labels are detected, causing the action to fail.
  • Easy Configuration: Labels can be easily configured through the action's input parameters.

Inputs

The following input parameters can be used to configure the action:

repo-token

The GitHub token used to interact with the GitHub API.

  • Default: ${{ github.token }}
  • Usage: Optional

pr-number

The number of the pull request to validate.

  • Default: ${{ github.event.pull_request.number }}
  • Usage: Optional

valid-labels

A comma-separated list of valid labels that are allowed on the pull request.

  • Default: None
  • Usage: Required

invalid-labels

A comma-separated list of invalid labels that are not allowed on the pull request.

  • Default: None
  • Usage: Optional

Outputs

None. This action does not set any outputs.

Example workflow

This example workflows demonstrates a minimal configuration to validate pull requests based on predefined labels. In this example, the action is configured to check for valid labels breaking-change, bugfix, documentation, and enhancement.

name: PR Labels

on:
  pull_request_target:
    types: [opened, labeled, unlabeled, synchronize]

jobs:
  validate:
    name: Verify
    runs-on: ubuntu-latest
    steps:
      - name: 🏷 Verify PR has a valid label
        uses: klaasnicolaas/action-pr-labels@v1
        with:
          valid-labels: >-
            breaking-change, bugfix, documentation, enhancement

Full workflow example

This example workflow demonstrates a full example configuration to validate pull requests based on predefined labels. In this example, the action is configured to check for valid labels breaking-change, bugfix, documentation, and enhancement. Additionally, it checks for invalid labels duplicate and invalid.

name: PR Labels

on:
  pull_request_target:
    types: [opened, labeled, unlabeled, synchronize]

jobs:
  validate:
    name: Verify
    runs-on: ubuntu-latest
    steps:
      - name: 🏷 Verify PR has a valid label
        uses: klaasnicolaas/action-pr-labels@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          pr-number: ${{ github.event.pull_request.number }}
          valid-labels: >-
            breaking-change, bugfix, documentation, enhancement
          invalid-labels: >-
            duplicate, invalid

Contributing

This is an active open-source project. We are always open to people who want to use the code or contribute to it.

We've set up a separate document for our contribution guidelines.

Thank you for being involved! 😍

License

Distributed under the Apache License 2.0 license. See LICENSE for more information.