Skip to content
Closed
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
6 changes: 4 additions & 2 deletions KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ A developer who isn't here yet gets a page with their GitHub avatar, name, handl

Its page shows how many members are waiting to follow them: the members who followed them on GitHub when they were looked up, and the ones who clicked **Follow** on their page, which then reads **Waiting** and can be clicked again to stop waiting. Members also see the people they follow among them. When the developer signs up, everyone waiting follows them, and their notifications show those follows like any others. Who you wait to follow is in your data export, and goes when you delete your account. If you delete your account, your page doesn't come back as one of these, until you sign in again.

Sources: [looking handles up](app/Http/Controllers/ProfileLookupController.php), [lookup page](resources/js/pages/profile/lookup.tsx), [developer page](resources/js/pages/profile/unclaimed.tsx), [GitHub lookups](app/Actions/CreateGitHubProfile.php).
Like an organization's page, it has a **Commits** tab and a **Mentions** tab. **Commits** stays empty until they sign up. **Mentions** lists the commits and replies that mention them, newest first, a reply with the commit it answers, with the usual visibility: guests see approved commits only, and commits across a block or by people you muted are left out. A commit is linked to them as it is posted when they already have a page, and the commits written before they had one are found shortly after their page is first looked up. A commit stays listed after they rename on GitHub, since it is linked to them rather than to the handle; if someone else takes their old handle, the page and its mentions go, and the page of whoever has the handle now only lists the commits posted after it. Nobody is notified of these mentions.

Sources: [looking handles up](app/Http/Controllers/ProfileLookupController.php), [lookup page](resources/js/pages/profile/lookup.tsx), [developer page](resources/js/pages/profile/unclaimed.tsx), [GitHub lookups](app/Actions/CreateGitHubProfile.php), [mentions](app/Queries/UnclaimedProfileMentionsQuery.php), [earlier mentions](app/Actions/CreateUnclaimedProfileTopics.php).

### Going live

Expand Down Expand Up @@ -265,7 +267,7 @@ The smiley button in the commit, reply and quote composers opens the same search

In commits, replies, and remotes, start a line with `>` to render a quote block. Consecutive quoted lines stay together; an unquoted line ends the block. Quotes keep inline code, links, mentions, and emoji formatting. A `>` inside code or in the middle of a line stays literal.

Typing **@** in a composer opens developer suggestions. Use ↑/↓ to move, Enter or Tab to select, and Esc to dismiss. A bare @ suggests people you follow; typing more searches names and usernames. In replies, matching suggestions put the direct recipient first, then the root commit author, then other visible participants in that thread, followed by ordinary suggestions. Quotes prioritize only the quoted commit author. These priorities also apply to a bare @; typing a term still filters everyone, and yourself, muted developers, and blocked developers are excluded. In an org's messages, suggestions search the loaded member list instantly and update as membership refreshes. Suggestions are limited to the org's members, but you can still type anyone's handle yourself. Mentions link to profiles and can notify the mentioned developer after approval. Mentioning a GitHub organization, like `@laravel`, links to its [organization page](#organization-pages) and notifies its members: a known organization links right away, one mentioned for the first time once the commit is approved and GitHub confirms it is an organization. Typing @ followed by a few letters also suggests organizations that already have a page, after developers. Organization mentions only link in commits and replies, not in remotes. In commits and replies, but not in remotes, a mention of anyone else links to `/@handle` too, where signed-in members can [look them up on GitHub](#developers-not-on-devnull-yet); it never notifies anyone who isn't on /dev/null. Email addresses and scoped packages such as `@inertiajs/react` are not treated as mentions.
Typing **@** in a composer opens developer suggestions. Use ↑/↓ to move, Enter or Tab to select, and Esc to dismiss. A bare @ suggests people you follow; typing more searches names and usernames. In replies, matching suggestions put the direct recipient first, then the root commit author, then other visible participants in that thread, followed by ordinary suggestions. Quotes prioritize only the quoted commit author. These priorities also apply to a bare @; typing a term still filters everyone, and yourself, muted developers, and blocked developers are excluded. In an org's messages, suggestions search the loaded member list instantly and update as membership refreshes. Suggestions are limited to the org's members, but you can still type anyone's handle yourself. Mentions link to profiles and can notify the mentioned developer after approval. Mentioning a GitHub organization, like `@laravel`, links to its [organization page](#organization-pages) and notifies its members: a known organization links right away, one mentioned for the first time once the commit is approved and GitHub confirms it is an organization. Typing @ followed by a few letters also suggests organizations that already have a page, after developers. Organization mentions only link in commits and replies, not in remotes. In commits and replies, but not in remotes, a mention of anyone else links to `/@handle` too, where signed-in members can [look them up on GitHub](#developers-not-on-devnull-yet), and once they have a page it shows on their **Mentions** tab; it never notifies anyone who isn't on /dev/null. Email addresses and scoped packages such as `@inertiajs/react` are not treated as mentions.

