Skip to content

A GitHub Action that automatically adds labels to pull requests, issues, and more. Streamline your workflow by ensuring that every new pull request, issue, or event is properly labeled upon creation.

License

Notifications You must be signed in to change notification settings

HassanBahati/labeler-action

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

Labeler GitHub Action

This GitHub Action automatically adds a specified label to Pull Requests. It is designed to be flexible and future-proof for additional labeling capabilities such as issues and other GitHub events.

Features

  • Automatically label Pull Requests when they are opened.
  • Configurable with any custom label.
  • Designed for future expansion to support labeling issues and other GitHub events.

Usage

Example Workflow

Here’s how you can use this action in your GitHub repository. Create a workflow YAML file (e.g., .github/workflows/labeler.yml) and use the following configuration:

name: Auto Labeler

on:
  pull_request:
    types: [opened]

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Apply Label
        uses: HassanBahati/[email protected]
        with:
          gh-token: ${{ secrets.GITHUB_TOKEN }}
          label: "Your-Label-Here"

Inputs

Name Description Required Default
gh-token GitHub token to authenticate API requests. Usually, the GITHUB_TOKEN secret. Yes N/A
label The label to be applied to the Pull Request. Yes N/A

Example Use Case

This action is useful when you want to ensure Pull Requests are labeled appropriately without manual intervention. For instance, you might want to add a review needed label when a new Pull Request is opened.

uses: HassanBahati/[email protected]
with:
  gh-token: ${{ secrets.GITHUB_TOKEN }}
  label: "review needed"

Future Plans

In future versions, this action will support:

  • Labeling issues.
  • Advanced event triggers.
  • Dynamic labeling rules based on PR content, file changes, or issue type.

Outputs

Currently, the action does not return any outputs, but this can be added in future iterations if needed.

Authentication

The gh-token input uses GitHub’s GITHUB_TOKEN, which is automatically provided in your repository secrets. This token allows the action to authenticate API requests and apply labels to issues and pull requests.

Error Handling

If the action is run on any event other than a Pull Request or encounters an API error, it will fail with an appropriate error message:

  • If the event is not a Pull Request, the action will fail with: This action can only be run on Pull Requests.
  • If there’s an issue with the API request, the error message returned by the GitHub API will be displayed.

License

This project is licensed under the MIT License.

About

A GitHub Action that automatically adds labels to pull requests, issues, and more. Streamline your workflow by ensuring that every new pull request, issue, or event is properly labeled upon creation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published