|
1 | 1 | name: PR Title Labeler |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: |
5 | | - types: [opened, edited, reopened] |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - edited |
| 8 | + - reopened |
6 | 9 |
|
7 | 10 | jobs: |
8 | | - label: |
| 11 | + label-pr: |
9 | 12 | runs-on: ubuntu-latest |
10 | 13 |
|
| 14 | + # 기본 GITHUB_TOKEN 대신 PAT을 쓰기 때문에 permissions 블록은 생략 가능 |
11 | 15 | steps: |
12 | | - - name: Label PR by title |
13 | | - uses: jimschubert/labeler-action@v2 |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v3 |
14 | 18 | with: |
15 | | - GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} |
| 19 | + token: ${{ secrets.PAT_TOKEN }} |
| 20 | + |
| 21 | + - name: Label PR based on title |
| 22 | + uses: actions/github-script@v6 |
| 23 | + with: |
| 24 | + github-token: ${{ secrets.PAT_TOKEN }} |
| 25 | + script: | |
| 26 | + const title = context.payload.pull_request.title || ""; |
| 27 | +
|
| 28 | + const labelMap = [ |
| 29 | + { pattern: /^feat:/i, label: '✨ feat' }, |
| 30 | + { pattern: /^fix:/i, label: '🐞 fix' }, |
| 31 | + { pattern: /^refactor:/i, label: '🔨 refactor' }, |
| 32 | + { pattern: /^docs:/i, label: '📃 docs' }, |
| 33 | + { pattern: /^chore:/i, label: '⚙️ chore' }, |
| 34 | + { pattern: /^test:/i, label: '✅ test' }, |
| 35 | + { pattern: /^style:/i, label: '🎨 style' } |
| 36 | + ]; |
| 37 | +
|
| 38 | + const labelsToAdd = labelMap |
| 39 | + .filter(entry => entry.pattern.test(title)) |
| 40 | + .map(entry => entry.label); |
| 41 | +
|
| 42 | + if (labelsToAdd.length > 0) { |
| 43 | + await github.rest.issues.addLabels({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + issue_number: context.issue.number, |
| 47 | + labels: labelsToAdd |
| 48 | + }); |
| 49 | + core.info(`Added labels: ${labelsToAdd.join(', ')}`); |
| 50 | + } else { |
| 51 | + core.info('No matching labels found for PR title.'); |
| 52 | + } |
0 commit comments