Typing **#123** in a composer looks up that exact issue or pull request in the /dev/null repository, `dev-null-sh/dev-null.sh`. The matching title appears beneath the number; click it or use Enter or Tab to insert its GitHub URL, just like choosing an emoji suggestion. A space or punctuation leaves the number as typed and dismisses the suggestion. Missing numbers and failed lookups leave the text unchanged. Code, URL fragments, and references qualified with another repository are not expanded.

Expand Down
4 changes: 3 additions & 1 deletion app/Actions/CreateCommit.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use App\Models\User;
use App\Queries\AdminsQuery;
use App\Queries\MentionedOrganizationsQuery;
use App\Queries\MentionedUnclaimedProfilesQuery;
use App\Queries\MentionedUsersQuery;
use App\Queries\TomQuery;
use App\Services\EmojiShortcodes;
Expand All @@ -48,6 +49,7 @@ public function __construct(
private Urls $urls,
private MentionedUsersQuery $mentionedUsers,
private MentionedOrganizationsQuery $mentionedOrganizations,
private MentionedUnclaimedProfilesQuery $mentionedUnclaimedProfiles,
private CreateCommitTopics $createCommitTopics,
private TomQuery $tomQuery,
private AdminsQuery $admins,
Expand Down Expand Up @@ -90,7 +92,7 @@ public function handle(User $user, string $body, ?Commit $parent = null, ?Commit
'created_at' => $createdAt,
]);

$this->createCommitTopics->handle($commit, $this->mentionedOrganizations->get($body, $mentions));
$this->createCommitTopics->handle($commit, $this->mentionedOrganizations->get($body, $mentions), $this->mentionedUnclaimedProfiles->get($body, $mentions));
$this->createCommitImages->handle($commit, $images, $imageDescriptions);

