(SQUASH PLS) Require exactly 1 change type label on every schema PR #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Change Type label verification | |
on: | |
pull_request: | |
types: [opened, edited, labeled, unlabeled, synchronize] | |
jobs: | |
check-label: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Require exactly one change type label | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const allChangeTypeLabels = new Set([ | |
'change type - cosmetic πΉ', | |
'change type - documentation - docs team π', | |
'change type - documentation - member π', | |
'change type - major π¨', | |
'change type - minor π€', | |
]); | |
const prLabels = context.payload.pull_request.labels.map(label => label.name); | |
const appliedChangeTypeLabels = prLabels.filter(prLabel => allChangeTypeLabels.has(prLabel)); | |
if (appliedChangeTypeLabels.length !== 1) { | |
const baseMessage = `The PR must have EXACTLY one of the following CHANGE TYPE labels: ${Array.from(allChangeTypeLabels).sort().join(', ')}. ` | |
const n = appliedChangeTypeLabels.length; | |
let contextualMessage; | |
if (n === 0) { | |
contextualMessage = 'It currently has no change type label. Please β add one label. π' | |
} else { | |
contextualMessage = `It currently has ${n} change type labels (${JSON.stringify(appliedChangeTypeLabels)}). π Please β remove ${n-1} label(s).` | |
} | |
core.setFailed(baseMessage + contextualMessage); | |
} |