Skip to content

Commit b80ca97

Browse files
Merge branch 'main' into test-validation-timezone-boundary
2 parents b979b44 + e6b5723 commit b80ca97

66 files changed

Lines changed: 6726 additions & 1026 deletions

Some content is hidden

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

.github/workflows/conflict-notifier.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
});
8282
}
8383
84-
// Check existing comments to enforce a 2-hour notification gap
84+
// Check existing comments to enforce a 24-hour notification gap
8585
const { data: comments } = await github.rest.issues.listComments({
8686
owner: context.repo.owner,
8787
repo: context.repo.repo,
@@ -101,8 +101,8 @@ jobs:
101101
const lastComment = conflictComments[conflictComments.length - 1];
102102
const lastCommentTime = new Date(lastComment.created_at).getTime();
103103
const nowTime = new Date().getTime();
104-
const TWO_HOURS_MS = 2 * 60 * 60 * 1000;
105-
if (nowTime - lastCommentTime >= TWO_HOURS_MS) {
104+
const TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1000;
105+
if (nowTime - lastCommentTime >= TWENTY_FOUR_HOURS_MS) {
106106
shouldComment = true;
107107
}
108108
}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ URL Parameter > Theme Default > System Fallback
189189
| `labelColor` | `hex` | No || Custom text color for the isometric labels — **without** `#` |
190190
| `versus` | `string` | No || GitHub username of an opponent to compare against in side-by-side versus mode |
191191
| `shading` | `boolean` | No | `false` | Apply intensity-based opacity shading to tower faces so lower intensity levels appear slightly dimmer |
192+
| `opacity` | `number` | No | `1.0` | Global opacity scalar for all tower fill-opacity values (0.1–1.0). `opacity=0.5` = semi-transparent ghost look. `opacity=0.8` = faded, great on light backgrounds. |
192193
| `gradient` | `boolean` | No | `false` | Opt-in to show volumetric gradients on the monolith floor |
193194

194195
### Grace Period Examples
@@ -322,6 +323,14 @@ Explore some of the built-in CommitPulse themes and quickly copy the style you l
322323

323324
![](https://commitpulse.vercel.app/api/streak?user=jhasourav07&gradient=true&shading=true)
324325

326+
<!-- Semi-transparent ghost city look -->
327+
328+
![](https://commitpulse.vercel.app/api/streak?user=jhasourav07&opacity=0.5)
329+
330+
<!-- Slightly faded — perfect for light background embeds -->
331+
332+
![](https://commitpulse.vercel.app/api/streak?user=jhasourav07&opacity=0.8)
333+
325334
<!-- GitHub-style Heatmap View -->
326335

327336
![](https://commitpulse.vercel.app/api/streak?user=jhasourav07&view=heatmap)

app/(root)/dashboard/[username]/page.test.tsx

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ vi.mock('@/components/dashboard/Heatmap', () => ({
5656
),
5757
}));
5858

59+
vi.mock('@/components/dashboard/HistoricalTrendView', () => ({
60+
default: ({ period, activity }: { period: { label: string }; activity: unknown[] }) => (
61+
<div data-testid="historical-trend-view" data-prop={JSON.stringify(activity)}>
62+
{period.label}
63+
</div>
64+
),
65+
}));
66+
5967
vi.mock('@/components/dashboard/AIInsights', () => ({
6068
default: () => <div data-testid="ai-insights">AIInsights</div>,
6169
}));
@@ -147,9 +155,15 @@ describe('DashboardPage', () => {
147155

148156
render(PageContent);
149157

150-
expect(getFullDashboardData).toHaveBeenCalledWith('octocat', {
151-
bypassCache: false,
152-
});
158+
expect(getFullDashboardData).toHaveBeenCalledWith(
159+
'octocat',
160+
expect.objectContaining({
161+
bypassCache: false,
162+
from: expect.any(String),
163+
to: expect.any(String),
164+
rangeLabel: 'Last 12 months',
165+
})
166+
);
153167

154168
const generateLink = screen.getByText('Generate Your Own').closest('a');
155169
expect(generateLink).toBeDefined();
@@ -158,7 +172,7 @@ describe('DashboardPage', () => {
158172
expect(screen.getByTestId('activity-landscape')).toBeDefined();
159173
expect(screen.getByTestId('language-chart')).toBeDefined();
160174
expect(screen.getByTestId('commit-clock')).toBeDefined();
161-
expect(screen.getByTestId('heatmap')).toBeDefined();
175+
expect(screen.getByTestId('historical-trend-view')).toBeDefined();
162176
expect(screen.getByTestId('ai-insights')).toBeDefined();
163177
expect(screen.getByTestId('achievements')).toBeDefined();
164178
expect(screen.getAllByTestId('stats-card')).toHaveLength(3);
@@ -175,21 +189,46 @@ describe('DashboardPage', () => {
175189

176190
render(PageContent);
177191

178-
expect(getFullDashboardData).toHaveBeenCalledWith('octocat', {
179-
bypassCache: true,
192+
expect(getFullDashboardData).toHaveBeenCalledWith(
193+
'octocat',
194+
expect.objectContaining({
195+
bypassCache: true,
196+
from: expect.any(String),
197+
to: expect.any(String),
198+
rangeLabel: 'Last 12 months',
199+
})
200+
);
201+
});
202+
203+
it('passes a calendar-year query through to getFullDashboardData', async () => {
204+
const PageContent = await DashboardPage({
205+
params: Promise.resolve({ username: 'octocat' }),
206+
searchParams: Promise.resolve({ year: '2024' }),
180207
});
208+
209+
render(PageContent);
210+
211+
expect(getFullDashboardData).toHaveBeenCalledWith(
212+
'octocat',
213+
expect.objectContaining({
214+
bypassCache: false,
215+
from: '2024-01-01T00:00:00.000Z',
216+
to: '2024-12-31T23:59:59.999Z',
217+
rangeLabel: '2024',
218+
})
219+
);
181220
});
182221

183-
it('passes the correct activity data to Heatmap', async () => {
222+
it('passes the correct activity data to the historical trend view', async () => {
184223
const PageContent = await DashboardPage({
185224
params: Promise.resolve({ username: 'octocat' }),
186225
searchParams: Promise.resolve({}),
187226
});
188227

189228
render(PageContent);
190229

191-
const heatmap = screen.getByTestId('heatmap');
192-
expect(JSON.parse(heatmap.getAttribute('data-prop') ?? '[]')).toEqual(mockData.activity);
230+
const trendView = screen.getByTestId('historical-trend-view');
231+
expect(JSON.parse(trendView.getAttribute('data-prop') ?? '[]')).toEqual(mockData.activity);
193232
});
194233

195234
it('calls notFound when dashboard data fetch throws an error', async () => {

app/(root)/dashboard/[username]/page.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Metadata } from 'next';
44
import DashboardClient from '@/components/dashboard/DashboardClient';
55
import { getFullDashboardData, fetchUserProfile } from '@/lib/github';
66
import { notFound, redirect } from 'next/navigation';
7+
import { resolveDashboardPeriod } from '@/utils/dashboardPeriod';
78

89
export const revalidate = 3600; // Cache for 1 hour
910

@@ -60,16 +61,33 @@ export default async function DashboardPage({
6061
searchParams,
6162
}: {
6263
params: Promise<{ username: string }>;
63-
searchParams: Promise<{ refresh?: string }>;
64+
searchParams: Promise<{
65+
refresh?: string;
66+
year?: string;
67+
month?: string;
68+
from?: string;
69+
to?: string;
70+
}>;
6471
}) {
6572
const { username } = await params;
66-
const refreshParams = await searchParams;
67-
const bypassCache = refreshParams?.refresh === 'true';
73+
const resolvedSearchParams = await searchParams;
74+
const bypassCache = resolvedSearchParams?.refresh === 'true';
75+
const period = resolveDashboardPeriod({
76+
year: resolvedSearchParams?.year,
77+
month: resolvedSearchParams?.month,
78+
from: resolvedSearchParams?.from,
79+
to: resolvedSearchParams?.to,
80+
});
6881

6982
let data;
7083

7184
try {
72-
data = await getFullDashboardData(username, { bypassCache });
85+
data = await getFullDashboardData(username, {
86+
bypassCache,
87+
from: period.from,
88+
to: period.to,
89+
rangeLabel: period.label,
90+
});
7391
} catch (error) {
7492
if (error instanceof Error && error.message.includes('not found')) {
7593
// Smart Redirect: If the GraphQL "user" query fails, check if it's actually an Organization
@@ -87,5 +105,5 @@ export default async function DashboardPage({
87105
throw error;
88106
}
89107

90-
return <DashboardClient initialData={data} username={username} />;
108+
return <DashboardClient initialData={data} username={username} period={period} />;
91109
}

app/api/compare/route.test.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { GET } from './route';
3+
4+
vi.mock('@/lib/github', () => ({
5+
getFullDashboardData: vi.fn(),
6+
}));
7+
8+
import { getFullDashboardData } from '@/lib/github';
9+
10+
const makeRequest = (search: string) => new Request(`http://localhost:3000/api/compare?${search}`);
11+
12+
describe('GET /api/compare', () => {
13+
beforeEach(() => {
14+
vi.clearAllMocks();
15+
vi.mocked(getFullDashboardData).mockResolvedValue({
16+
calendar: { totalContributions: 50, weeks: [] },
17+
} as never);
18+
});
19+
20+
// ── Validation ────────────────────────────────────────────────────────────
21+
22+
it('returns 400 when user1 is missing', async () => {
23+
const res = await GET(makeRequest('user2=octocat'));
24+
expect(res.status).toBe(400);
25+
});
26+
27+
it('returns 400 when user2 is missing', async () => {
28+
const res = await GET(makeRequest('user1=octocat'));
29+
expect(res.status).toBe(400);
30+
});
31+
32+
it('returns 400 when both users are missing', async () => {
33+
const res = await GET(makeRequest(''));
34+
expect(res.status).toBe(400);
35+
});
36+
37+
it('returns 400 for invalid GitHub username format for user1', async () => {
38+
const res = await GET(makeRequest('user1=-invalid&user2=octocat'));
39+
expect(res.status).toBe(400);
40+
const data = await res.json();
41+
expect(data.details.fieldErrors.user1).toBeDefined();
42+
});
43+
44+
it('returns 400 for invalid GitHub username format for user2', async () => {
45+
const res = await GET(makeRequest('user1=octocat&user2=-invalid'));
46+
expect(res.status).toBe(400);
47+
const data = await res.json();
48+
expect(data.details.fieldErrors.user2).toBeDefined();
49+
});
50+
51+
it('returns 400 for username exceeding 39 characters', async () => {
52+
const res = await GET(makeRequest(`user1=${'a'.repeat(40)}&user2=octocat`));
53+
expect(res.status).toBe(400);
54+
});
55+
56+
it('returns 400 when comparing a user with themselves', async () => {
57+
const res = await GET(makeRequest('user1=octocat&user2=octocat'));
58+
expect(res.status).toBe(400);
59+
const data = await res.json();
60+
expect(data.details.fieldErrors.user2).toContain('Cannot compare a user with themselves.');
61+
});
62+
63+
it('returns 400 for self-comparison regardless of case', async () => {
64+
const res = await GET(makeRequest('user1=OctoCat&user2=octocat'));
65+
expect(res.status).toBe(400);
66+
});
67+
68+
// ── Success ──────────────────────────────────────────────────────────────
69+
70+
it('returns 200 with comparison data for valid users', async () => {
71+
const res = await GET(makeRequest('user1=alice&user2=bob'));
72+
expect(res.status).toBe(200);
73+
const data = await res.json();
74+
expect(data.user1).toBeDefined();
75+
expect(data.user2).toBeDefined();
76+
});
77+
78+
// ── Error handling ────────────────────────────────────────────────────────
79+
80+
it('returns 404 when user1 is not found on GitHub', async () => {
81+
vi.mocked(getFullDashboardData).mockRejectedValueOnce(new Error('Not found'));
82+
const res = await GET(makeRequest('user1=ghost123&user2=octocat'));
83+
expect(res.status).toBe(404);
84+
});
85+
86+
it('returns 404 when user2 is not found on GitHub', async () => {
87+
vi.mocked(getFullDashboardData)
88+
.mockResolvedValueOnce({ calendar: { totalContributions: 0, weeks: [] } } as never)
89+
.mockRejectedValueOnce(new Error('Not found'));
90+
const res = await GET(makeRequest('user1=octocat&user2=ghost123'));
91+
expect(res.status).toBe(404);
92+
});
93+
});

app/api/compare/route.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { NextResponse } from 'next/server';
22
import { getFullDashboardData } from '@/lib/github';
3+
import { compareParamsSchema } from '@/lib/validations';
34

45
export const revalidate = 3600;
56

67
export async function GET(request: Request) {
78
const { searchParams } = new URL(request.url);
8-
const user1 = searchParams.get('user1');
9-
const user2 = searchParams.get('user2');
109

11-
if (!user1 || !user2) {
10+
const parseResult = compareParamsSchema.safeParse(Object.fromEntries(searchParams.entries()));
11+
12+
if (!parseResult.success) {
13+
const fieldErrors = parseResult.error.flatten();
1214
return NextResponse.json(
13-
{ error: 'Both user1 and user2 query parameters are required.' },
15+
{ error: 'Invalid parameters', details: fieldErrors },
1416
{ status: 400 }
1517
);
1618
}
1719

18-
if (user1.toLowerCase() === user2.toLowerCase()) {
19-
return NextResponse.json({ error: 'Cannot compare a user with themselves.' }, { status: 400 });
20-
}
20+
const { user1, user2 } = parseResult.data;
2121

2222
try {
2323
const [result1, result2] = await Promise.allSettled([

0 commit comments

Comments
 (0)