ci: simplify label PR workflow (#25579)

This commit is contained in:
Damian Głowala 2024-02-02 15:40:40 +01:00 committed by GitHub
parent be7d43034b
commit c41acfb7ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,6 @@ on:
- opened - opened
branches: branches:
- main - main
- 2.x
jobs: jobs:
add-pr-labels: add-pr-labels:
@ -24,27 +23,20 @@ jobs:
const labelsToAdd = [] const labelsToAdd = []
const pullRequest = { const pullRequest = {
baseLabel: '${{ github.event.pull_request.base.label }}',
number: ${{ github.event.pull_request.number }}, number: ${{ github.event.pull_request.number }},
title: process.env.PULL_REQUEST_TITLE, title: process.env.PULL_REQUEST_TITLE,
labelsNames: ${{ toJson(github.event.pull_request.labels.*.name) }} labelsNames: ${{ toJson(github.event.pull_request.labels.*.name) }}
} }
// Select label based on the branch name // Select label based on the name of the base branch
const branchNameBasedLabelName = { const baseBranchLabelName = '3.x'
'nuxt:main': '3.x',
'nuxt:2.x': '2.x'
}[pullRequest.baseLabel]
if ( if (!pullRequest.labelsNames.includes(baseBranchLabelName)) {
branchNameBasedLabelName && labelsToAdd.push(baseBranchLabelName)
!pullRequest.labelsNames.includes(branchNameBasedLabelName)
) {
labelsToAdd.push(branchNameBasedLabelName)
} }
// Select label based on the type in PR title // Select label based on the type in PR title
const eligibleTypesToLabelsNamesMap = { const pullRequestTypeToLabelName = {
chore: 'chore', chore: 'chore',
ci: 'chore', ci: 'chore',
docs: 'documentation', docs: 'documentation',
@ -55,13 +47,13 @@ jobs:
test: 'test' test: 'test'
} }
for (const [eligibleType, labelName] of Object.entries( for (const [pullRequestType, labelName] of Object.entries(
eligibleTypesToLabelsNamesMap pullRequestTypeToLabelName
)) { )) {
if ( if (
pullRequest.title.startsWith(eligibleType) && pullRequest.title.startsWith(pullRequestType) &&
!pullRequest.labelsNames.includes( !pullRequest.labelsNames.includes(
eligibleTypesToLabelsNamesMap[eligibleType] pullRequestTypeToLabelName[pullRequestType]
) )
) { ) {
labelsToAdd.push(labelName) labelsToAdd.push(labelName)