Skip to content
Open
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
5 changes: 4 additions & 1 deletion KNOWLEDGE_BASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ Its page shows how many members are waiting to follow them: the members who foll

Its page also says how many commits mention them, like **12 commits mention them**, counting approved commits that mention `@handle` outside code, refreshed within the hour. The commits themselves aren't shown or linked, since they can't answer what's said about them.

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), [mention count](app/Queries/UnclaimedProfileMentionCountQuery.php).
Apps look handles up and wait to follow through the [signed API](#signed-api-and-devices), with the same budget of 30 lookups an hour. Anyone can read a developer who isn't here yet at `/api/v1/unclaimed-profiles/{handle}`, with how many members wait to follow them and how many commits mention them. A signed request also says whether you wait, and up to three people you follow who do. Once a lookup finds the handle, its status answers not found, and the app opens it as a user, an organization or a developer not here yet.

Sources: [looking handles up](app/Http/Controllers/ProfileLookupController.php), [API lookups](app/Http/Controllers/Api/ProfileLookupController.php), [lookup page](resources/js/pages/profile/lookup.tsx), [developer page](resources/js/pages/profile/unclaimed.tsx), [GitHub lookups](app/Actions/CreateGitHubProfile.php), [mention count](app/Queries/UnclaimedProfileMentionCountQuery.php).

### Going live

Expand Down Expand Up @@ -593,6 +595,7 @@ A signed request sees what the web shows you, such as your own pending commits a
- preview commit drafts without publishing them;
- request a feature or report a bug as `/feature` and `/bug` do, with the same limit of 10 opened issues a day;
- follow or unfollow people and organizations, mute or unmute, and block or unblock, and list who you muted and blocked;
- look up a handle on GitHub and check where the lookup stands, and wait or stop waiting to follow a developer who isn't on /dev/null yet;
- read who to follow, also as it is suggested beside a profile or a commit, and mark a suggestion not interested;
- read the hot topics, and each one's commits from the past week with its recap;
- list guilds as the Guilds page does, 24 a page, searched by name, handle or description, with whether you joined or muted each one and whether it is paused, while guilds are available to you;
Expand Down
34 changes: 34 additions & 0 deletions app/Http/Controllers/Api/PendingFollowController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Actions\CreatePendingFollow;
use App\Actions\DeletePendingFollow;
use App\Http\Requests\CreateApiPendingFollowRequest;
use App\Http\Requests\DeleteApiPendingFollowRequest;
use App\Models\Profile;
use App\Models\User;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\Response;

/**
* Following a developer who isn't on /dev/null yet waits for them to sign up.
*/
final readonly class PendingFollowController
{
public function store(CreateApiPendingFollowRequest $request, #[CurrentUser] User $user, Profile $profile, CreatePendingFollow $action): Response
{
$action->handle($user, $profile);

return response()->noContent();
}

public function destroy(DeleteApiPendingFollowRequest $request, #[CurrentUser] User $user, Profile $profile, DeletePendingFollow $action): Response
{
$action->handle($user, $profile);

return response()->noContent();
}
}
33 changes: 33 additions & 0 deletions app/Http/Controllers/Api/ProfileLookupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Actions\CreateProfileLookup;
use App\Http\Requests\CreateApiProfileLookupRequest;
use App\Http\Requests\ShowApiProfileLookupRequest;
use App\Queries\ProfileLookupQuery;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;

/**
* A handle nobody on /dev/null has may still be someone's on GitHub. The app looks it up, then polls where the lookup
* stands until GitHub answers, as the web's lookup page does.
*/
final readonly class ProfileLookupController
{
public function show(ShowApiProfileLookupRequest $request, ProfileLookupQuery $lookups): JsonResponse
{
$lookup = $lookups->get($request->handle());

return response()->json(['status' => $lookup['status'], 'resumes_at' => $lookup['resumesAt']]);
}

public function store(CreateApiProfileLookupRequest $request, CreateProfileLookup $action): Response
{
$action->handle($request->handle());

return response()->noContent(202);
}
}
35 changes: 35 additions & 0 deletions app/Http/Controllers/Api/UnclaimedProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api;

use App\Http\Requests\ShowApiUnclaimedProfileRequest;
use App\Models\Profile;
use App\Models\User;
use App\Queries\PendingFollowsQuery;
use App\Queries\UnclaimedProfileMentionCountQuery;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\JsonResponse;

final readonly class UnclaimedProfileController
{
/**
* A developer looked up from GitHub who isn't on /dev/null yet, as their page on the web shows them, with how many
* members wait to follow them and how many commits mention them. A signed request also gets whether its user waits,
* and who they follow that does.
*/
public function show(ShowApiUnclaimedProfileRequest $request, #[CurrentUser] ?User $user, PendingFollowsQuery $pendingFollows, UnclaimedProfileMentionCountQuery $mentions): JsonResponse
{
$profile = $request->profile();
assert($profile instanceof Profile);

return response()->json([
'data' => $profile->only(['id', 'handle', 'name', 'avatar_url', 'bio']),
'waiting_count' => $pendingFollows->count($profile),
'mention_count' => $mentions->get($profile),
'is_waiting' => $user instanceof User && $pendingFollows->isWaiting($profile, $user),
'waiting_you_follow' => $user instanceof User ? $pendingFollows->youFollow($profile, $user) : [],
]);
}
}
19 changes: 5 additions & 14 deletions app/Http/Controllers/UnclaimedProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use App\Http\Requests\ShowUnclaimedProfileRequest;
use App\Models\Profile;
use App\Models\User;
use App\Queries\PendingFollowsQuery;
use App\Queries\UnclaimedProfileMentionCountQuery;
use App\Services\PageMetadata;
use Illuminate\Container\Attributes\CurrentUser;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\DB;
use Inertia\Inertia;
use Inertia\Response;

Expand All @@ -22,7 +22,7 @@
* shows of them but where they are, for anyone with the link, but kept out of search engines, with how many members
* wait to follow them, and how many commits mention them. Signing in as them makes it theirs. Like users' pages, it moves for good to the handle's own case.
*/
public function show(ShowUnclaimedProfileRequest $request, #[CurrentUser] ?User $currentUser, PageMetadata $metadata, UnclaimedProfileMentionCountQuery $mentions): RedirectResponse|Response
public function show(ShowUnclaimedProfileRequest $request, #[CurrentUser] ?User $currentUser, PageMetadata $metadata, UnclaimedProfileMentionCountQuery $mentions, PendingFollowsQuery $pendingFollows): RedirectResponse|Response
{
$profile = $request->profile();
assert($profile instanceof Profile);
Expand All @@ -34,22 +34,13 @@ public function show(ShowUnclaimedProfileRequest $request, #[CurrentUser] ?User
return redirect(route('user.show', $profile->handle).($query === '' ? '' : "?{$query}"), 301, ['Cache-Control' => 'max-age=86400, private']);
}

$waiting = DB::table('pending_follows')->where('github_id', $profile->github_id);

return Inertia::render('profile/unclaimed', [
'profile' => $profile->only(['id', 'handle', 'name', 'avatar_url', 'bio']),
// Counting reads through the commits, so the page doesn't wait for it...
'mentionCount' => Inertia::defer(fn (): int => $mentions->get($profile)),
'waitingCount' => fn (): int => $waiting->clone()->count(),
'isWaiting' => fn (): bool => $currentUser instanceof User && $waiting->clone()->where('user_id', $currentUser->id)->exists(),
// Who follows whom is for members, so only they see who is waiting, among the people they follow...
'waitingYouFollow' => fn (): array => $currentUser instanceof User ? $currentUser->following()
->whereIn('users.id', $waiting->clone()->select('user_id'))
->orderBy('users.id')
->limit(3)
->get()
->map(fn (User $user): array => $user->only(['id', 'handle', 'name', 'avatar_url']))
->all() : [],
'waitingCount' => fn (): int => $pendingFollows->count($profile),
'isWaiting' => fn (): bool => $currentUser instanceof User && $pendingFollows->isWaiting($profile, $currentUser),
'waitingYouFollow' => fn (): array => $currentUser instanceof User ? $pendingFollows->youFollow($profile, $currentUser) : [],
])->withViewData(['preview' => $currentUser instanceof User || $request->inertia() ? null : $metadata->unclaimedProfile($profile)]);
}
}
31 changes: 31 additions & 0 deletions app/Http/Requests/CreateApiPendingFollowRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Models\Profile;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Http\FormRequest;

final class CreateApiPendingFollowRequest extends FormRequest
{
/**
* Only a developer who isn't on /dev/null yet is waited for: once they are, members follow them.
*/
public function authorize(): Response
{
$profile = $this->route('profile');
assert($profile instanceof Profile);

return $profile->isUnclaimed() ? Response::allow() : Response::denyAsNotFound();
}

/**
* @return array{}
*/
public function rules(): array
{
return [];
}
}
41 changes: 41 additions & 0 deletions app/Http/Requests/CreateApiProfileLookupRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use Closure;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;

final class CreateApiProfileLookupRequest extends FormRequest
{
/**
* @return array<string, array<int, mixed>>
*/
public function rules(): array
{
return [
'handle' => [
'bail',
'required',
'string',
'regex:/^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/',
Rule::unique('profiles', 'handle'),
// GitHub said there's no such account a moment ago, so it isn't asked again for a day...
function (string $attribute, string $value, Closure $fail): void {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if (Cache::has('github-profiles:not-found:'.Str::lower($value))) {
$fail(__('GitHub has no @:handle.', ['handle' => $value]));
}
},
],
];
}

public function handle(): string
{
return $this->string('handle')->value();
}
}
1 change: 1 addition & 0 deletions app/Http/Requests/CreateProfileLookupRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function rules(): array
{
return [
'handle' => [
'bail',
'required',
'string',
'regex:/^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$/',
Expand Down
31 changes: 31 additions & 0 deletions app/Http/Requests/DeleteApiPendingFollowRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Models\Profile;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Http\FormRequest;

final class DeleteApiPendingFollowRequest extends FormRequest
{
/**
* Only a developer who isn't on /dev/null yet is waited for: once they are, members follow them.
*/
public function authorize(): Response
{
$profile = $this->route('profile');
assert($profile instanceof Profile);

return $profile->isUnclaimed() ? Response::allow() : Response::denyAsNotFound();
}

/**
* @return array{}
*/
public function rules(): array
{
return [];
}
}
45 changes: 45 additions & 0 deletions app/Http/Requests/ShowApiProfileLookupRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Models\Profile;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;

final class ShowApiProfileLookupRequest extends FormRequest
{
/**
* Only a handle GitHub could have can be looked up. Someone who deleted their account here left for good, so their
* handle is missing, like one GitHub could not have. So is a handle a profile has, as a lookup that found it does.
*/
public function authorize(): Response
{
$handle = Str::lower($this->handle());

return preg_match('/^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){0,38}$/', $handle) === 1
&& Cache::get("github-profiles:not-found:{$handle}") !== 'deleted'
&& Profile::query()->where('handle', $this->handle())->doesntExist()
? Response::allow()
: Response::denyAsNotFound();
}

/**
* @return array{}
*/
public function rules(): array
{
return [];
}

public function handle(): string
{
$handle = $this->route('handle');
assert(is_string($handle));

return $handle;
}
}
38 changes: 38 additions & 0 deletions app/Http/Requests/ShowApiUnclaimedProfileRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Models\Profile;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Http\FormRequest;

final class ShowApiUnclaimedProfileRequest extends FormRequest
{
private ?Profile $profile = null;

public function authorize(): Response
{
return $this->profile()?->isUnclaimed() === true ? Response::allow() : Response::denyAsNotFound();
}

/**
* @return array{}
*/
public function rules(): array
{
return [];
}

/**
* Only developers who already have a page, whatever the case of the handle, so looking one up never asks GitHub.
*/
public function profile(): ?Profile
{
$handle = $this->route('handle');
assert(is_string($handle));

return $this->profile ??= Profile::query()->firstWhere('handle', $handle);
}
}
6 changes: 5 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ private function bootRateLimitingDefaults(): void
});

// Every lookup spends GitHub's shared budget, so a member gets a few an hour. Their page says so...
RateLimiter::for('profile-lookups', fn (Request $request): Limit => Limit::perHour(30)->by($this->userId($request))->response(function (): RedirectResponse {
RateLimiter::for('profile-lookups', fn (Request $request): Limit => Limit::perHour(30)->by($this->userId($request))->response(function (Request $request, array $headers): JsonResponse|RedirectResponse {
if ($request->is('api/*')) {
return new ApiException(ApiErrorCode::RateLimited, __('You looked up too many handles. Try again later.'), $headers)->render();
}

Inertia::flash('lookupThrottled', true);

return back();
Expand Down
Loading