@@ -0,0 +1,47 @@
+name: PR Labeler
+
+on:
+ pull_request:
+ types: [opened, edited]
+
+jobs:
+ label:
+ runs-on: ubuntu-latest
+ permissions:
+ pull-requests: write
+
+ steps:
+ - name: Apply label based on PR title prefix
+ uses: actions/github-script@v7
+ with:
+ script: |
+ const title = context.payload.pull_request.title;
+ const prefixMap = {
+ 'feat': 'feat',
+ 'fix': 'fix',
+ 'chore': 'chore',
+ 'refactor': 'refactor',
+ 'docs': 'docs',
+ 'i18n': 'i18n',
+ };
+
+ const match = title.match(/^(\w+)(\(.+\))?:/);
+ if (!match) return;
+
+ const label = prefixMap[match[1]];
+ if (!label) return;
+
+ const { data: labels } = await github.rest.issues.listLabelsOnIssue({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.payload.pull_request.number,
+ });
+
+ if (labels.some(l => l.name === label)) return;
+
+ await github.rest.issues.addLabels({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.payload.pull_request.number,
+ labels: [label],
+ });