ci: add workflow to automatically label PRs based on title
This commit is contained in:
@@ -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
|
||||||
Reference in New Issue
Block a user