| 1 |
name: "Label Pull Request" |
| 2 |
on: |
| 3 |
- pull_request_target |
| 4 |
|
| 5 |
jobs: |
| 6 |
label-pr: |
| 7 |
permissions: |
| 8 |
contents: read |
| 9 |
pull-requests: write |
| 10 |
runs-on: ubuntu-latest |
| 11 |
steps: |
| 12 |
- uses: actions/checkout@v7 |
| 13 |
with: |
| 14 |
sparse-checkout: | |
| 15 |
.github/labeler.yml |
| 16 |
sparse-checkout-cone-mode: false |
| 17 |
- uses: actions/labeler@v7 |
| 18 |
with: |
| 19 |
configuration-path: .github/labeler.yml |
| 20 |
- name: Label based on PR title |
| 21 |
uses: actions/github-script@v9 |
| 22 |
with: |
| 23 |
script: | |
| 24 |
const title = context.payload.pull_request.title.toLowerCase(); |
| 25 |
const labels = []; |
| 26 |
|
| 27 |
if (title.includes("fix") || title.includes("bug")) { |
| 28 |
labels.push("type: bug"); |
| 29 |
} |
| 30 |
if (title.includes("feat")) { |
| 31 |
labels.push("type: feature"); |
| 32 |
} |
| 33 |
if (title.includes("doc")) { |
| 34 |
labels.push("type: documentation"); |
| 35 |
} |
| 36 |
if (title.includes("refactor")) { |
| 37 |
labels.push("type: refactor"); |
| 38 |
} |
| 39 |
|
| 40 |
if (labels.length > 0) { |
| 41 |
await github.rest.issues.addLabels({ |
| 42 |
owner: context.repo.owner, |
| 43 |
repo: context.repo.repo, |
| 44 |
issue_number: context.payload.pull_request.number, |
| 45 |
labels |
| 46 |
}); |
| 47 |
} |