if ($poll instanceof NewPoll) {
Expand Down
19 changes: 13 additions & 6 deletions app/Actions/CreateCommitTopics.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@
final readonly class CreateCommitTopics
{
/**
* Links the commit to the organizations it mentions, by the lowercase handle written in its body. A reference the
* commit is already linked by keeps what it was linked to. A handle of digits only is still a string reference.
* Links the commit to the organizations it mentions, and to the developers it mentions who aren't on /dev/null
* yet, by the lowercase handle written in its body. A reference the commit is already linked by keeps what it was
* linked to. A handle of digits only is still a string reference.
*
* @param array<string, string> $organizations
* @param array<string, string> $developers
*/
public function handle(Commit $commit, array $organizations): void
public function handle(Commit $commit, array $organizations, array $developers = []): void
{
DB::table('commit_topics')->insertOrIgnore(array_map(fn (int|string $reference, string $id): array => [
$topics = fn (array $topics, TopicType $type): array => array_map(fn (int|string $reference, string $id): array => [
'commit_id' => $commit->id,
'reference' => (string) $reference,
'topic_type' => TopicType::Organization->value,
'topic_type' => $type->value,
'topic_id' => $id,
], array_keys($organizations), $organizations));
], array_keys($topics), $topics);

DB::table('commit_topics')->insertOrIgnore([
...$topics($organizations, TopicType::Organization),
...$topics($developers, TopicType::Developer),
]);
}
}
28 changes: 26 additions & 2 deletions app/Actions/CreateGitHubProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use App\Contracts\Services\GitHubProvider;
use App\Dto\GitHubProfile;
use App\Enums\ProfileType;
use App\Jobs\LinkUnclaimedProfileTopics;
use App\Models\Profile;
use App\Models\User;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

final readonly class CreateGitHubProfile
{
Expand All @@ -25,7 +27,8 @@ public function __construct(

/**
* Gives the handle a page from its GitHub account: an organization's, or an unclaimed developer's, which keeps only
* what the page shows, with the members following them on GitHub waiting to follow them here. A user here who
* what the page shows, with the members following them on GitHub waiting to follow them here, and the commits that
* mentioned them linked to it, unless the handle was another page's here. A user here who
* renamed on GitHub moves to the handle. A handle that is no GitHub account, or the account of someone who deleted
* theirs here, is remembered for a day, so the page says so without asking GitHub again.
*/
Expand Down Expand Up @@ -56,6 +59,10 @@ public function handle(string $handle): void
: $this->github->followerIds($profile->handle, CreateUserGitHubFollows::MaxPages);

DB::transaction(function () use ($profile, $githubId, $followerIds): void {
// Read before the stale handles move, as the earlier mentions of a handle that was someone else's page
// here were meant for them...
$wasAnothersHandle = Profile::query()->where('handle', $profile->handle)->where('github_id', '!=', $githubId)->exists();

$this->updateStaleHandles->handle($profile->handle, $githubId);

$existing = Profile::query()->where('type', ProfileType::User)->firstWhere('github_id', $githubId);
Expand All @@ -67,19 +74,36 @@ public function handle(string $handle): void
return;
}

Profile::query()->updateOrCreate(['github_id' => $githubId, 'type' => ProfileType::User], [
$unclaimed = Profile::query()->updateOrCreate(['github_id' => $githubId, 'type' => ProfileType::User], [
'handle' => $profile->handle,
'name' => $profile->name,
'avatar_url' => $profile->avatarUrl,
'bio' => $profile->bio,
'github_synced_at' => now(),
]);

// The commits that mentioned them before are linked to their page, at its new handle too, unless they
// meant whoever had the handle here before...
if (! $wasAnothersHandle && ($unclaimed->wasRecentlyCreated || $this->movedHandle($unclaimed))) {
dispatch(new LinkUnclaimedProfileTopics($unclaimed))->afterCommit();
}

// Those still waiting from before the profile last went are kept...
DB::table('pending_follows')->insertOrIgnoreUsing(
['user_id', 'github_id', 'created_at'],
User::query()->whereIn('github_id', $followerIds)->select('id')->selectRaw('?, ?', [$githubId, now()]),
);
});
}

/**
* A handle is one whatever its case, so only a new one moves the page: a change of case leaves its mentions as
* they are.
*/
private function movedHandle(Profile $profile): bool
{
$previous = $profile->getPrevious()['handle'] ?? null;

return is_string($previous) && Str::lower($previous) !== Str::lower($profile->handle);
}
}
106 changes: 106 additions & 0 deletions app/Actions/CreateUnclaimedProfileTopics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

namespace App\Actions;

use App\Enums\ProfileType;
use App\Models\Commit;
use App\Models\Profile;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

final readonly class CreateUnclaimedProfileTopics
{
public function __construct(private CreateCommitTopics $createCommitTopics)
{
//
}

/**
* Links the commits that mentioned the developers before they had a page to them, by the handle each page has now,
* as commits posted since are linked as they are posted. Only developers still not on /dev/null are linked. Safe to
* call more than once.
*/
public function handle(Profile ...$profiles): void
{
$developers = $this->developers($profiles);

if ($developers === []) {
return;
}

$this->link(Commit::withTrashed()
->where(function (Builder $query) use ($developers): void {
foreach (array_keys($developers) as $handle) {
$query->orWhere('body', 'ilike', '%@'.addcslashes((string) $handle, '\\%_').'%');
Comment thread
kachelle marked this conversation as resolved.
Resolved
}
})
->select(['id', 'body', 'mentions'])
->lazyById(500), $developers);
}

/**
* The given developers, or every one, who have a page but aren't on /dev/null yet, by lowercase handle.
*
* @param iterable<array-key, Profile>|null $profiles
* @return array<string, string>
*/
public function developers(?iterable $profiles = null): array
{
$developers = [];

foreach ($profiles ?? Profile::query()->where('type', ProfileType::User)->whereDoesntHave('user')->lazyById(500) as $profile) {
// The query already left out the claimed ones...
if ($profiles === null || $profile->isUnclaimed()) {
$developers[Str::lower($profile->handle)] = $profile->id;
}
}

return $developers;
}

/**
* Links each of the commits to the developers it mentions among the given ones. A mention of a handle that was a
* user's when it was written stays that user's. Each commit is linked as it is, locked, so a commit erased in the
* meantime gets none. Returns how many commits were linked.
*
* @param iterable<int, Commit> $commits
* @param array<string, string> $developers
*/
public function link(iterable $commits, array $developers): int
{
$linked = 0;

foreach ($commits as $commit) {
if ($this->mentioned($commit, $developers) === []) {
continue;
}

$linked += DB::transaction(function () use ($commit, $developers): int {
$commit = Commit::withTrashed()->lockForUpdate()->find($commit->id);
$mentioned = $commit instanceof Commit ? $this->mentioned($commit, $developers) : [];

if (! $commit instanceof Commit || $mentioned === []) {
return 0;
}

$this->createCommitTopics->handle($commit, [], $mentioned);

return 1;
});
}

return $linked;
}

/**
* @param array<string, string> $developers
* @return array<string, string>
*/
private function mentioned(Commit $commit, array $developers): array
{
return array_intersect_key($developers, array_flip($commit->mentionedNonUsers()));
}
}
3 changes: 3 additions & 0 deletions app/Actions/DeleteUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Enums\CommitUpdate;
use App\Enums\ConversationKind;
use App\Enums\TopicType;
use App\Enums\UserUpdate;
use App\Events\CommitsUpdated;
use App\Events\UsersUpdated;
Expand Down Expand Up @@ -76,6 +77,8 @@ public function handle(User $user): void
resolve(DeleteStoredFiles::class)->retain($imagePaths);

DB::table('commit_topics')->whereIn('commit_id', $this->touchedCommits($user)->select('id'))->delete();
// What mentioned them before they signed up was linked to their profile, which goes...
DB::table('commit_topics')->where('topic_type', TopicType::Developer)->where('topic_id', $user->id)->delete();
Headline::query()->whereIn('id', DB::table('commit_headline')->select('headline_id')
->whereIn('commit_id', $this->touchedCommits($user)->select('id')))
->update(['summary' => null, 'summary_created_at' => null]);
Expand Down
14 changes: 10 additions & 4 deletions app/Actions/UpdateCommitTopics.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Models\Commit;
use App\Queries\MentionedOrganizationsQuery;
use App\Queries\MentionedUnclaimedProfilesQuery;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\DB;

Expand All @@ -14,15 +15,16 @@
public function __construct(
private UpdateMentionedOrganizations $updateMentionedOrganizations,
private MentionedOrganizationsQuery $mentionedOrganizations,
private MentionedUnclaimedProfilesQuery $mentionedUnclaimedProfiles,
private CreateCommitTopics $createCommitTopics,
) {
//
}

/**
* Looks the organizations the commit mentions up, then links the commit to them. The links come from the commit as
* it is after the lookups, locked, so a commit erased in the meantime gets none. Returns when to try again if the
* rate limit cut the lookups short.
* Looks the organizations the commit mentions up, then links the commit to them, and to the developers it mentions
* who have a page but aren't on /dev/null yet. The links come from the commit as it is after the lookups, locked,
* so a commit erased in the meantime gets none. Returns when to try again if the rate limit cut the lookups short.
*/
public function handle(Commit $commit): ?CarbonImmutable
{
Expand All @@ -38,7 +40,11 @@ public function handle(Commit $commit): ?CarbonImmutable
$commit = Commit::withTrashed()->lockForUpdate()->find($commit->id);

if ($commit instanceof Commit) {
$this->createCommitTopics->handle($commit, $this->mentionedOrganizations->get($commit->body, $commit->mentions ?? []));
$this->createCommitTopics->handle(
$commit,
$this->mentionedOrganizations->get($commit->body, $commit->mentions ?? []),
$this->mentionedUnclaimedProfiles->get($commit->body, $commit->mentions ?? []),
);
}
});

Expand Down
Loading