Skip to content

Commit c24f6f4

Browse files
Merge branch 'main' into test-calculate-commit-spike
2 parents 84f7336 + 56fbc35 commit c24f6f4

139 files changed

Lines changed: 12641 additions & 1546 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/scripts/issue-management/claim-handler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ async function handleClaim({ github, context }) {
3030

3131
const issueAuthor = context.payload.issue.user.login;
3232

33-
const isAuthorJhasourav07 = issueAuthor.toLowerCase() === 'jhasourav07';
33+
const MAINTAINERS = ['jhasourav07', 'aamod007', 'souravjhahind'];
34+
const isOpenedByMaintainer = MAINTAINERS.includes(issueAuthor.toLowerCase());
3435

35-
if (!isAuthorJhasourav07 && commenter.toLowerCase() !== issueAuthor.toLowerCase()) {
36+
if (!isOpenedByMaintainer && commenter.toLowerCase() !== issueAuthor.toLowerCase()) {
3637
await github.rest.issues.createComment({
3738
owner,
3839
repo,
@@ -73,7 +74,7 @@ async function handleClaim({ github, context }) {
7374
owner,
7475
repo,
7576
issue_number: issueNumber,
76-
body: `❌ You already have **${existingIssues.length}/${MAX_ASSIGNED_ISSUES}** active assigned issues (the maximum allowed).\nPlease complete or unassign one of your current issues before claiming another.\n\n${issueList}`,
77+
body: `❌ You already have **${existingIssues.length}/${MAX_ASSIGNED_ISSUES}** active assigned issues (the maximum allowed).\nPlease complete or \`/unclaim\` one of your current issues before claiming another.\n\n${issueList}`,
7778
});
7879
return;
7980
}

.github/scripts/issue-management/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { handleAssign } = require('./assign-handler');
44
const { handleUnassign } = require('./unassign-handler');
55
const { handleAddLabel } = require('./addlabel-handler');
66
const { handleClaim } = require('./claim-handler');
7+
const { handleUnclaim } = require('./unclaim-handler');
78

89
module.exports = async ({ github, context, core }) => {
910
const commentBody = context.payload.comment?.body;
@@ -48,6 +49,9 @@ module.exports = async ({ github, context, core }) => {
4849
case 'claim':
4950
await handleClaim({ github, context });
5051
break;
52+
case 'unclaim':
53+
await handleUnclaim({ github, context });
54+
break;
5155
case 'ping':
5256
await github.rest.issues.createComment({
5357
owner,

.github/scripts/issue-management/parse-command.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ function parseCommand(commentBody) {
1515
const claimMatch = line.match(/^\/claim\s*$/i);
1616
if (claimMatch) return { command: 'claim' };
1717

18+
const unclaimMatch = line.match(/^\/unclaim\s*$/i);
19+
if (unclaimMatch) return { command: 'unclaim' };
20+
1821
const pingMatch = line.match(/^\/ping\s*$/i);
1922
if (pingMatch) return { command: 'ping' };
2023

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
async function handleUnclaim({ github, context }) {
2+
const { owner, repo } = context.repo;
3+
const issueNumber = context.payload.issue.number;
4+
const commenter = context.payload.comment.user.login;
5+
const issueState = context.payload.issue.state;
6+
7+
if (issueState === 'closed') {
8+
await github.rest.issues.createComment({
9+
owner,
10+
repo,
11+
issue_number: issueNumber,
12+
body: `❌ Commands cannot be used on closed issues.`,
13+
});
14+
return;
15+
}
16+
17+
const currentAssignees = context.payload.issue.assignees.map((a) => a.login.toLowerCase());
18+
19+
if (!currentAssignees.includes(commenter.toLowerCase())) {
20+
await github.rest.issues.createComment({
21+
owner,
22+
repo,
23+
issue_number: issueNumber,
24+
body: `ℹ️ @${commenter}, you are not currently assigned to this issue, so there's nothing to unclaim.`,
25+
});
26+
return;
27+
}
28+
29+
await github.rest.issues.removeAssignees({
30+
owner,
31+
repo,
32+
issue_number: issueNumber,
33+
assignees: [commenter],
34+
});
35+
36+
await github.rest.issues.createComment({
37+
owner,
38+
repo,
39+
issue_number: issueNumber,
40+
body: `✅ Successfully unclaimed this issue for @${commenter}.\n\n> 🔓 The issue is now open for others to claim.`,
41+
});
42+
}
43+
44+
module.exports = { handleUnclaim };

.github/workflows/assign-request-reminder.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
contains(github.event.comment.body, 'can i be assigned') ||
4343
contains(github.event.comment.body, 'assign me to this') ||
4444
contains(github.event.comment.body, 'assign me this') ||
45-
contains(github.event.comment.body, 'i will work on this') ||
45+
contains(github.event.comment.body, 'work on this') ||
4646
contains(github.event.comment.body, 'i''ll work on this') ||
4747
contains(github.event.comment.body, 'ill work on this') ||
4848
contains(github.event.comment.body, 'i can work on this') ||
@@ -94,7 +94,7 @@ jobs:
9494
`## 📋 A Few Things to Know`,
9595
``,
9696
`- You can hold a **maximum of 3 open issues** at a time.`,
97-
`- If there's **no activity for 2 days**, the assignment will automatically expire so others can pick it up.`,
97+
`- If there's **no activity for 3 days**, the assignment will automatically expire so others can pick it up.`,
9898
`- Make sure to read our **[CONTRIBUTING.md](https://github.com/${owner}/${repo}/blob/main/CONTRIBUTING.md)** before you start — it covers code style, commit conventions, and the PR checklist.`,
9999
``,
100100
`## 💬 Join Our Discord`,

.github/workflows/conflict-notifier.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ name: Merge Conflict Notifier
22

33
on:
44
schedule:
5-
- cron: '0 * * * *'
5+
- cron: '*/30 * * * *' # Hourly/half-hourly fallback
6+
push:
7+
branches:
8+
- main
9+
pull_request_target:
10+
types: [synchronize, reopened, edited]
611
workflow_dispatch:
712

813
permissions:
@@ -76,20 +81,33 @@ jobs:
7681
});
7782
}
7883
79-
// Check if we've already posted a conflict comment to avoid spam
84+
// Check existing comments to enforce a 2-hour notification gap
8085
const { data: comments } = await github.rest.issues.listComments({
8186
owner: context.repo.owner,
8287
repo: context.repo.repo,
8388
issue_number: pr.number,
8489
per_page: 100,
8590
});
8691
87-
const alreadyCommented = comments.some(c =>
92+
const conflictComments = comments.filter(c =>
8893
c.user?.login === 'github-actions[bot]' &&
8994
c.body?.includes('merge conflicts with the main branch')
9095
);
9196
92-
if (!alreadyCommented) {
97+
let shouldComment = false;
98+
if (conflictComments.length === 0) {
99+
shouldComment = true;
100+
} else {
101+
const lastComment = conflictComments[conflictComments.length - 1];
102+
const lastCommentTime = new Date(lastComment.created_at).getTime();
103+
const nowTime = new Date().getTime();
104+
const TWO_HOURS_MS = 2 * 60 * 60 * 1000;
105+
if (nowTime - lastCommentTime >= TWO_HOURS_MS) {
106+
shouldComment = true;
107+
}
108+
}
109+
110+
if (shouldComment) {
93111
await github.rest.issues.createComment({
94112
owner: context.repo.owner,
95113
repo: context.repo.repo,

.github/workflows/issue-management.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ jobs:
2222
contains(github.event.comment.body, '/assign') ||
2323
contains(github.event.comment.body, '/unassign') ||
2424
contains(github.event.comment.body, '/addlabel') ||
25-
contains(github.event.comment.body, '/claim')
25+
contains(github.event.comment.body, '/claim') ||
26+
contains(github.event.comment.body, '/unclaim')
2627
)
2728
steps:
2829
- name: Checkout Repository

.gitignore

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2-
3-
# dependencies
4-
/node_modules
5-
/.pnp
6-
.pnp.*
7-
.yarn/*
8-
!.yarn/patches
9-
!.yarn/plugins
10-
!.yarn/releases
11-
!.yarn/versions
12-
13-
# testing
14-
/coverage
15-
16-
# next.js
17-
/.next/
18-
/out/
19-
20-
# production
21-
/build
22-
23-
# misc
24-
.DS_Store
25-
*.pem
26-
27-
# debug
28-
npm-debug.log*
29-
yarn-debug.log*
30-
yarn-error.log*
31-
.pnpm-debug.log*
32-
33-
# env files — ignore all local secrets but commit the example template
34-
.env*
35-
!.env.local.example
36-
.env.local
37-
# vercel
38-
.vercel
39-
40-
# typescript
41-
*.tsbuildinfo
42-
next-env.d.ts
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files — ignore all local secrets but commit the example template
34+
.env*
35+
!.env.local.example
36+
.env.local
37+
# vercel
38+
.vercel
39+
40+
# typescript
41+
*.tsbuildinfo
42+
next-env.d.ts

CONTRIBUTING.md

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
- [The Standard We Hold](#-the-standard-we-hold)
1111
- [Local Setup](#-local-setup)
12+
- [Testing Your Changes](#-testing-your-changes)
1213
- [What to Contribute](#-what-to-contribute)
1314
- [Automated Issue Management & Claiming](#-automated-issue-management--claiming)
1415
- [Branch & Commit Conventions](#-branch--commit-conventions)
@@ -88,6 +89,110 @@ http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME
8889
8990
---
9091

92+
## 🧪 Testing Your Changes
93+
94+
This section covers everything you need to verify your changes work correctly **before opening a PR**. There are two layers of testing: visual browser preview and the automated test suite.
95+
96+
### 1. Visual Browser Preview
97+
98+
With your dev server running (`npm run dev`), open your browser and visit these URLs to preview the SVG output directly:
99+
100+
**Standard badge — valid username:**
101+
102+
```
103+
http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME
104+
```
105+
106+
**Monthly view:**
107+
108+
```
109+
http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME&view=monthly
110+
```
111+
112+
**Custom theme — test your color changes:**
113+
114+
```
115+
http://localhost:3000/api/streak?user=YOUR_GITHUB_USERNAME&theme=YOUR_THEME_NAME
116+
```
117+
118+
**Invalid username — must render a styled SVG error card, not raw JSON:**
119+
120+
```
121+
http://localhost:3000/api/streak?user=vivek%20Sangani
122+
```
123+
124+
**Non-existent username — must render the ghost-city not-found badge:**
125+
126+
```
127+
http://localhost:3000/api/streak?user=xyzabc999notreallll
128+
```
129+
130+
> **⚠️ Browser XML error warning:** If your browser shows an `EntityRef: expecting ';'` error instead of rendering the SVG, it means an unescaped `&` character exists somewhere in the SVG output. All `&` characters inside SVG `<style>` blocks (e.g. in Google Fonts `@import` URLs) must be written as `&amp;`. Check `lib/svg/generator.ts` for any raw `&` in template literals.
131+
132+
> **💡 Tip:** For a cleaner SVG preview, open the URL in **Firefox** — it renders SVG directly in the browser with no wrapper page. Chrome wraps it in an XML viewer which can show false parse warnings.
133+
134+
### 2. Running the Vitest Test Suite
135+
136+
CommitPulse uses **Vitest** for unit and integration tests. Run the full test suite with:
137+
138+
```bash
139+
npm run test
140+
```
141+
142+
To run tests in watch mode while you develop (reruns on every file save):
143+
144+
```bash
145+
npm run test -- --watch
146+
```
147+
148+
To run only a specific test file:
149+
150+
```bash
151+
npm run test -- lib/calculate.test.ts
152+
```
153+
154+
**What a passing run looks like:**
155+
156+
```
157+
✓ lib/calculate.test.ts (12 tests)
158+
✓ lib/svg/generator.test.ts (8 tests)
159+
✓ app/api/streak/route.test.ts (6 tests)
160+
161+
Test Files 3 passed (3)
162+
Tests 26 passed (26)
163+
```
164+
165+
> **🚨 All tests must pass before you open a PR.** The CI pipeline runs `npm run test` automatically on every pull request and will block merging if any test fails.
166+
167+
### 3. Interpreting SVG Output in the Browser
168+
169+
When you open a badge URL in your browser, here is what each response means:
170+
171+
| What you see | What it means |
172+
| -------------------------------------------- | ---------------------------------------------------------- |
173+
| Animated isometric city renders correctly | ✅ Everything is working |
174+
| Ghost-city badge with "NOT FOUND" label | ✅ Working — the username doesn't exist on GitHub |
175+
| Styled error card with "Invalid username" | ✅ Working — the username format was invalid |
176+
| Raw JSON `{"error":"Invalid parameters"...}` | ❌ Bug — validation errors must return SVG, not JSON |
177+
| Browser XML parse error / blank white page | ❌ Bug — unescaped `&` or malformed SVG in generator |
178+
| `401 Unauthorized` in the terminal | ❌ Your `GITHUB_PAT` in `.env.local` is missing or invalid |
179+
180+
### 4. Lint and Format
181+
182+
Run these before every commit:
183+
184+
```bash
185+
# Auto-format all files
186+
npm run format
187+
188+
# Check for linting errors
189+
npm run lint
190+
```
191+
192+
Fix every error before pushing. CI will fail if either check reports issues.
193+
194+
---
195+
91196
## 🤝 Contributor Onboarding
92197

93198
### 📁 Project Structure
@@ -233,6 +338,7 @@ Our automation runs entirely through issue comments. Here is how you interact wi
233338
| Command | Who Can Use It? | What It Does |
234339
| ----------------------------- | ------------------------------------------------------- | --------------------------------------------------------- |
235340
| `/claim` | **Issue Author (or Anyone if authored by jhasourav07)** | Self-assigns the issue to you. |
341+
| `/unclaim` | **Assigned Contributor** | Removes the assignment from yourself (opens it back up). |
236342
| `/addlabel <label1> <label2>` | **Anyone** | Adds labels to the issue (e.g. `/addlabel frontend bug`). |
237343
| `/unassign @username` | **Maintainers Only** | Removes the assignee from an issue. |
238344
| `/assign @username` | **Maintainers Only** | Manually assigns someone to an issue. |
@@ -258,7 +364,7 @@ To keep the project moving, assignments are not permanent.
258364
If the bot rejects your command, check these common scenarios:
259365

260366
- **"Commands cannot be used on closed issues"**: You cannot claim, assign, or unassign on closed issues. Find an open one!
261-
- **"You already have X/3 active assigned issues"**: You have reached the maximum of 3 concurrent assignments. Finish one of your current tasks before claiming a new issue. If you're stuck, ask a maintainer to `/unassign` you from one.
367+
- **"You already have X/3 active assigned issues"**: You have reached the maximum of 3 concurrent assignments. Finish one of your current tasks before claiming a new issue. If you're stuck, use the `/unclaim` command to unassign yourself from an issue, or ask a maintainer to `/unassign` you.
262368
- **"This issue is already assigned to @username"**: Be faster next time! Look for issues without assignees.
263369
- **"Only the author of this issue can claim it"**: You tried to `/claim` an issue you did not create. You can only claim issues that you authored (unless the issue was authored by `jhasourav07`, which anyone can claim).
264370
- **"The following label(s) do not exist"**: You can only add existing repo labels. The bot will reply with a list of valid labels you can use.

0 commit comments

Comments
 (0)