2023-12-01 11:41:52 +00:00
|
|
|
name: Label PR
|
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request_target:
|
|
|
|
types:
|
|
|
|
- opened
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
- 2.x
|
|
|
|
|
|
|
|
jobs:
|
2024-01-24 11:50:40 +00:00
|
|
|
add-pr-labels:
|
|
|
|
name: Add PR labels
|
2023-12-01 11:41:52 +00:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
permissions:
|
|
|
|
pull-requests: write
|
|
|
|
if: github.repository == 'nuxt/nuxt'
|
|
|
|
steps:
|
|
|
|
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
2024-01-24 11:50:40 +00:00
|
|
|
env:
|
|
|
|
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
|
2023-12-01 11:41:52 +00:00
|
|
|
with:
|
|
|
|
script: |
|
2024-01-24 11:50:40 +00:00
|
|
|
const labelsToAdd = []
|
|
|
|
|
|
|
|
const pullRequest = {
|
|
|
|
baseLabel: ${{ github.event.pull_request.base.label }},
|
|
|
|
number: ${{ github.event.pull_request.number }},
|
|
|
|
title: process.env.PULL_REQUEST_TITLE,
|
|
|
|
labelsNames: ${{ github.event.pull_request.labels }}.map(
|
|
|
|
(label) => label.name
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select label based on the branch name
|
|
|
|
const branchNameBasedLabelName = {
|
|
|
|
'nuxt:main': '3.x',
|
|
|
|
'nuxt:2.x': '2.x'
|
|
|
|
}[pullRequest.baseLabel]
|
|
|
|
|
|
|
|
if (
|
|
|
|
branchNameBasedLabelName &&
|
|
|
|
!pullRequest.labelsNames.includes(branchNameBasedLabelName)
|
|
|
|
) {
|
|
|
|
labelsToAdd.push(branchNameBasedLabelName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select label based on the type in PR title
|
|
|
|
const eligibleTypesToLabelsNamesMap = {
|
|
|
|
chore: 'chore',
|
|
|
|
ci: 'chore',
|
|
|
|
docs: 'documentation',
|
|
|
|
feat: 'enhancement',
|
|
|
|
fix: 'bug',
|
|
|
|
perf: 'performance',
|
|
|
|
refactor: 'refactor',
|
|
|
|
test: 'test'
|
2023-12-01 11:41:52 +00:00
|
|
|
}
|
2024-01-24 11:50:40 +00:00
|
|
|
|
|
|
|
for (const [eligibleType, labelName] of Object.entries(
|
|
|
|
eligibleTypesToLabelsNamesMap
|
|
|
|
)) {
|
|
|
|
if (
|
|
|
|
pullRequest.title.startsWith(eligibleType) &&
|
|
|
|
!pullRequest.labelsNames.includes(
|
|
|
|
eligibleTypesToLabelsNamesMap[eligibleType]
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
labelsToAdd.push(labelName)
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add selected labels
|
|
|
|
github.rest.issues.addLabels({
|
|
|
|
issue_number: pullRequest.number,
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
labels: labelsToAdd
|
|
|
|
})
|