GitHub action to copy labels from any issues closed by a pull request into the pull request itself.
---
name: Sync Closing Labels
on:
pull_request_target
jobs:
sync:
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Sync labels with closing issues
uses: williambdean/closing-labels@v1.0.0The action uses github.token by default — no additional secrets required. The workflow must grant pull-requests: write permission.
| Input | Required | Default | Description |
|---|---|---|---|
gh_token |
No | ${{ github.token }} |
GitHub token with pull-requests: write permission |
exclude |
No | "" |
Comma-separated list of labels to never add |
issue_types |
No | "false" |
If "true", also use each closing issue's type (e.g. Bug) as a label name |
respect_unlabeled |
No | "true" |
If "true", labels manually removed from the PR will not be re-added |
owner |
No | ${{ github.repository_owner }} |
Repository owner |
repo |
No | ${{ github.event.repository.name }} |
Repository name |
pr_number |
No | ${{ github.event.number }} |
Pull request number |
dry_run |
No | "false" |
If "true", print what would be added without applying it (for testing) |
fail_on_error |
No | "false" |
If "true", exit with an error when the sync fails; otherwise log the error and exit successfully (no-op) |
- uses: williambdean/closing-labels@v1.0.0
with:
exclude: "wontfix,duplicate"- uses: williambdean/closing-labels@v1.0.0
with:
issue_types: "true"- uses: williambdean/closing-labels@v1.0.0
with:
respect_unlabeled: "false"- uses: williambdean/closing-labels@v1.0.0
with:
gh_token: ${{ secrets.MY_GITHUB_TOKEN }}- Queries the GitHub GraphQL API to find all issues referenced as "closing" by the pull request
- Collects all labels from those issues (plus each issue's type when
issue_types: "true") - Optionally subtracts any labels that were manually removed from the PR (
respect_unlabeled) - Optionally filters out labels in the
excludelist - Skips labels already present on the pull request
- Applies the remaining labels to the pull request via the GitHub REST API
Labels are synced only from issues closed in the same repository as the pull request. GitHub's closing keywords (Closes, Fixes, …) are same-repo only, so cross-repository references are not treated as closing references and are ignored by this action.
By default the action is best-effort: if a GitHub API call fails, the error is logged and the action exits successfully, leaving the pull request unchanged (a no-op). Set fail_on_error: "true" to fail the workflow step instead. A pull request with no closing issues is also a no-op.
Please see our Security Policy for information on how to report security vulnerabilities.
For actions, we recommend pinning uses: to a full commit SHA rather than a mutable tag or branch, e.g.:
- uses: williambdean/closing-labels@0123456789abcdef0123456789abcdef01234567 # v1.0.0The tag in the comment is only a convenience for tracking which release the SHA corresponds to.
Build and enter the Docker container locally:
make build
make interactiveFrom inside the container, run the action with the required environment variables:
GH_TOKEN="$(gh auth token)" \
INPUT_OWNER="williambdean" \
INPUT_REPO="closing-labels" \
INPUT_PR_NUMBER="21" \
INPUT_EXCLUDE="wontfix,duplicate" \
INPUT_RESPECT_UNLABELED="true" \
INPUT_DRY_RUN="true" \
closing-labelsSet INPUT_DRY_RUN="true" to preview what labels would be applied without making any changes.
