Skip to content

shanearcaro/automatic-labeler

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

Automatic Pull request Labeler

Automatically add labels to your pull requests based on file paths and extensions.

Action Options

github-token: Token used for authentication [required]

with:
  github-token: ${{ github.token }}

paths:

Apply a label based on directory changes [optional]

with:
  paths: |
    .github/: "workflows"
    backend/src/: "backend"

This will apply the labels workflows and backend when the pull request includes any changed files in either directories.

languages:

Apply a label based on a file extension [optional]

languages: |
  ts: "typescript"
  js: "typescript"
  tsx: "react"
  jsx: "react"
  yml: "config"
  yaml: "config"
  json: "config"
  md: "documentation"
  sh: "scripting"
  Dockerfile: "docker"

This will apply the labels if any file changes are detected with the extensions .ts, .js, .tsx, or .jsx, etc.

assign_owner:

Assign the creator of the pull request as an assignee. [optional]

assign-owner: 'true' 

Labels

Labels that do not exist will be created with a random color.

A full example using this action:

name: "Automatic PR Labeler"
on:
  pull_request:
    types: [opened]
permissions: // Required permissions for action to work properly
  contents: read // Read content from repository
  pull-requests: write // Read and edit pull requests
  repository-projects: read // Read GITHUB_TOKEN
jobs:
  label:
    runs-on: ubuntu-latest
    env:
      GH_TOKEN: ${{ github.token }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 // Fetch the entire history of the repository
      - name: Assign labels
        uses: shanearcaro/automatic-labeler@v2.1.0
        with:
          paths: |
            .github/: "workflows"
            backend/src/: "backend"
          languages: |
            ts: "typescript"
            js: "typescript"
            tsx: "react"
            jsx: "react"
            yml: "config"
            yaml: "config"
            json: "config"
            md: "documentation"
            sh: "scripting"
            Dockerfile: "docker"
          assign-owner: 'true'