ci: add workflow to automatically label PRs based on title
Auto Label PRs / label (pull_request) Successful in 3s
Test PR / test (pull_request) Successful in 5s
Release on Merge / release (pull_request) Has been skipped

This commit is contained in:
2026-05-02 23:38:21 -04:00
parent 48b436b20a
commit b78becad5f
+42
View File
@@ -0,0 +1,42 @@
name: Auto Label PRs
on:
pull_request:
types: [opened, edited]
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Apply labels based on PR title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
API_URL: ${{ github.api_url }}
run: |
shopt -s nocasematch
labels="["
if [[ "$PR_TITLE" =~ ^(ci|test)(/|:) ]]; then
labels="${labels}13," # 13 is Kind/Testing
fi
if [[ "$PR_TITLE" =~ ^docs(/|:) ]]; then
labels="${labels}14," # 14 is Kind/Documentation
fi
labels="${labels%,}]"
if [ "$labels" != "[]" ]; then
echo "Adding labels to PR #${PR_NUMBER}: ${labels}"
curl -X POST "${API_URL}/repos/${REPO_OWNER}/${REPO_NAME}/issues/${PR_NUMBER}/labels" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"labels\": ${labels}}"
else
echo "No matching prefixes found in title: ${PR_TITLE}"
fi