From be5c7e85fbc5424142f34618fa8c9d9c0ab9bdf0 Mon Sep 17 00:00:00 2001 From: Shane Smith Date: Sat, 21 Nov 2026 16:25:33 +1030 Subject: [PATCH] Draw a commit graph scale the app doesn't know as a year A profile's commit activity comes from devnull with a scale of day, week, month or year. If the scale was anything else, the app dropped the whole response, so the profile said "0 commits in the last year" over an empty strip. A scale that wasn't a string, such as an array, threw an error and broke the profile screen. A scale the app doesn't know, or one that's missing or not a string, is now drawn as a year and keeps its buckets. dev-null-sh/dev-null.sh#1658 proposes a half scale, which then shows as 26 weekly cells, but nothing here depends on it merging. --- app/Devnull/Data/Activity.php | 4 ++-- tests/Unit/Devnull/ActivityTest.php | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Devnull/Data/Activity.php b/app/Devnull/Data/Activity.php index 3a802ed2..1ca9be78 100644 --- a/app/Devnull/Data/Activity.php +++ b/app/Devnull/Data/Activity.php @@ -31,7 +31,7 @@ public function __construct(public string $scale = 'year', public array $buckets */ public static function fromArray(mixed $data): self { - if (! is_array($data) || ! array_key_exists($data['scale'] ?? null, self::Windows) || ! is_array($data['buckets'] ?? null)) { + if (! is_array($data) || ! is_array($data['buckets'] ?? null)) { return new self; } @@ -43,7 +43,7 @@ public static function fromArray(mixed $data): self } } - return new self($data['scale'], $buckets); + return new self(in_array($data['scale'] ?? null, array_keys(self::Windows), true) ? $data['scale'] : 'year', $buckets); } public function total(): int diff --git a/tests/Unit/Devnull/ActivityTest.php b/tests/Unit/Devnull/ActivityTest.php index 944ebca8..b0760a0b 100644 --- a/tests/Unit/Devnull/ActivityTest.php +++ b/tests/Unit/Devnull/ActivityTest.php @@ -81,3 +81,11 @@ function activityJson(string $scale, CarbonImmutable $from, string $step, array expect(Activity::fromArray(activityJson('week', CarbonImmutable::parse('2026-10-09'), 'days', array_fill(0, 7, 0)))->isEmpty())->toBeTrue() ->and(Activity::fromArray(activityJson('year', CarbonImmutable::parse('2025-10-12'), 'days', array_fill(0, 7, 0)))->isEmpty())->toBeFalse(); }); + +it('draws a scale it does not know as a year rather than dropping the commits', function () { + $activity = Activity::fromArray(activityJson('quarter', CarbonImmutable::parse('2026-08-23'), 'days', [1, ...array_fill(0, 89, 0), 2])); + + expect($activity->scale)->toBe('year') + ->and($activity->cells())->toHaveCount(13) + ->and($activity->total())->toBe(3); +});