Skip to content

Commit 2413e02

Browse files
authored
Merge pull request #6 from ReactSphere/copilot/add-auto-label-for-pr-and-issue
feat: auto-label PRs and issues + sync all repo labels
2 parents d184a8a + da24afc commit 2413e02

4 files changed

Lines changed: 288 additions & 0 deletions

File tree

.github/labeler.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Auto-labeler configuration for pull requests
2+
# Uses actions/labeler to apply labels based on changed file paths
3+
# https://github.com/actions/labeler
4+
5+
documentation:
6+
- changed-files:
7+
- any-glob-to-any-file:
8+
- "**/*.md"
9+
- "docs/**"
10+
11+
ci/cd:
12+
- changed-files:
13+
- any-glob-to-any-file:
14+
- ".github/**"
15+
16+
leaderboard:
17+
- changed-files:
18+
- any-glob-to-any-file:
19+
- "LEADERBOARD.md"
20+
- ".github/scripts/generate-leaderboard.js"
21+
22+
week-1:
23+
- changed-files:
24+
- any-glob-to-any-file:
25+
- "challenges/week-1/**"
26+
- "challenges/week-1.md"
27+
28+
week-2:
29+
- changed-files:
30+
- any-glob-to-any-file:
31+
- "challenges/week-2/**"
32+
- "challenges/week-2.md"
33+
34+
week-3:
35+
- changed-files:
36+
- any-glob-to-any-file:
37+
- "challenges/week-3/**"
38+
- "challenges/week-3.md"
39+
40+
week-4:
41+
- changed-files:
42+
- any-glob-to-any-file:
43+
- "challenges/week-4/**"
44+
- "challenges/week-4.md"
45+
46+
challenge:
47+
- changed-files:
48+
- any-glob-to-any-file:
49+
- "challenges/**"
50+
51+
dependencies:
52+
- changed-files:
53+
- any-glob-to-any-file:
54+
- "package.json"
55+
- "package-lock.json"
56+
- "yarn.lock"
57+
- "pnpm-lock.yaml"

.github/labels.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Label definitions for ReactSphere Community Challenges
2+
# Used by the label-sync workflow to keep labels in sync with this file
3+
4+
# ── Status labels ──────────────────────────────────────────────────────────────
5+
- name: "needs-review"
6+
color: "fbca04"
7+
description: "Awaiting review from maintainers"
8+
9+
- name: "in-progress"
10+
color: "0075ca"
11+
description: "Work is currently in progress"
12+
13+
- name: "approved"
14+
color: "0e8a16"
15+
description: "Submission or change has been approved"
16+
17+
- name: "needs-changes"
18+
color: "e4e669"
19+
description: "Changes requested before merging"
20+
21+
- name: "blocked"
22+
color: "b60205"
23+
description: "Blocked by another issue or external dependency"
24+
25+
# ── Type labels ────────────────────────────────────────────────────────────────
26+
- name: "bug"
27+
color: "d73a4a"
28+
description: "Something isn't working"
29+
30+
- name: "enhancement"
31+
color: "a2eeef"
32+
description: "New feature or improvement to existing functionality"
33+
34+
- name: "feature"
35+
color: "0075ca"
36+
description: "Request for a new feature"
37+
38+
- name: "documentation"
39+
color: "0075ca"
40+
description: "Improvements or additions to documentation"
41+
42+
- name: "question"
43+
color: "d876e3"
44+
description: "Further information is requested"
45+
46+
- name: "discussion"
47+
color: "e4e669"
48+
description: "Open for community discussion"
49+
50+
# ── Challenge labels ───────────────────────────────────────────────────────────
51+
- name: "challenge"
52+
color: "6f42c1"
53+
description: "Related to a weekly challenge"
54+
55+
- name: "submission"
56+
color: "1d76db"
57+
description: "A challenge submission"
58+
59+
- name: "week-1"
60+
color: "c5def5"
61+
description: "Week 1 challenge"
62+
63+
- name: "week-2"
64+
color: "c5def5"
65+
description: "Week 2 challenge"
66+
67+
- name: "week-3"
68+
color: "c5def5"
69+
description: "Week 3 challenge"
70+
71+
- name: "week-4"
72+
color: "c5def5"
73+
description: "Week 4 challenge"
74+
75+
# ── Difficulty labels ──────────────────────────────────────────────────────────
76+
- name: "beginner"
77+
color: "0e8a16"
78+
description: "Beginner-level challenge or task"
79+
80+
- name: "intermediate"
81+
color: "fbca04"
82+
description: "Intermediate-level challenge or task"
83+
84+
- name: "advanced"
85+
color: "d93f0b"
86+
description: "Advanced-level challenge or task"
87+
88+
# ── Contribution labels ────────────────────────────────────────────────────────
89+
- name: "good first issue"
90+
color: "7057ff"
91+
description: "Good for newcomers"
92+
93+
- name: "help wanted"
94+
color: "008672"
95+
description: "Extra attention is needed"
96+
97+
- name: "hacktoberfest"
98+
color: "ff7518"
99+
description: "Valid Hacktoberfest contribution"
100+
101+
# ── Resolution labels ──────────────────────────────────────────────────────────
102+
- name: "duplicate"
103+
color: "cfd3d7"
104+
description: "This issue or pull request already exists"
105+
106+
- name: "invalid"
107+
color: "e4e669"
108+
description: "This doesn't seem right"
109+
110+
- name: "wontfix"
111+
color: "ffffff"
112+
description: "This will not be worked on"
113+
114+
# ── Area labels ────────────────────────────────────────────────────────────────
115+
- name: "leaderboard"
116+
color: "f9d0c4"
117+
description: "Related to the leaderboard"
118+
119+
- name: "ci/cd"
120+
color: "0075ca"
121+
description: "Related to CI/CD workflows and automation"
122+
123+
- name: "dependencies"
124+
color: "0366d6"
125+
description: "Pull requests that update a dependency file"

.github/workflows/auto-label.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
});

.github/workflows/label-sync.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Sync Labels
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- .github/labels.yml
10+
workflow_dispatch:
11+
12+
permissions:
13+
issues: write
14+
15+
jobs:
16+
sync:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repo
20+
uses: actions/checkout@v4
21+
22+
- name: Sync labels
23+
uses: EndBug/label-sync@v2
24+
with:
25+
config-file: .github/labels.yml
26+
delete-other-labels: false
27+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)