main << develop #148
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: Auto Labeler based on Branch Name | |
| on: | |
| pull_request: | |
| types: [opened] | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| add-label: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Add label based on branch prefix | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const labelMapping = { | |
| 'setting': 'setting', | |
| 'feat': 'feat', | |
| 'fix': 'fix', | |
| 'api': 'api', | |
| 'refactor': 'refactor', | |
| 'chore': 'chore', | |
| 'deploy': 'deploy', | |
| 'comment': 'comment', | |
| 'test': 'test', | |
| 'rename': 'rename', | |
| 'remove': 'remove', | |
| 'docs': 'docs', | |
| }; | |
| const branchName = context.payload.pull_request.head.ref; | |
| console.log(`Branch name is: ${branchName}`); | |
| const branchPrefix = branchName.split('/')[0]; | |
| console.log(`Branch prefix is: ${branchPrefix}`); | |
| const labelToAdd = labelMapping[branchPrefix]; | |
| if (labelToAdd) { | |
| console.log(`Found matching label: ${labelToAdd}`); | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| labels: [labelToAdd] | |
| }); | |
| } else { | |
| console.log('No matching label found for the branch prefix.'); | |
| } |