ci: Add auto-label GH action #1
Workflow file for this run
This file contains hidden or 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: Changelog Labeler | |
| on: | |
| pull_request: | |
| types: [opened, edited] | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| label: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Add changelog label | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const title = context.payload.pull_request.title.toLowerCase(); | |
| const prNumber = context.payload.pull_request.number; | |
| // Get current labels | |
| const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| }); | |
| // Check if a Changelog label already exists | |
| const hasChangelogLabel = currentLabels.some(label => | |
| label.name.startsWith('Changelog') || label.name === 'skip-changelog' | |
| ); | |
| if (hasChangelogLabel) { | |
| console.log('PR already has a Changelog label, skipping'); | |
| return; | |
| } | |
| // Determine which label to apply | |
| let newLabel = null; | |
| if (title.startsWith('feat')) { | |
| newLabel = 'Changelog: Feature'; | |
| } else if (title.startsWith('fix') || title.startsWith('bugfix')) { | |
| newLabel = 'Changelog: Bugfix'; | |
| } else if (title.includes('deprecate')) { | |
| newLabel = 'Changelog: Deprecation'; | |
| } else if (title.startsWith('docs')) { | |
| newLabel = 'Changelog: Docs'; | |
| } else if (title.startswith('ref') || title.startsWith('test')) { | |
| newLabel = 'Changelog: Internal'; | |
| } else if (title.startsWith('ci') || title.startsWith('build')) { | |
| newLabel = 'skip-changelog'; | |
| } | |
| // Apply the new label if one was determined | |
| if (newLabel) { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: [newLabel], | |
| }); | |
| console.log(`Applied label: ${newLabel}`); | |
| } else { | |
| console.log('No matching label pattern found in PR title, please add manually'); | |
| } | |