From b78becad5fb194f84c45c46251c133ba0c14b798 Mon Sep 17 00:00:00 2001 From: rootiest Date: Sat, 2 May 2026 23:38:21 -0400 Subject: [PATCH] ci: add workflow to automatically label PRs based on title --- .gitea/workflows/label-pr.yaml | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .gitea/workflows/label-pr.yaml diff --git a/.gitea/workflows/label-pr.yaml b/.gitea/workflows/label-pr.yaml new file mode 100644 index 0000000..a6189ea --- /dev/null +++ b/.gitea/workflows/label-pr.yaml @@ -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