From 7b380476b5d8c2b08374e7f96bfc1c8382f657b3 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:12:41 +1030 Subject: [PATCH 01/10] feat: add quarter and half activity scales between a month and a year --- app/Enums/ActivityScale.php | 10 +++++--- tests/Unit/Queries/UserActivityQueryTest.php | 25 +++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/Enums/ActivityScale.php b/app/Enums/ActivityScale.php index 0554828e1..5c99c21d3 100644 --- a/app/Enums/ActivityScale.php +++ b/app/Enums/ActivityScale.php @@ -12,6 +12,8 @@ enum ActivityScale: string case Day = 'day'; case Week = 'week'; case Month = 'month'; + case Quarter = 'quarter'; + case Half = 'half'; case Year = 'year'; /** @@ -19,7 +21,7 @@ enum ActivityScale: string */ public static function since(CarbonInterface $since, CarbonImmutable $now): self { - foreach ([self::Day, self::Week, self::Month] as $scale) { + foreach ([self::Day, self::Week, self::Month, self::Quarter, self::Half] as $scale) { if ($since->greaterThanOrEqualTo($scale->start($now))) { return $scale; } @@ -34,13 +36,15 @@ public function start(CarbonImmutable $now): CarbonImmutable self::Day => $now->startOfHour()->subHours(23), self::Week => $now->startOfDay()->subDays(6), self::Month => $now->startOfDay()->subDays(29), + self::Quarter => $now->subWeeks(12)->startOfWeek(CarbonInterface::SUNDAY), + self::Half => $now->subWeeks(25)->startOfWeek(CarbonInterface::SUNDAY), self::Year => $now->subWeeks(52)->startOfWeek(CarbonInterface::SUNDAY), }; } /** * The start of the window ending now, as the operations page has always counted: the last 24 hours, 7 days, or - * 30 days. The year keeps its whole weeks, since its grid needs them. + * 30 days. The week grids keep their whole weeks, since they need them. */ public function rollingStart(CarbonImmutable $now): CarbonImmutable { @@ -48,7 +52,7 @@ public function rollingStart(CarbonImmutable $now): CarbonImmutable self::Day => $now->subDay(), self::Week => $now->subWeek(), self::Month => $now->subDays(30), - self::Year => $this->start($now), + self::Quarter, self::Half, self::Year => $this->start($now), }; } diff --git a/tests/Unit/Queries/UserActivityQueryTest.php b/tests/Unit/Queries/UserActivityQueryTest.php index 7f30bb22b..1440e49eb 100644 --- a/tests/Unit/Queries/UserActivityQueryTest.php +++ b/tests/Unit/Queries/UserActivityQueryTest.php @@ -25,7 +25,11 @@ 'start of the last 7 days' => ['2026-10-09 00:00:00', ActivityScale::Week], 'just before the last 7 days' => ['2026-10-08 23:59:59', ActivityScale::Month], 'start of the last 30 days' => ['2026-09-16 00:00:00', ActivityScale::Month], - 'just before the last 30 days' => ['2026-09-15 23:59:59', ActivityScale::Year], + 'just before the last 30 days' => ['2026-09-15 23:59:59', ActivityScale::Quarter], + 'start of the last 13 weeks' => ['2026-07-19 00:00:00', ActivityScale::Quarter], + 'just before the last 13 weeks' => ['2026-07-18 23:59:59', ActivityScale::Half], + 'start of the last 26 weeks' => ['2026-04-19 00:00:00', ActivityScale::Half], + 'just before the last 26 weeks' => ['2026-04-18 23:59:59', ActivityScale::Year], 'years ago' => ['2024-01-01 00:00:00', ActivityScale::Year], ]); @@ -41,6 +45,8 @@ 'just now' => ['2026-10-15 12:30:00', ActivityScale::Day], 'three days ago' => ['2026-10-12 09:00:00', ActivityScale::Week], 'two weeks ago' => ['2026-10-01 09:00:00', ActivityScale::Month], + 'two months ago' => ['2026-08-15 09:00:00', ActivityScale::Quarter], + 'four months ago' => ['2026-06-15 09:00:00', ActivityScale::Half], 'two years ago' => ['2024-10-15 09:00:00', ActivityScale::Year], ]); @@ -85,6 +91,23 @@ ]); }); +it('counts the commits of each day of the weeks since the first one', function (string $since, ActivityScale $scale, string $first, int $days): void { + $user = User::factory()->create(); + + Commit::factory()->for($user)->create(['created_at' => $since]); + Commit::factory()->for($user)->count(2)->create(); + + $activity = resolve(UserActivityQuery::class)->get($user, $user); + + expect($activity['scale'])->toBe($scale) + ->and($activity['buckets'])->toHaveCount($days) + ->and($activity['buckets'][0]['date'])->toBe($first) + ->and(end($activity['buckets']))->toBe(['date' => '2026-10-15', 'count' => 2]); +})->with([ + 'quarter' => ['2026-08-15 09:00:00', ActivityScale::Quarter, '2026-07-19', 89], + 'half' => ['2026-06-15 09:00:00', ActivityScale::Half, '2026-04-19', 180], +]); + it('counts the commits of each day of the last 30 days', function (): void { $user = User::factory()->create(); From 45788cf55f23efa26ba27a6916c6c3af595adb3a Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:17:34 +1030 Subject: [PATCH 02/10] feat: keep the quarter and half scales off the operations activity page --- app/Http/Requests/ShowSiteActivityRequest.php | 2 +- .../Feature/Controllers/Api/UserControllerTest.php | 14 ++++++++++++++ .../Controllers/SiteActivityControllerTest.php | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/ShowSiteActivityRequest.php b/app/Http/Requests/ShowSiteActivityRequest.php index 202649e22..29aeb381a 100644 --- a/app/Http/Requests/ShowSiteActivityRequest.php +++ b/app/Http/Requests/ShowSiteActivityRequest.php @@ -27,7 +27,7 @@ public function authorize(): Response public function rules(): array { return [ - 'scale' => ['nullable', Rule::enum(ActivityScale::class)], + 'scale' => ['nullable', Rule::enum(ActivityScale::class)->only([ActivityScale::Day, ActivityScale::Week, ActivityScale::Month, ActivityScale::Year])], 'metric' => ['nullable', Rule::enum(ActivityMetric::class)], ]; } diff --git a/tests/Feature/Controllers/Api/UserControllerTest.php b/tests/Feature/Controllers/Api/UserControllerTest.php index f15b3390a..f527878bd 100644 --- a/tests/Feature/Controllers/Api/UserControllerTest.php +++ b/tests/Feature/Controllers/Api/UserControllerTest.php @@ -180,6 +180,20 @@ expect(json_decode($response->getContent(), flags: JSON_THROW_ON_ERROR)->bio_profiles)->toBeInstanceOf(stdClass::class); }); +it('returns the quarter scale for a profile whose first visible commit is two months old', function (): void { + $this->travelTo(now()->setDate(2026, 10, 15)->setTime(12, 0)); + + $keyPair = apiKeyPairFor(User::factory()->create()); + $user = User::factory()->create(); + + Commit::factory()->for($user)->create(['created_at' => '2026-08-15 09:00:00']); + + signedApiRequest($keyPair, 'GET', route('api-user.show', $user)) + ->assertOk() + ->assertJsonPath('activity.scale', 'quarter') + ->assertJsonCount(89, 'activity.buckets'); +}); + it('counts the pending commits of a signed-in user on their own profile', function (): void { $user = User::factory()->create(); $keyPair = apiKeyPairFor($user); diff --git a/tests/Feature/Controllers/SiteActivityControllerTest.php b/tests/Feature/Controllers/SiteActivityControllerTest.php index 06d42c086..79970dc6e 100644 --- a/tests/Feature/Controllers/SiteActivityControllerTest.php +++ b/tests/Feature/Controllers/SiteActivityControllerTest.php @@ -71,6 +71,8 @@ ->assertSessionHasErrors(); })->with([ 'unknown scale' => [['scale' => 'decade']], + 'quarter scale' => [['scale' => 'quarter']], + 'half scale' => [['scale' => 'half']], 'unknown series' => [['metric' => 'stars']], ]); From 113d092edc2ade14d9da2a711383a3d8ed22b2f0 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:18:33 +1030 Subject: [PATCH 03/10] feat: draw the quarter and half activity scales as shorter week grids --- resources/js/components/activity-graph.tsx | 41 +++++++++++++++++---- resources/js/types/activity.ts | 8 ++++- tests/Unit/ActivityCells.test.tsx | 42 ++++++++++++++++++++++ 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/resources/js/components/activity-graph.tsx b/resources/js/components/activity-graph.tsx index 937f6792b..f1576d423 100644 --- a/resources/js/components/activity-graph.tsx +++ b/resources/js/components/activity-graph.tsx @@ -33,9 +33,18 @@ export const activityWindows: Record = { day: 'in the last 24 hours', week: 'in the last 7 days', month: 'in the last 30 days', + quarter: 'in the last 3 months', + half: 'in the last 6 months', year: 'in the last year', }; +/** + * The scales drawn as a grid of weeks, one column per week, rather than a strip. + */ +export function isWeekGrid(scale: ActivityScale): boolean { + return scale === 'quarter' || scale === 'half' || scale === 'year'; +} + function levelColor(level: number): string { return level === 0 ? 'var(--muted)' @@ -85,7 +94,7 @@ export function activitySummary( ): string { const total = activityTotal(activity); - return total === 0 && activity.scale !== 'year' + return total === 0 && !isWeekGrid(activity.scale) ? `No ${noun[1]} yet` : `${count(total, noun)} ${activityWindows[activity.scale]}`; } @@ -178,7 +187,7 @@ export function ActivityGraph({ onPeriodHover?: (period: string | null) => void; }) { const total = activityTotal(activity); - const isEmpty = total === 0 && activity.scale !== 'year'; + const isEmpty = total === 0 && !isWeekGrid(activity.scale); return (
- {scale === 'year' ? ( - index % 7 === 0); const monthLabels = weekStarts.map((day, index) => { const changesMonth = @@ -425,7 +442,17 @@ function YearGrid({
{ + assert.equal( + activitySummary( + { scale: 'quarter', buckets: [{ date: '2026-10-15', count: 3 }] }, + ['commit', 'commits'], + ), + '3 commits in the last 3 months', + ); + assert.equal( + activitySummary({ scale: 'half', buckets: [] }, ['commit', 'commits']), + '0 commits in the last 6 months', + ); +}); + +test('draws quarter, half and year as week grids with one column per week', () => { + for (const [scale, weeks] of [ + ['quarter', 13], + ['half', 26], + ['year', 53], + ] as const) { + const buckets = Array.from({ length: weeks * 7 }, (_, day) => ({ + date: new Date(Date.UTC(2026, 0, 4 + day)) + .toISOString() + .slice(0, 10), + count: day % 3, + })); + const html = renderToString( + , + ); + + assert.match( + html, + new RegExp(`repeat\\(${weeks}, minmax\\(0, 1fr\\)\\)`), + ); + assert.match(html, /grid-rows-7/); + } +}); From 9c68a77d74b794de63ec3ec2a5a2a772c17cbd53 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:20:36 +1030 Subject: [PATCH 04/10] fix: size the quarter grid's cells closer to the year grid's --- resources/js/components/activity-graph.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/components/activity-graph.tsx b/resources/js/components/activity-graph.tsx index f1576d423..af3973f30 100644 --- a/resources/js/components/activity-graph.tsx +++ b/resources/js/components/activity-graph.tsx @@ -399,7 +399,7 @@ function Strip({ /** * Shorter grids cap each week's column, so a few weeks don't stretch into oversized cells. */ -const weekPitch = '2rem'; +const weekPitch = '1.5rem'; function WeekGrid({ scale, From e21d45db72dbfa962b99608a7ebc5fc4633cf68e Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:23:58 +1030 Subject: [PATCH 05/10] fix: leave the last week of the activity grid unlabelled so a new month cannot spill past it --- resources/js/components/activity-graph.tsx | 4 +++- tests/Unit/ActivityCells.test.tsx | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/resources/js/components/activity-graph.tsx b/resources/js/components/activity-graph.tsx index af3973f30..b3f1fc286 100644 --- a/resources/js/components/activity-graph.tsx +++ b/resources/js/components/activity-graph.tsx @@ -421,7 +421,9 @@ function WeekGrid({ .slice(1, 3) .some((week) => monthOf(week.date) !== monthOf(day.date)); - return changesMonth && !nextLabelIsClose + const isLastWeek = index === weekStarts.length - 1; + + return changesMonth && !nextLabelIsClose && !isLastWeek ? monthNames[monthOf(day.date)] : null; }); diff --git a/tests/Unit/ActivityCells.test.tsx b/tests/Unit/ActivityCells.test.tsx index d3651300f..92b047384 100644 --- a/tests/Unit/ActivityCells.test.tsx +++ b/tests/Unit/ActivityCells.test.tsx @@ -132,3 +132,20 @@ test('draws quarter, half and year as week grids with one column per week', () = assert.match(html, /grid-rows-7/); } }); + +test('leaves the last week unlabelled when it starts a month, so the label cannot spill past the grid', () => { + const buckets = Array.from({ length: 26 * 7 }, (_, day) => ({ + date: new Date(Date.UTC(2026, 4, 10 + day)).toISOString().slice(0, 10), + count: 1, + })); + const html = renderToString( + , + ); + + assert.match(html, /whitespace-nowrap">OctNov Date: Sat, 21 Nov 2026 13:30:00 +1030 Subject: [PATCH 06/10] refactor: drop the quarter activity scale, so profiles go from a month straight to half a year --- app/Enums/ActivityScale.php | 6 ++--- .../Controllers/Api/UserControllerTest.php | 6 ++--- .../SiteActivityControllerTest.php | 1 - tests/Unit/Queries/UserActivityQueryTest.php | 22 ++++++++----------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/Enums/ActivityScale.php b/app/Enums/ActivityScale.php index 5c99c21d3..25e8b3f56 100644 --- a/app/Enums/ActivityScale.php +++ b/app/Enums/ActivityScale.php @@ -12,7 +12,6 @@ enum ActivityScale: string case Day = 'day'; case Week = 'week'; case Month = 'month'; - case Quarter = 'quarter'; case Half = 'half'; case Year = 'year'; @@ -21,7 +20,7 @@ enum ActivityScale: string */ public static function since(CarbonInterface $since, CarbonImmutable $now): self { - foreach ([self::Day, self::Week, self::Month, self::Quarter, self::Half] as $scale) { + foreach ([self::Day, self::Week, self::Month, self::Half] as $scale) { if ($since->greaterThanOrEqualTo($scale->start($now))) { return $scale; } @@ -36,7 +35,6 @@ public function start(CarbonImmutable $now): CarbonImmutable self::Day => $now->startOfHour()->subHours(23), self::Week => $now->startOfDay()->subDays(6), self::Month => $now->startOfDay()->subDays(29), - self::Quarter => $now->subWeeks(12)->startOfWeek(CarbonInterface::SUNDAY), self::Half => $now->subWeeks(25)->startOfWeek(CarbonInterface::SUNDAY), self::Year => $now->subWeeks(52)->startOfWeek(CarbonInterface::SUNDAY), }; @@ -52,7 +50,7 @@ public function rollingStart(CarbonImmutable $now): CarbonImmutable self::Day => $now->subDay(), self::Week => $now->subWeek(), self::Month => $now->subDays(30), - self::Quarter, self::Half, self::Year => $this->start($now), + self::Half, self::Year => $this->start($now), }; } diff --git a/tests/Feature/Controllers/Api/UserControllerTest.php b/tests/Feature/Controllers/Api/UserControllerTest.php index f527878bd..e42e8dee2 100644 --- a/tests/Feature/Controllers/Api/UserControllerTest.php +++ b/tests/Feature/Controllers/Api/UserControllerTest.php @@ -180,7 +180,7 @@ expect(json_decode($response->getContent(), flags: JSON_THROW_ON_ERROR)->bio_profiles)->toBeInstanceOf(stdClass::class); }); -it('returns the quarter scale for a profile whose first visible commit is two months old', function (): void { +it('returns the half scale for a profile whose first visible commit is two months old', function (): void { $this->travelTo(now()->setDate(2026, 10, 15)->setTime(12, 0)); $keyPair = apiKeyPairFor(User::factory()->create()); @@ -190,8 +190,8 @@ signedApiRequest($keyPair, 'GET', route('api-user.show', $user)) ->assertOk() - ->assertJsonPath('activity.scale', 'quarter') - ->assertJsonCount(89, 'activity.buckets'); + ->assertJsonPath('activity.scale', 'half') + ->assertJsonCount(180, 'activity.buckets'); }); it('counts the pending commits of a signed-in user on their own profile', function (): void { diff --git a/tests/Feature/Controllers/SiteActivityControllerTest.php b/tests/Feature/Controllers/SiteActivityControllerTest.php index 79970dc6e..0269b234d 100644 --- a/tests/Feature/Controllers/SiteActivityControllerTest.php +++ b/tests/Feature/Controllers/SiteActivityControllerTest.php @@ -71,7 +71,6 @@ ->assertSessionHasErrors(); })->with([ 'unknown scale' => [['scale' => 'decade']], - 'quarter scale' => [['scale' => 'quarter']], 'half scale' => [['scale' => 'half']], 'unknown series' => [['metric' => 'stars']], ]); diff --git a/tests/Unit/Queries/UserActivityQueryTest.php b/tests/Unit/Queries/UserActivityQueryTest.php index 1440e49eb..84d8ee7fc 100644 --- a/tests/Unit/Queries/UserActivityQueryTest.php +++ b/tests/Unit/Queries/UserActivityQueryTest.php @@ -25,9 +25,7 @@ 'start of the last 7 days' => ['2026-10-09 00:00:00', ActivityScale::Week], 'just before the last 7 days' => ['2026-10-08 23:59:59', ActivityScale::Month], 'start of the last 30 days' => ['2026-09-16 00:00:00', ActivityScale::Month], - 'just before the last 30 days' => ['2026-09-15 23:59:59', ActivityScale::Quarter], - 'start of the last 13 weeks' => ['2026-07-19 00:00:00', ActivityScale::Quarter], - 'just before the last 13 weeks' => ['2026-07-18 23:59:59', ActivityScale::Half], + 'just before the last 30 days' => ['2026-09-15 23:59:59', ActivityScale::Half], 'start of the last 26 weeks' => ['2026-04-19 00:00:00', ActivityScale::Half], 'just before the last 26 weeks' => ['2026-04-18 23:59:59', ActivityScale::Year], 'years ago' => ['2024-01-01 00:00:00', ActivityScale::Year], @@ -45,7 +43,7 @@ 'just now' => ['2026-10-15 12:30:00', ActivityScale::Day], 'three days ago' => ['2026-10-12 09:00:00', ActivityScale::Week], 'two weeks ago' => ['2026-10-01 09:00:00', ActivityScale::Month], - 'two months ago' => ['2026-08-15 09:00:00', ActivityScale::Quarter], + 'two months ago' => ['2026-08-15 09:00:00', ActivityScale::Half], 'four months ago' => ['2026-06-15 09:00:00', ActivityScale::Half], 'two years ago' => ['2024-10-15 09:00:00', ActivityScale::Year], ]); @@ -91,22 +89,20 @@ ]); }); -it('counts the commits of each day of the weeks since the first one', function (string $since, ActivityScale $scale, string $first, int $days): void { +it('counts the commits of each day of the last 26 weeks', function (): void { $user = User::factory()->create(); - Commit::factory()->for($user)->create(['created_at' => $since]); + Commit::factory()->for($user)->create(['created_at' => '2026-06-15 09:00:00']); Commit::factory()->for($user)->count(2)->create(); $activity = resolve(UserActivityQuery::class)->get($user, $user); - expect($activity['scale'])->toBe($scale) - ->and($activity['buckets'])->toHaveCount($days) - ->and($activity['buckets'][0]['date'])->toBe($first) + expect($activity['scale'])->toBe(ActivityScale::Half) + ->and($activity['buckets'])->toHaveCount(180) + ->and($activity['buckets'][0])->toBe(['date' => '2026-04-19', 'count' => 0]) + ->and($activity['buckets'][57])->toBe(['date' => '2026-06-15', 'count' => 1]) ->and(end($activity['buckets']))->toBe(['date' => '2026-10-15', 'count' => 2]); -})->with([ - 'quarter' => ['2026-08-15 09:00:00', ActivityScale::Quarter, '2026-07-19', 89], - 'half' => ['2026-06-15 09:00:00', ActivityScale::Half, '2026-04-19', 180], -]); +}); it('counts the commits of each day of the last 30 days', function (): void { $user = User::factory()->create(); From 25435ceba7a11a20758f5e4ea4e6632f3cf51272 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:30:26 +1030 Subject: [PATCH 07/10] refactor: drop the quarter activity grid from the profile --- resources/js/components/activity-graph.tsx | 3 +-- resources/js/types/activity.ts | 1 - tests/Unit/ActivityCells.test.tsx | 9 ++++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/resources/js/components/activity-graph.tsx b/resources/js/components/activity-graph.tsx index b3f1fc286..3c599fadd 100644 --- a/resources/js/components/activity-graph.tsx +++ b/resources/js/components/activity-graph.tsx @@ -33,7 +33,6 @@ export const activityWindows: Record = { day: 'in the last 24 hours', week: 'in the last 7 days', month: 'in the last 30 days', - quarter: 'in the last 3 months', half: 'in the last 6 months', year: 'in the last year', }; @@ -42,7 +41,7 @@ export const activityWindows: Record = { * The scales drawn as a grid of weeks, one column per week, rather than a strip. */ export function isWeekGrid(scale: ActivityScale): boolean { - return scale === 'quarter' || scale === 'half' || scale === 'year'; + return scale === 'half' || scale === 'year'; } function levelColor(level: number): string { diff --git a/resources/js/types/activity.ts b/resources/js/types/activity.ts index 6d1a59f52..2af4c22cc 100644 --- a/resources/js/types/activity.ts +++ b/resources/js/types/activity.ts @@ -2,7 +2,6 @@ export type ActivityScale = | 'day' | 'week' | 'month' - | 'quarter' | 'half' | 'year'; diff --git a/tests/Unit/ActivityCells.test.tsx b/tests/Unit/ActivityCells.test.tsx index 92b047384..d0bbfe1d3 100644 --- a/tests/Unit/ActivityCells.test.tsx +++ b/tests/Unit/ActivityCells.test.tsx @@ -91,13 +91,13 @@ test('labels the cells with the summary and paints them in the given color', () assert.match(html, /--lane:var\(--muted-foreground\)/); }); -test('summarizes the quarter and half windows, counting zero instead of saying none yet', () => { +test('summarizes the half-year window, counting zero instead of saying none yet', () => { assert.equal( activitySummary( - { scale: 'quarter', buckets: [{ date: '2026-10-15', count: 3 }] }, + { scale: 'half', buckets: [{ date: '2026-10-15', count: 3 }] }, ['commit', 'commits'], ), - '3 commits in the last 3 months', + '3 commits in the last 6 months', ); assert.equal( activitySummary({ scale: 'half', buckets: [] }, ['commit', 'commits']), @@ -105,9 +105,8 @@ test('summarizes the quarter and half windows, counting zero instead of saying n ); }); -test('draws quarter, half and year as week grids with one column per week', () => { +test('draws half and year as week grids with one column per week', () => { for (const [scale, weeks] of [ - ['quarter', 13], ['half', 26], ['year', 53], ] as const) { From 391c2f92a5a6bf140691e3d801f611dd625038d7 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 13:43:57 +1030 Subject: [PATCH 08/10] style: fit the activity scale type on one line --- resources/js/types/activity.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/resources/js/types/activity.ts b/resources/js/types/activity.ts index 2af4c22cc..d6e7028fe 100644 --- a/resources/js/types/activity.ts +++ b/resources/js/types/activity.ts @@ -1,9 +1,4 @@ -export type ActivityScale = - | 'day' - | 'week' - | 'month' - | 'half' - | 'year'; +export type ActivityScale = 'day' | 'week' | 'month' | 'half' | 'year'; export type ActivityBucket = { date: string; From e3b1cce4feda03cde2f35fc7335d31b97d070887 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 14:30:18 +1030 Subject: [PATCH 09/10] fix: keep API clients on the year activity scale until they support the half year --- app/Enums/ActivityScale.php | 13 ++++++++++--- app/Http/Controllers/Api/UserController.php | 4 +++- app/Queries/UserActivityQuery.php | 13 +++++++++---- .../Feature/Controllers/Api/UserControllerTest.php | 7 ++++--- tests/Unit/Queries/UserActivityQueryTest.php | 10 ++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/app/Enums/ActivityScale.php b/app/Enums/ActivityScale.php index 25e8b3f56..5ea1ed373 100644 --- a/app/Enums/ActivityScale.php +++ b/app/Enums/ActivityScale.php @@ -16,11 +16,18 @@ enum ActivityScale: string case Year = 'year'; /** - * The smallest scale whose window still contains everything since the given moment. + * The scales shorter than a year that a profile's activity can fit into, smallest first. */ - public static function since(CarbonInterface $since, CarbonImmutable $now): self + public const array FITTING = [self::Day, self::Week, self::Month, self::Half]; + + /** + * The smallest of the given scales whose window still contains everything since the given moment, or else the year. + * + * @param list $scales + */ + public static function since(CarbonInterface $since, CarbonImmutable $now, array $scales = self::FITTING): self { - foreach ([self::Day, self::Week, self::Month, self::Half] as $scale) { + foreach ($scales as $scale) { if ($since->greaterThanOrEqualTo($scale->start($now))) { return $scale; } diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 1b1725481..0a054ff9b 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api; +use App\Enums\ActivityScale; use App\Http\Requests\ShowApiUserRequest; use App\Http\Resources\CommitResource; use App\Http\Resources\UserResource; @@ -39,7 +40,8 @@ public function show(ShowApiUserRequest $request, #[CurrentUser] ?User $currentU 'follows_you' => $user->isFollowing($currentUser), 'is_muting' => $currentUser->isMuting($user), 'pasteis_received' => $user->pasteis_received, - 'activity' => $activity->get($user, $currentUser), + // API clients don't know the half-year scale yet, so they keep getting the year for anyone past a month. + 'activity' => $activity->get($user, $currentUser, scales: [ActivityScale::Day, ActivityScale::Week, ActivityScale::Month]), 'streaks' => $userStreaks, 'achievements' => $achievements->get($user, $currentUser, $userStreaks), 'pinned_commit' => $pinnedCommit instanceof Commit ? CommitResource::make($pinnedCommit) : null, diff --git a/app/Queries/UserActivityQuery.php b/app/Queries/UserActivityQuery.php index 6fffab00e..bedf43e39 100644 --- a/app/Queries/UserActivityQuery.php +++ b/app/Queries/UserActivityQuery.php @@ -16,15 +16,16 @@ public function __construct(private ActivityBucketsQuery $buckets) {} /** - * Without a scale, it is the smallest one that fits all of the visible activity. + * Without a scale, it is the smallest of the given ones that fits all of the visible activity, or else the year. * + * @param list $scales * @return array{scale: ActivityScale, buckets: list} */ - public function get(User $user, ?User $viewer, ?ActivityScale $scale = null): array + public function get(User $user, ?User $viewer, ?ActivityScale $scale = null, array $scales = ActivityScale::FITTING): array { $now = CarbonImmutable::now(); - $scale ??= $this->scale($user, $viewer, $now); + $scale ??= $this->scale($user, $viewer, $now, $scales); return [ 'scale' => $scale, @@ -32,13 +33,17 @@ public function get(User $user, ?User $viewer, ?ActivityScale $scale = null): ar ]; } - private function scale(User $user, ?User $viewer, CarbonImmutable $now): ActivityScale + /** + * @param list $scales + */ + private function scale(User $user, ?User $viewer, CarbonImmutable $now, array $scales): ActivityScale { $firstCommitAt = $user->commits()->visibleTo($viewer)->min('created_at'); return ActivityScale::since( is_string($firstCommitAt) ? CarbonImmutable::parse($firstCommitAt) : $user->created_at, $now, + $scales, ); } } diff --git a/tests/Feature/Controllers/Api/UserControllerTest.php b/tests/Feature/Controllers/Api/UserControllerTest.php index e42e8dee2..f09f04a32 100644 --- a/tests/Feature/Controllers/Api/UserControllerTest.php +++ b/tests/Feature/Controllers/Api/UserControllerTest.php @@ -180,7 +180,7 @@ expect(json_decode($response->getContent(), flags: JSON_THROW_ON_ERROR)->bio_profiles)->toBeInstanceOf(stdClass::class); }); -it('returns the half scale for a profile whose first visible commit is two months old', function (): void { +it('keeps API clients on the year for a profile whose first visible commit is two months old', function (): void { $this->travelTo(now()->setDate(2026, 10, 15)->setTime(12, 0)); $keyPair = apiKeyPairFor(User::factory()->create()); @@ -190,8 +190,9 @@ signedApiRequest($keyPair, 'GET', route('api-user.show', $user)) ->assertOk() - ->assertJsonPath('activity.scale', 'half') - ->assertJsonCount(180, 'activity.buckets'); + ->assertJsonPath('activity.scale', 'year') + ->assertJsonCount(369, 'activity.buckets') + ->assertJsonPath('activity.buckets.0.date', '2025-10-12'); }); it('counts the pending commits of a signed-in user on their own profile', function (): void { diff --git a/tests/Unit/Queries/UserActivityQueryTest.php b/tests/Unit/Queries/UserActivityQueryTest.php index 84d8ee7fc..7e45e4e77 100644 --- a/tests/Unit/Queries/UserActivityQueryTest.php +++ b/tests/Unit/Queries/UserActivityQueryTest.php @@ -89,6 +89,16 @@ ]); }); +it('falls back to the year when the half year is not among the scales to choose from', function (): void { + $user = User::factory()->create(); + + Commit::factory()->for($user)->create(['created_at' => '2026-08-15 09:00:00']); + + expect(resolve(UserActivityQuery::class)->get($user, $user, scales: [ActivityScale::Day, ActivityScale::Week, ActivityScale::Month])) + ->scale->toBe(ActivityScale::Year) + ->buckets->toHaveCount(369); +}); + it('counts the commits of each day of the last 26 weeks', function (): void { $user = User::factory()->create(); From 1b33408307e61afd661c227d08db42e0f80255bf Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 16:04:27 +1030 Subject: [PATCH 10/10] docs: describe the half-year activity graph and the full-year README embed --- KNOWLEDGE_BASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 1073cf7f3..c86097248 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -531,7 +531,7 @@ Sources: [web app manifest](public/site.webmanifest), [service worker](public/sw ### Activity graphs and README embeds -Profiles display commit activity with current and longest streaks. The profile graph adapts to how long someone has been committing: the last 24 hours, 7 days, 30 days, or a year. Hovering a cell highlights that period's commits. Settings → Profile includes a live preview and copyable Markdown for embedding your /dev/null activity graph in a GitHub profile README. The graph is public at `/@{handle}/graph.svg`, uses your lane color, and supports `?theme=light`, `dark`, or `auto` (light by default). The SVG is cached for an hour, so a new commit may not appear in an external embed immediately. +Profiles display commit activity with current and longest streaks. The profile graph adapts to how long someone has been committing: the last 24 hours, 7 days, 30 days, 6 months, or a year. Hovering a cell highlights that period's commits. Settings → Profile includes a live preview and copyable Markdown for embedding your /dev/null activity graph in a GitHub profile README. The graph is public at `/@{handle}/graph.svg`, always shows the full year, uses your lane color, and supports `?theme=light`, `dark`, or `auto` (light by default). The SVG is cached for an hour, so a new commit may not appear in an external embed immediately. Sources: [graph embed settings](resources/js/components/activity-graph-embed.tsx), [graph controller](app/Http/Controllers/UserActivityGraphController.php), [graph route and cache](routes/web.php).