Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/Queries/ContributorsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* @phpstan-type Account array{login: string, github_id: string, commits: int}
* @phpstan-type Contributor array{login: string, commits: int, username: string|null}
* @phpstan-type Contributor array{login: string, commits: int, handle: string|null}
*/
final readonly class ContributorsQuery
{
Expand All @@ -35,8 +35,8 @@ public function __construct(private GitHub $github)
}

/**
* The repository contributors, most commits first, as GitHub counts them, each with their /dev/null username, or
* null when they aren't on it. They are found by their GitHub account, since a username can change on either side.
* The repository contributors, most commits first, as GitHub counts them, each with their /dev/null handle, or
* null when they aren't on it. They are found by their GitHub account, since a handle can change on either side.
*
* @return list<Contributor>|null
*/
Expand All @@ -48,15 +48,15 @@ public function get(): ?array
return null;
}

$usernames = User::query()
$handles = User::query()
->whereIn('github_id', array_column($accounts, 'github_id'))
->get()
->mapWithKeys(fn (User $user): array => [$user->github_id => $user->username]);
->mapWithKeys(fn (User $user): array => [$user->github_id => $user->handle]);

return array_map(fn (array $account): array => [
'login' => $account['login'],
'commits' => $account['commits'],
'username' => $usernames->get($account['github_id']),
'handle' => $handles->get($account['github_id']),
], $accounts);
}

Expand Down
4 changes: 2 additions & 2 deletions resources/js/lib/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export type StoryPerson = {
};

/**
* Someone with a commit on production. The username is theirs on /dev/null, or null when they aren't on it.
* Someone with a commit on production. The handle is theirs on /dev/null, or null when they aren't on it.
*/
export type StoryContributor = {
login: string;
commits: number;
username: string | null;
handle: string | null;
};

export const storyBefore: StoryEvent[] = [
Expand Down
8 changes: 4 additions & 4 deletions resources/js/pages/about/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function Contributors({ contributors }: { contributors: StoryContributor[] }) {
<ul className="grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2">
{contributors.map((contributor) => (
<li key={contributor.login}>
{contributor.username === null ? (
{contributor.handle === null ? (
<a
href={`https://github.com/${contributor.login}`}
target="_blank"
Expand All @@ -313,12 +313,12 @@ function Contributors({ contributors }: { contributors: StoryContributor[] }) {
</a>
) : (
<UserPreview
user={{ username: contributor.username }}
user={{ handle: contributor.handle }}
className="block"
>
<Link
href={show({ username: contributor.username })}
aria-label={`@${contributor.username} on /dev/null`}
href={show({ handle: contributor.handle })}
aria-label={`@${contributor.handle} on /dev/null`}
className={className}
>
<ContributorCard contributor={contributor} />
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Controllers/AboutControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@
->assertOk()
->assertInertia(fn ($page) => $page
->has('contributors', 1)
->where('contributors.0', ['login' => 'xHeaven', 'commits' => 187, 'username' => null]));
->where('contributors.0', ['login' => 'xHeaven', 'commits' => 187, 'handle' => null]));
});

it('links each contributor who is on /dev/null to their profile, found by their GitHub account', function (): void {
fakeGitHubContributors([gitHubContributor('xHeaven', 217, id: 14284867), gitHubContributor('nunomaduro', 189)]);
User::factory()->create(['github_id' => '14284867', 'username' => 'renamed-on-devnull']);
User::factory()->create(['github_id' => '14284867', 'handle' => 'renamed-on-devnull']);

$this->get(route('about.show'))
->assertOk()
->assertInertia(fn ($page) => $page
->where('contributors.0', ['login' => 'xHeaven', 'commits' => 217, 'username' => 'renamed-on-devnull'])
->where('contributors.1', ['login' => 'nunomaduro', 'commits' => 189, 'username' => null]));
->where('contributors.0', ['login' => 'xHeaven', 'commits' => 217, 'handle' => 'renamed-on-devnull'])
->where('contributors.1', ['login' => 'nunomaduro', 'commits' => 189, 'handle' => null]));
});

it('leaves the contributors out while GitHub is unreachable', function (): void {
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Queries/ContributorsQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
fakeGitHubContributors([gitHubContributor('xHeaven', 187), gitHubContributor('jubianchi', 1)]);

expect(resolve(ContributorsQuery::class)->get())->toBe([
['login' => 'xHeaven', 'commits' => 187, 'username' => null],
['login' => 'jubianchi', 'commits' => 1, 'username' => null],
['login' => 'xHeaven', 'commits' => 187, 'handle' => null],
['login' => 'jubianchi', 'commits' => 1, 'handle' => null],
]);
});

Expand All @@ -24,7 +24,7 @@
gitHubContributor('dependabot', 4, 'Bot'),
]);

expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'xHeaven', 'commits' => 187, 'username' => null]]);
expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'xHeaven', 'commits' => 187, 'handle' => null]]);
});

it('reads every page GitHub has, up to a thousand people', function (int $contributors, int $expected, int $requests): void {
Expand Down Expand Up @@ -57,7 +57,7 @@
gitHubContributor('xHeaven', 187),
]);

expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'xHeaven', 'commits' => 187, 'username' => null]]);
expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'xHeaven', 'commits' => 187, 'handle' => null]]);
});

it('asks GitHub again an hour later, not before', function (): void {
Expand Down Expand Up @@ -128,6 +128,6 @@

$this->travel(61)->seconds();

expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'recovered', 'commits' => 12, 'username' => null]]);
expect(resolve(ContributorsQuery::class)->get())->toBe([['login' => 'recovered', 'commits' => 12, 'handle' => null]]);
Http::assertSentCount(3);
});