mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
ci: label pull request based on type in title (#25404)
This commit is contained in:
parent
1daf92b3de
commit
44fcacba84
78
.github/workflows/label-pr.yml
vendored
78
.github/workflows/label-pr.yml
vendored
@ -9,31 +9,73 @@ on:
|
|||||||
- 2.x
|
- 2.x
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
add-pr-label:
|
add-pr-labels:
|
||||||
name: Add PR label
|
name: Add PR labels
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
if: github.repository == 'nuxt/nuxt'
|
if: github.repository == 'nuxt/nuxt'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
|
||||||
|
env:
|
||||||
|
PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const baseName = "${{ github.event.pull_request.base.label }}"
|
const labelsToAdd = []
|
||||||
const PRNumber = "${{ github.event.pull_request.number }}"
|
|
||||||
|
|
||||||
if(baseName === "nuxt:2.x") {
|
const pullRequest = {
|
||||||
github.rest.issues.addLabels({
|
baseLabel: ${{ github.event.pull_request.base.label }},
|
||||||
issue_number: PRNumber,
|
number: ${{ github.event.pull_request.number }},
|
||||||
owner: context.repo.owner,
|
title: process.env.PULL_REQUEST_TITLE,
|
||||||
repo: context.repo.repo,
|
labelsNames: ${{ github.event.pull_request.labels }}.map(
|
||||||
labels: ["2.x"]
|
(label) => label.name
|
||||||
})
|
)
|
||||||
} else if(baseName === "nuxt:main") {
|
|
||||||
github.rest.issues.addLabels({
|
|
||||||
issue_number: PRNumber,
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
labels: ["3.x"]
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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'
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user