Skip to content

Week 2 task solution #11

Week 2 task solution

Week 2 task solution #11

Workflow file for this run

name: Auto Label
on:
pull_request:
types: [opened, synchronize, reopened]
issues:
types: [opened, edited]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
# ── Auto-label pull requests based on changed files ──────────────────────────
label-pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Label PR by changed files
uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
sync-labels: false
# ── Auto-label issues based on title / body keywords ─────────────────────────
label-issue:
if: github.event_name == 'issues'
runs-on: ubuntu-latest
steps:
- name: Apply labels to issue
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const title = (issue.title || '').toLowerCase();
const body = (issue.body || '').toLowerCase();
const text = title + ' ' + body;
const labels = [];
const add = (label) => labels.push(label);
// Type detection
if (/\bbug\b|error|crash|broken|not working/.test(text)) add('bug');
if (/\bfeature\b|feature request|add support|new feature/.test(text)) add('feature');
if (/\benhancement\b|improve|improvement/.test(text)) add('enhancement');
if (/\bdoc(s|umentation)?\b|readme|typo/.test(text)) add('documentation');
if (/\bquestion\b|how (do|to|can)|help me|confused/.test(text)) add('question');
// Challenge / submission detection
if (/\bchallenge\b/.test(text)) add('challenge');
if (/\bsubmission\b/.test(text)) add('submission');
// Week detection
const weekMatch = text.match(/\bweek[-\s]?(\d+)\b/);
if (weekMatch) add(`week-${weekMatch[1]}`);
// Difficulty detection
if (/\bbeginner\b/.test(text)) add('beginner');
if (/\bintermediate\b/.test(text)) add('intermediate');
if (/\badvanced\b/.test(text)) add('advanced');
// Good first issue / help wanted
if (/good first issue|starter|newcomer|first (pr|contribution)/.test(text)) add('good first issue');
if (/help wanted|looking for help/.test(text)) add('help wanted');
// Leaderboard
if (/\bleaderboard\b/.test(text)) add('leaderboard');
if (labels.length === 0) return;
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels,
});