|
| 1 | +name: Auto Label |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + issues: |
| 7 | + types: [opened, edited] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + issues: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + # ── Auto-label pull requests based on changed files ────────────────────────── |
| 16 | + label-pr: |
| 17 | + if: github.event_name == 'pull_request' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Label PR by changed files |
| 21 | + uses: actions/labeler@v5 |
| 22 | + with: |
| 23 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 24 | + configuration-path: .github/labeler.yml |
| 25 | + sync-labels: false |
| 26 | + |
| 27 | + # ── Auto-label issues based on title / body keywords ───────────────────────── |
| 28 | + label-issue: |
| 29 | + if: github.event_name == 'issues' |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Apply labels to issue |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + script: | |
| 37 | + const issue = context.payload.issue; |
| 38 | + const title = (issue.title || '').toLowerCase(); |
| 39 | + const body = (issue.body || '').toLowerCase(); |
| 40 | + const text = title + ' ' + body; |
| 41 | + const labels = []; |
| 42 | +
|
| 43 | + const add = (label) => labels.push(label); |
| 44 | +
|
| 45 | + // Type detection |
| 46 | + if (/\bbug\b|error|crash|broken|not working/.test(text)) add('bug'); |
| 47 | + if (/\bfeature\b|feature request|add support|new feature/.test(text)) add('feature'); |
| 48 | + if (/\benhancement\b|improve|improvement/.test(text)) add('enhancement'); |
| 49 | + if (/\bdoc(s|umentation)?\b|readme|typo/.test(text)) add('documentation'); |
| 50 | + if (/\bquestion\b|how (do|to|can)|help me|confused/.test(text)) add('question'); |
| 51 | +
|
| 52 | + // Challenge / submission detection |
| 53 | + if (/\bchallenge\b/.test(text)) add('challenge'); |
| 54 | + if (/\bsubmission\b/.test(text)) add('submission'); |
| 55 | +
|
| 56 | + // Week detection |
| 57 | + const weekMatch = text.match(/\bweek[-\s]?(\d+)\b/); |
| 58 | + if (weekMatch) add(`week-${weekMatch[1]}`); |
| 59 | +
|
| 60 | + // Difficulty detection |
| 61 | + if (/\bbeginner\b/.test(text)) add('beginner'); |
| 62 | + if (/\bintermediate\b/.test(text)) add('intermediate'); |
| 63 | + if (/\badvanced\b/.test(text)) add('advanced'); |
| 64 | +
|
| 65 | + // Good first issue / help wanted |
| 66 | + if (/good first issue|starter|newcomer|first (pr|contribution)/.test(text)) add('good first issue'); |
| 67 | + if (/help wanted|looking for help/.test(text)) add('help wanted'); |
| 68 | +
|
| 69 | + // Leaderboard |
| 70 | + if (/\bleaderboard\b/.test(text)) add('leaderboard'); |
| 71 | +
|
| 72 | + if (labels.length === 0) return; |
| 73 | +
|
| 74 | + await github.rest.issues.addLabels({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + issue_number: issue.number, |
| 78 | + labels, |
| 79 | + }); |
0 commit comments