diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index d29acd2c7..df7b736a8 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -161,7 +161,7 @@ Sources: [go-live button](resources/js/components/profile-live-button.tsx), [liv ### Achievement badges and XP -Profiles have **16 achievement badges**. Earned badges appear in a single row, with **+N more** when more have been earned than fit. Hover over the row on desktop or tap it on mobile to toggle a popover with every badge, including locked badges and their progress. Profiles with no earned badges show **View achievements** instead. Select a badge in the popover, or the profile's rank or unlocked count, to open the detailed achievements dialog. +Profiles have **17 achievement badges**. Earned badges appear in a single row, with **+N more** when more have been earned than fit. Hover over the row on desktop or tap it on mobile to toggle a popover with every badge, including locked badges and their progress. Profiles with no earned badges show **View achievements** instead. Select a badge in the popover, or the profile's rank or unlocked count, to open the detailed achievements dialog. | Badge | When it unlocks | | --- | --- | @@ -181,10 +181,11 @@ Profiles have **16 achievement badges**. Earned badges appear in a single row, w | **shell shocked** | “Survived the php2shell downtime of Oct '26. Earns 100 XP.” — accounts created before **October 21, 2026 at 14:00 UTC** receive this badge and **100 bonus XP**. Accounts created at or after that moment do not qualify. | | **super-saiyan** | Have **9,000 followers or more** on /dev/null. “Y—your follower count. It... it’s over 9000!!!1!” | | **whoopsie** | “Nuked production at least once.” — unlocked for **@paulinevos**, **@nunomaduro**, **@brendt**, and **@mnapoli**, regardless of handle capitalization. No bonus XP. | +| **git blame** | Have **at least one commit** in the [/dev/null repository](https://github.com/dev-null-sh/dev-null.sh) on GitHub, matched by your GitHub account rather than your handle. “Landed a commit in the /dev/null repo itself. git blame now points at you.” It uses the same contributor list as the About page, cached for an hour, so it can take that hour (and however long GitHub takes to update its counts) to appear after a merge. An earned badge stays while that list is cached; it only locks when the list runs out while GitHub can't be reached, until GitHub answers again. | Commit counts include replies and quotes. Commit-based badges and XP use non-deleted commits visible to the person viewing the profile, so an author may see progress from pending or rejected commits that other viewers cannot see. Streak badges use the **longest** streak, not the current streak: missing a day does not by itself remove them. Days follow the activity graph's app-timezone grouping, not the user's selected display timezone. -Badges are calculated from current account data, not permanently recorded awards. Removing qualifying activity can reduce progress or lock a badge again; for example, unstarring a commit can remove **stargazer**. **Shell shocked** depends only on when the account was created, so deleting activity does not remove it. When a commit posted on the web unlocks a badge, a toast names it and confetti drops; clicking an unlocked badge drops confetti again. Unlocking a badge does not normally give bonus XP; **shell shocked** contributes **100 XP** once. XP otherwise comes from **10 per commit**, **15 per day in the longest streak**, **5 per star received**, **5 per reply to another developer**, and **2 per star given to another developer**. The **luddite** penalty applies once while the badge is unlocked, not once per unfollow, and total XP cannot fall below zero. A qualifying reply contributes both commit XP and reply XP; pastéis do not add XP. +Badges are calculated from current account data, not permanently recorded awards. Removing qualifying activity can reduce progress or lock a badge again; for example, unstarring a commit can remove **stargazer**. **Shell shocked** depends only on when the account was created, so deleting activity does not remove it. **Git blame** depends only on GitHub's contributor list, not on anything posted on /dev/null. When a commit posted on the web unlocks a badge, a toast names it and confetti drops; clicking an unlocked badge drops confetti again. Unlocking a badge does not normally give bonus XP; **shell shocked** contributes **100 XP** once. XP otherwise comes from **10 per commit**, **15 per day in the longest streak**, **5 per star received**, **5 per reply to another developer**, and **2 per star given to another developer**. The **luddite** penalty applies once while the badge is unlocked, not once per unfollow, and total XP cannot fall below zero. A qualifying reply contributes both commit XP and reply XP; pastéis do not add XP. XP also determines your Unix rank: **user** at 0 XP, **daemon** at 50, **operator** at 150, **maintainer** at 400, **wheel** at 1,000, and **root** at 2,500. The achievements dialog's **Ranks** tab shows the levels and progress. Level-up notifications use your public progress, so pending or rejected commits do not trigger them. Each level above the starting rank can notify you only once, even if you lose and regain the XP; jumping ahead does not send a notification for every skipped level. diff --git a/app/Enums/Achievement.php b/app/Enums/Achievement.php index e089fadc7..8bff03dbe 100644 --- a/app/Enums/Achievement.php +++ b/app/Enums/Achievement.php @@ -22,6 +22,7 @@ enum Achievement: string case ShellShocked = 'shell_shocked'; case SuperSaiyan = 'super_saiyan'; case Whoopsie = 'whoopsie'; + case GitBlame = 'git_blame'; public function label(): string { @@ -42,6 +43,7 @@ public function label(): string self::ShellShocked => 'shell shocked', self::SuperSaiyan => 'super-saiyan', self::Whoopsie => 'whoopsie', + self::GitBlame => 'git blame', }; } @@ -64,6 +66,7 @@ public function description(): string self::ShellShocked => "Survived the php2shell downtime of Oct '26. Earns 100 XP.", self::SuperSaiyan => 'Y—your follower count. It... it’s over 9000!!!1!', self::Whoopsie => 'Nuked production at least once.', + self::GitBlame => 'Landed a commit in the /dev/null repo itself. git blame now points at you.', }; } @@ -86,6 +89,7 @@ public function icon(): string self::ShellShocked => 'bomb', self::SuperSaiyan => 'dragon-ball', self::Whoopsie => 'mushroom-cloud', + self::GitBlame => 'git-commit-horizontal', }; } @@ -108,6 +112,7 @@ public function target(): int self::ShellShocked => 1, self::SuperSaiyan => 9000, self::Whoopsie => 1, + self::GitBlame => 1, }; } } diff --git a/app/Queries/ContributorsQuery.php b/app/Queries/ContributorsQuery.php index 8d0407945..7a37f9bef 100644 --- a/app/Queries/ContributorsQuery.php +++ b/app/Queries/ContributorsQuery.php @@ -60,6 +60,15 @@ public function get(): ?array ], $accounts); } + /** + * How many commits the user's GitHub account has in the repository, as GitHub counts them, from the same list the + * About page shows. Zero when it has none, or GitHub didn't answer. + */ + public function commits(User $user): int + { + return array_column($this->accounts() ?? [], 'commits', 'github_id')[$user->github_id] ?? 0; + } + /** * The GitHub accounts behind the contributors. A failed read is kept for a minute, so an outage doesn't send every * visitor to GitHub. diff --git a/app/Queries/UserAchievementsQuery.php b/app/Queries/UserAchievementsQuery.php index 6c0174ef9..300df5935 100644 --- a/app/Queries/UserAchievementsQuery.php +++ b/app/Queries/UserAchievementsQuery.php @@ -35,7 +35,7 @@ */ final readonly class UserAchievementsQuery { - public function __construct(private UserStreakQuery $streaks) + public function __construct(private UserStreakQuery $streaks, private ContributorsQuery $contributors) { // } @@ -90,6 +90,7 @@ public function get(User $user, ?User $viewer, ?array $streaks = null): array $hasUnfollowedTom = $user->followers()->where('github_id', CreateTomFriendship::GITHUB_ID)->exists() && ! $user->following()->where('github_id', CreateTomFriendship::GITHUB_ID)->exists(); $isShellShocked = $user->created_at->lt('2026-10-21 14:00:00 UTC'); + $repositoryCommits = $this->contributors->commits($user); // XP breakdown: 10 per commit, 15 per streak day, 5 per star received, 5 per reply, 2 per star given $commitsXp = $commitsCount * 10; @@ -192,6 +193,10 @@ public function get(User $user, ?User $viewer, ?array $streaks = null): array 'progress' => in_array(mb_strtolower($user->handle), ['paulinevos', 'nunomaduro', 'brendt', 'mnapoli'], true) ? 1 : 0, 'target' => Achievement::Whoopsie->target(), ], + Achievement::GitBlame->value => [ + 'progress' => min($repositoryCommits, Achievement::GitBlame->target()), + 'target' => Achievement::GitBlame->target(), + ], ]; $badges = array_map(function (Achievement $achievement) use ($metrics): array { diff --git a/resources/js/components/achievements-dialog.tsx b/resources/js/components/achievements-dialog.tsx index 7a67e7f22..1ec0c5270 100644 --- a/resources/js/components/achievements-dialog.tsx +++ b/resources/js/components/achievements-dialog.tsx @@ -4,6 +4,7 @@ import { Box, FileCode, Flame, + GitCommitHorizontal, GitMerge, Key, Server, @@ -48,6 +49,7 @@ const iconMap: Record> = { bomb: Bomb, 'dragon-ball': DragonBallIcon, 'mushroom-cloud': MushroomCloudIcon, + 'git-commit-horizontal': GitCommitHorizontal, }; export function AchievementsDialog({ diff --git a/resources/js/components/achievements-shelf.tsx b/resources/js/components/achievements-shelf.tsx index 62839a871..be9ef226c 100644 --- a/resources/js/components/achievements-shelf.tsx +++ b/resources/js/components/achievements-shelf.tsx @@ -6,6 +6,7 @@ import { ChevronRight, FileCode, Flame, + GitCommitHorizontal, GitMerge, Key, Server, @@ -53,6 +54,7 @@ const iconMap: Record> = { bomb: Bomb, 'dragon-ball': DragonBallIcon, 'mushroom-cloud': MushroomCloudIcon, + 'git-commit-horizontal': GitCommitHorizontal, }; export function AchievementsShelf({ diff --git a/tests/Feature/Controllers/SessionControllerTest.php b/tests/Feature/Controllers/SessionControllerTest.php index 9fd947934..fb5d1ed15 100644 --- a/tests/Feature/Controllers/SessionControllerTest.php +++ b/tests/Feature/Controllers/SessionControllerTest.php @@ -227,6 +227,7 @@ it('redirects to the intended url after login', function (): void { $github = $this->mock(GitHubProvider::class); + $github->shouldReceive('contributors')->andReturn([]); $github->shouldReceive('hasSponsorsListing')->andReturnFalse(); $user = User::factory()->create(); diff --git a/tests/Feature/Controllers/UserControllerTest.php b/tests/Feature/Controllers/UserControllerTest.php index 52c8c4ba2..20224876b 100644 --- a/tests/Feature/Controllers/UserControllerTest.php +++ b/tests/Feature/Controllers/UserControllerTest.php @@ -729,6 +729,7 @@ Commit::factory()->for($user)->create(); $github = $this->mock(GitHubProvider::class); + $github->shouldReceive('contributors')->andReturn([]); $github->shouldReceive('login')->with($user->github_id)->andReturn('octocat'); $github->shouldReceive('readme')->with('octocat')->andReturn('

Hi there

'); @@ -743,6 +744,7 @@ $user = User::factory()->create(['handle' => 'octocat']); $github = $this->mock(GitHubProvider::class); + $github->shouldReceive('contributors')->andReturn([]); $github->shouldReceive('login')->andThrow(new ConnectionException('timed out')); $this->get(route('user.show', ['user' => $user, 'tab' => 'readme']))->assertOk()->assertInertia(fn ($page) => $page @@ -751,6 +753,7 @@ it('does not ask github for the readme on the other tabs', function (string $tab): void { $github = $this->mock(GitHubProvider::class); + $github->shouldReceive('contributors')->andReturn([]); $github->shouldNotReceive('login', 'readme'); $user = User::factory()->create(['handle' => 'octocat']); diff --git a/tests/Unit/Queries/ContributorsQueryTest.php b/tests/Unit/Queries/ContributorsQueryTest.php index 4fe14a9a8..b1ab769c4 100644 --- a/tests/Unit/Queries/ContributorsQueryTest.php +++ b/tests/Unit/Queries/ContributorsQueryTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); use App\Contracts\Services\GitHubProvider; +use App\Models\User; use App\Queries\ContributorsQuery; use GuzzleHttp\Psr7\Response as Psr7Response; use Illuminate\Http\Client\ConnectionException; @@ -149,3 +150,20 @@ expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'recovered', 'commits' => 12, 'handle' => null]]); $github->shouldHaveReceived('contributors')->times(3); }); + +it('counts the commits of a user by their GitHub account, and none for anyone else', function (): void { + $github = $this->mock(GitHubProvider::class); + $github->shouldReceive('contributors')->andReturn([gitHubContributor('xHeaven', 187), gitHubContributor('jubianchi', 1)]); + $query = resolve(ContributorsQuery::class); + + expect($query->commits(User::factory()->make(['github_id' => (string) crc32('jubianchi')])))->toBe(1) + ->and($query->commits(User::factory()->make(['handle' => 'xHeaven'])))->toBe(0); + + $github->shouldHaveReceived('contributors')->once(); +}); + +it('counts no commits while GitHub does not answer', function (): void { + $this->mock(GitHubProvider::class)->shouldReceive('contributors')->andThrow(new RequestException(new Response(new Psr7Response(500)))); + + expect(resolve(ContributorsQuery::class)->commits(User::factory()->make(['github_id' => (string) crc32('xHeaven')])))->toBe(0); +}); diff --git a/tests/Unit/Queries/UserAchievementsQueryTest.php b/tests/Unit/Queries/UserAchievementsQueryTest.php index 2db261824..e83a505b7 100644 --- a/tests/Unit/Queries/UserAchievementsQueryTest.php +++ b/tests/Unit/Queries/UserAchievementsQueryTest.php @@ -3,6 +3,7 @@ declare(strict_types=1); use App\Actions\CreateTomFriendship; +use App\Contracts\Services\GitHubProvider; use App\Enums\Achievement; use App\Enums\CommitStatus; use App\Enums\UnixRank; @@ -10,6 +11,9 @@ use App\Models\SshKey; use App\Models\User; use App\Queries\UserAchievementsQuery; +use GuzzleHttp\Psr7\Response as Psr7Response; +use Illuminate\Http\Client\RequestException; +use Illuminate\Http\Client\Response; beforeEach(function (): void { $this->travelTo(now()->setDate(2026, 10, 22)->setTime(12, 0)); @@ -28,7 +32,7 @@ ->and($result['ranks'])->toHaveCount(6) ->and($result['xp_breakdown']['commits']['xp'])->toBe(0) ->and($result['xp_breakdown']['shell_shocked']['xp'])->toBe(0) - ->and($result['badges'])->toHaveCount(16); + ->and($result['badges'])->toHaveCount(17); foreach ($result['badges'] as $badge) { expect($badge['unlocked'])->toBeFalse() @@ -384,3 +388,33 @@ 'exactly at cutoff' => ['2026-10-21 14:00:00', false, 0, 1], 'just after cutoff' => ['2026-10-21 14:00:01', false, 0, 1], ]); + +it('unlocks git blame with a commit in the /dev/null repository, matching the GitHub account', function (): void { + $contributor = User::factory()->create(['github_id' => (string) crc32('xHeaven'), 'handle' => 'renamed']); + $other = User::factory()->create(['handle' => 'xHeaven']); + $this->mock(GitHubProvider::class)->shouldReceive('contributors')->andReturn([gitHubContributor('xHeaven', 187)]); + + $query = resolve(UserAchievementsQuery::class); + $result = $query->get($contributor, null); + + expect(collect($result['badges'])->firstWhere('id', 'git_blame'))->toBe([ + 'id' => 'git_blame', + 'name' => 'git blame', + 'description' => 'Landed a commit in the /dev/null repo itself. git blame now points at you.', + 'icon' => 'git-commit-horizontal', + 'unlocked' => true, + 'progress' => 1, + 'target' => 1, + ])->and($result['xp'])->toBe(0) + ->and(collect($query->get($other, null)['badges'])->firstWhere('id', 'git_blame')['unlocked'])->toBeFalse(); +}); + +it('keeps git blame locked while GitHub does not answer', function (): void { + $user = User::factory()->create(['github_id' => (string) crc32('xHeaven')]); + $this->mock(GitHubProvider::class)->shouldReceive('contributors')->andThrow(new RequestException(new Response(new Psr7Response(500)))); + + $badge = collect(resolve(UserAchievementsQuery::class)->get($user, null)['badges'])->firstWhere('id', 'git_blame'); + + expect($badge['unlocked'])->toBeFalse() + ->and($badge['progress'])->toBe(0); +});