Skip to content

GH Actions: automate some issue/PR label management #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 1
appendOnly: true
labels:
- label: "Status: triage"
draft: false
author-can-merge: false

- label: "Component: Website"
draft: false
files:
- "src/.*"

- label: "Component: Wiki"
draft: false
files:
- "build/wiki-command-replacer.sh"
- "build/wiki-code-samples/.*"
- "wiki/.*"

- label: "Type: chores/QA/automation"
draft: false
files:
- ".yamllint.yml"
- ".github/.*"
- "build/wiki-command-replacer.sh"
49 changes: 49 additions & 0 deletions .github/workflows/label-new-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Label new PRs

on:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
# The `pull_request_target` event is used for "normal" PRs to label them when they are opened.
# This will use the `labeler.yml` file in the default (main) branch of the repo.
pull_request_target:
types:
- opened
- ready_for_review

# The `pull_request` event is used for PRs which change the files which handle the labeling to prevent a silently failing action.
# This will use the `labeler.yml` file in the PR branch.
pull_request:
paths:
- '.github/workflows/label-new-prs.yml'
- '.github/labeler.yml'

jobs:
label-new-prs:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target'

name: Add labels to new PRs

steps:
- name: Label new PRs
uses: srvaroa/labeler@v1
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

validate-labeler-worflow:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request' && github.event.pull_request.merged == false

name: Validate changes to Labeler logic

steps:
# Checkout is needed to use the `use_local_config` option.
- name: Checkout code
uses: actions/checkout@v4

- name: Verify changes to the labeling logic
uses: srvaroa/labeler@v1
with:
use_local_config: true
fail_on_error: true
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
79 changes: 79 additions & 0 deletions .github/workflows/label-remove-outdated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Remove outdated labels

on:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target
issues:
types:
- closed
pull_request_target:
types:
- closed
- review_requested

jobs:
on-issue-close:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event.issue.state == 'closed'

name: Clean up labels on issue close

steps:
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback
Status: close candidate
Status: help wanted
Status: needs investigation
Status: triage

on-pr-review-request:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event.action == 'review_requested'

name: "Clean up labels on PR (re-)review request"

steps:
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback

on-pr-merge:
runs-on: ubuntu-latest
if: github.repository_owner == 'PHPCSStandards' && github.event.pull_request.merged == true

name: Clean up labels on PR merge

steps:
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback
Status: close candidate
Status: has merge conflict
Status: help wanted
Status: needs investigation
Status: triage
Status: wait for PHPCS 4.0.0 release

on-pr-close:
runs-on: ubuntu-latest
# yamllint disable-line rule:line-length
if: github.repository_owner == 'PHPCSStandards' && github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == false

name: Clean up labels on PR close

steps:
- uses: mondeja/remove-labels-gh-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
labels: |
Status: awaiting feedback
Status: close candidate
Status: help wanted
Status: needs investigation
Status: triage
Loading