|
5 | 5 | types: [opened, edited, reopened] |
6 | 6 |
|
7 | 7 | jobs: |
8 | | - label: |
| 8 | + label-pr: |
9 | 9 | runs-on: ubuntu-latest |
10 | 10 |
|
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + pull-requests: write |
| 14 | + |
11 | 15 | steps: |
12 | | - - name: Label PR by title |
13 | | - uses: jimschubert/labeler-action@v2 |
| 16 | + - name: Label PR based on title |
| 17 | + uses: actions/github-script@v6 |
14 | 18 | with: |
15 | | - GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} |
| 19 | + script: | |
| 20 | + const prTitle = context.payload.pull_request.title; |
| 21 | +
|
| 22 | + const labelMap = [ |
| 23 | + { pattern: /^feat:/i, label: '✨ feat' }, |
| 24 | + { pattern: /^fix:/i, label: '🐞 fix' }, |
| 25 | + { pattern: /^chore:/i, label: '⚙️ chore' }, |
| 26 | + { pattern: /^docs:/i, label: '📃 docs' }, |
| 27 | + { pattern: /^refactor:/i, label: '🔨 refactor' }, |
| 28 | + { pattern: /^test:/i, label: '✅ test' } |
| 29 | + ]; |
| 30 | +
|
| 31 | + const labelsToAdd = labelMap |
| 32 | + .filter(entry => entry.pattern.test(prTitle)) |
| 33 | + .map(entry => entry.label); |
| 34 | +
|
| 35 | + if (labelsToAdd.length > 0) { |
| 36 | + await github.rest.issues.addLabels({ |
| 37 | + issue_number: context.issue.number, |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + labels: labelsToAdd |
| 41 | + }); |
| 42 | + core.info(`Added labels: ${labelsToAdd.join(', ')}`); |
| 43 | + } else { |
| 44 | + core.info('No matching labels found for PR title.'); |
| 45 | + } |
0 commit comments