From 785f57077ec6381613845e3ef4c2a51598491da1 Mon Sep 17 00:00:00 2001 From: EvgrafovMichail Date: Mon, 21 Sep 2026 18:26:34 +0300 Subject: [PATCH] Add label selection action --- .github/workflows/label-by-group.yml | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/label-by-group.yml diff --git a/.github/workflows/label-by-group.yml b/.github/workflows/label-by-group.yml new file mode 100644 index 00000000..97d8e60d --- /dev/null +++ b/.github/workflows/label-by-group.yml @@ -0,0 +1,52 @@ +name: Label PR by group + +on: + pull_request_target: + types: [opened, edited, reopened] + +permissions: + pull-requests: write + +jobs: + label-selection: + runs-on: ubuntu-latest + steps: + - name: Set label from PR title + uses: actions/github-script@v7 + with: + script: | + const title = context.payload.pull_request.title; + + // Expected title format: ". . " + const parts = title.split(".").map((part) => part.trim()); + + if (parts.length !== 3 || parts.some((part) => part.length === 0)) { + console.log(`Title "${title}" does not match the expected template, skipping.`); + return; + } + + const [hwNumber, , groupNumber] = parts; + + if (!/^\d+$/.test(hwNumber)) { + console.log(`Title "${title}" does not match the expected template, skipping.`); + return; + } + + const { data: labels } = await github.rest.issues.listLabelsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const matchingLabel = labels.find((label) => label.name === groupNumber); + + if (!matchingLabel) { + console.log(`No label named "${groupNumber}" found, skipping.`); + return; + } + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: [matchingLabel.name], + });