Repository navigation
1. Дябденко Богдан Константинович. 613 #74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Label PR by group | ||
|
Check warning on line 1 in .github/workflows/label-by-group.yml
|
||
| 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: "<hw number>. <full name>. <group number>" | ||
| 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], | ||
| }); | ||