From 407c265680658f7e590fb88931a1a02e72c1fc2b Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 12 Nov 2026 17:25:26 +0000 Subject: [PATCH 1/5] refactor: move pending follow queries into their own class --- .../UnclaimedProfileController.php | 19 ++------ app/Queries/PendingFollowsQuery.php | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 app/Queries/PendingFollowsQuery.php diff --git a/app/Http/Controllers/UnclaimedProfileController.php b/app/Http/Controllers/UnclaimedProfileController.php index 6e9312aa7..2e39943ca 100644 --- a/app/Http/Controllers/UnclaimedProfileController.php +++ b/app/Http/Controllers/UnclaimedProfileController.php @@ -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; @@ -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); @@ -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)]); } } diff --git a/app/Queries/PendingFollowsQuery.php b/app/Queries/PendingFollowsQuery.php new file mode 100644 index 000000000..57f010295 --- /dev/null +++ b/app/Queries/PendingFollowsQuery.php @@ -0,0 +1,48 @@ +waiting($profile)->count(); + } + + public function isWaiting(Profile $profile, User $user): bool + { + return $this->waiting($profile)->where('user_id', $user->id)->exists(); + } + + /** + * Who follows whom is for members, so they only see who is waiting among the people they follow. + * + * @return list + */ + public function youFollow(Profile $profile, User $user): array + { + /** @var list */ + return $user->following() + ->whereIn('users.id', $this->waiting($profile)->select('user_id')) + ->orderBy('users.id') + ->limit(3) + ->get() + ->map(fn (User $followed): array => $followed->only(['id', 'handle', 'name', 'avatar_url'])) + ->all(); + } + + private function waiting(Profile $profile): Builder + { + return DB::table('pending_follows')->where('github_id', $profile->github_id); + } +} From 9890d4ee53379cf1ab9381319e67c80e3ba5326e Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 12 Nov 2026 17:25:27 +0000 Subject: [PATCH 2/5] feat: let API clients look up GitHub profiles and wait to follow them --- .../Api/PendingFollowController.php | 34 +++++++ .../Api/ProfileLookupController.php | 33 +++++++ .../Api/UnclaimedProfileController.php | 32 +++++++ .../CreateApiPendingFollowRequest.php | 31 ++++++ .../CreateApiProfileLookupRequest.php | 40 ++++++++ .../DeleteApiPendingFollowRequest.php | 31 ++++++ .../Requests/ShowApiProfileLookupRequest.php | 45 +++++++++ .../ShowApiUnclaimedProfileRequest.php | 38 ++++++++ app/Providers/AppServiceProvider.php | 6 +- routes/api.php | 22 +++++ .../Api/PendingFollowControllerTest.php | 47 ++++++++++ .../Api/ProfileLookupControllerTest.php | 94 +++++++++++++++++++ .../Api/UnclaimedProfileControllerTest.php | 58 ++++++++++++ 13 files changed, 510 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Api/PendingFollowController.php create mode 100644 app/Http/Controllers/Api/ProfileLookupController.php create mode 100644 app/Http/Controllers/Api/UnclaimedProfileController.php create mode 100644 app/Http/Requests/CreateApiPendingFollowRequest.php create mode 100644 app/Http/Requests/CreateApiProfileLookupRequest.php create mode 100644 app/Http/Requests/DeleteApiPendingFollowRequest.php create mode 100644 app/Http/Requests/ShowApiProfileLookupRequest.php create mode 100644 app/Http/Requests/ShowApiUnclaimedProfileRequest.php create mode 100644 tests/Feature/Controllers/Api/PendingFollowControllerTest.php create mode 100644 tests/Feature/Controllers/Api/ProfileLookupControllerTest.php create mode 100644 tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php diff --git a/app/Http/Controllers/Api/PendingFollowController.php b/app/Http/Controllers/Api/PendingFollowController.php new file mode 100644 index 000000000..b7cb174ff --- /dev/null +++ b/app/Http/Controllers/Api/PendingFollowController.php @@ -0,0 +1,34 @@ +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(); + } +} diff --git a/app/Http/Controllers/Api/ProfileLookupController.php b/app/Http/Controllers/Api/ProfileLookupController.php new file mode 100644 index 000000000..41389a7c2 --- /dev/null +++ b/app/Http/Controllers/Api/ProfileLookupController.php @@ -0,0 +1,33 @@ +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); + } +} diff --git a/app/Http/Controllers/Api/UnclaimedProfileController.php b/app/Http/Controllers/Api/UnclaimedProfileController.php new file mode 100644 index 000000000..3a5935fe1 --- /dev/null +++ b/app/Http/Controllers/Api/UnclaimedProfileController.php @@ -0,0 +1,32 @@ +profile(); + assert($profile instanceof Profile); + + return response()->json([ + 'data' => $profile->only(['id', 'handle', 'name', 'avatar_url', 'bio']), + 'waiting_count' => $pendingFollows->count($profile), + 'is_waiting' => $user instanceof User && $pendingFollows->isWaiting($profile, $user), + 'waiting_you_follow' => $user instanceof User ? $pendingFollows->youFollow($profile, $user) : [], + ]); + } +} diff --git a/app/Http/Requests/CreateApiPendingFollowRequest.php b/app/Http/Requests/CreateApiPendingFollowRequest.php new file mode 100644 index 000000000..81783dbf5 --- /dev/null +++ b/app/Http/Requests/CreateApiPendingFollowRequest.php @@ -0,0 +1,31 @@ +route('profile'); + assert($profile instanceof Profile); + + return $profile->isUnclaimed() ? Response::allow() : Response::denyAsNotFound(); + } + + /** + * @return array{} + */ + public function rules(): array + { + return []; + } +} diff --git a/app/Http/Requests/CreateApiProfileLookupRequest.php b/app/Http/Requests/CreateApiProfileLookupRequest.php new file mode 100644 index 000000000..2de78376d --- /dev/null +++ b/app/Http/Requests/CreateApiProfileLookupRequest.php @@ -0,0 +1,40 @@ +> + */ + public function rules(): array + { + return [ + 'handle' => [ + '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 { + 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(); + } +} diff --git a/app/Http/Requests/DeleteApiPendingFollowRequest.php b/app/Http/Requests/DeleteApiPendingFollowRequest.php new file mode 100644 index 000000000..bf3241e54 --- /dev/null +++ b/app/Http/Requests/DeleteApiPendingFollowRequest.php @@ -0,0 +1,31 @@ +route('profile'); + assert($profile instanceof Profile); + + return $profile->isUnclaimed() ? Response::allow() : Response::denyAsNotFound(); + } + + /** + * @return array{} + */ + public function rules(): array + { + return []; + } +} diff --git a/app/Http/Requests/ShowApiProfileLookupRequest.php b/app/Http/Requests/ShowApiProfileLookupRequest.php new file mode 100644 index 000000000..af64c4d11 --- /dev/null +++ b/app/Http/Requests/ShowApiProfileLookupRequest.php @@ -0,0 +1,45 @@ +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; + } +} diff --git a/app/Http/Requests/ShowApiUnclaimedProfileRequest.php b/app/Http/Requests/ShowApiUnclaimedProfileRequest.php new file mode 100644 index 000000000..f97b8664f --- /dev/null +++ b/app/Http/Requests/ShowApiUnclaimedProfileRequest.php @@ -0,0 +1,38 @@ +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); + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 179d2b4be..b6f2c50ba 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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(); diff --git a/routes/api.php b/routes/api.php index ee64eceef..c413d68d4 100644 --- a/routes/api.php +++ b/routes/api.php @@ -68,6 +68,8 @@ use App\Http\Controllers\Api\OrgPingController; use App\Http\Controllers\Api\OrgReadController; use App\Http\Controllers\Api\OrgTypingController; +use App\Http\Controllers\Api\PendingFollowController; +use App\Http\Controllers\Api\ProfileLookupController; use App\Http\Controllers\Api\ProfileSearchController; use App\Http\Controllers\Api\RelatedCommitController; use App\Http\Controllers\Api\RemoteCandidateController; @@ -76,6 +78,7 @@ use App\Http\Controllers\Api\StarredCommitController; use App\Http\Controllers\Api\SuggestedUserController; use App\Http\Controllers\Api\SuggestionDismissalController; +use App\Http\Controllers\Api\UnclaimedProfileController; use App\Http\Controllers\Api\UserAutomaticTranslationController; use App\Http\Controllers\Api\UserBlockController; use App\Http\Controllers\Api\UserCommitController; @@ -140,6 +143,8 @@ ->name('api-organization-commit.index'); Route::get('organizations/{handle}/mentions', [OrganizationMentionController::class, 'index']) ->name('api-organization-mention.index'); + Route::get('unclaimed-profiles/{handle}', [UnclaimedProfileController::class, 'show']) + ->name('api-unclaimed-profile.show'); // Mentioned profiles: the user or organization a commit's or message's mention captured, by the id it carries, // as the web's mention links open them, so they still lead there once they rename... @@ -375,6 +380,23 @@ ->middleware('throttle:follows') ->name('api-user-follow.destroy'); + // Waiting to follow a developer who isn't on /dev/null yet... + Route::post('profiles/{profile}/pending-follow', [PendingFollowController::class, 'store']) + ->whereUuid('profile') + ->middleware('throttle:follows') + ->name('api-pending-follow.store'); + Route::delete('profiles/{profile}/pending-follow', [PendingFollowController::class, 'destroy']) + ->whereUuid('profile') + ->middleware('throttle:follows') + ->name('api-pending-follow.destroy'); + + // Profile Lookup: a handle nobody here has, looked up on GitHub, sharing the web's budget... + Route::get('profile-lookups/{handle}', [ProfileLookupController::class, 'show']) + ->name('api-profile-lookup.show'); + Route::post('profile-lookups', [ProfileLookupController::class, 'store']) + ->middleware('throttle:profile-lookups') + ->name('api-profile-lookup.store'); + // Organization Follow... Route::post('organizations/{handle}/follow', [OrganizationFollowController::class, 'store']) ->middleware('throttle:follows') diff --git a/tests/Feature/Controllers/Api/PendingFollowControllerTest.php b/tests/Feature/Controllers/Api/PendingFollowControllerTest.php new file mode 100644 index 000000000..1103c94a0 --- /dev/null +++ b/tests/Feature/Controllers/Api/PendingFollowControllerTest.php @@ -0,0 +1,47 @@ +member = User::factory()->create(); + $this->keyPair = apiKeyPairFor($this->member); +}); + +it('waits to follow a developer who is not here yet, and stops waiting', function (): void { + $profile = Profile::factory()->create(); + + signedApiRequest($this->keyPair, 'POST', route('api-pending-follow.store', $profile))->assertNoContent(); + signedApiRequest($this->keyPair, 'POST', route('api-pending-follow.store', $profile))->assertNoContent(); + + expect(DB::table('pending_follows')->where('github_id', $profile->github_id)->pluck('user_id')->all())->toBe([$this->member->id]); + + signedApiRequest($this->keyPair, 'DELETE', route('api-pending-follow.destroy', $profile))->assertNoContent(); + + $this->assertDatabaseEmpty('pending_follows'); +}); + +it('waits only for developers who are not here yet', function (Closure $profile): void { + $profile = $profile(); + + signedApiRequest($this->keyPair, 'POST', route('api-pending-follow.store', $profile))->assertNotFound(); + signedApiRequest($this->keyPair, 'DELETE', route('api-pending-follow.destroy', $profile))->assertNotFound(); + + $this->assertDatabaseEmpty('pending_follows'); +})->with([ + 'a user' => fn (): Profile => User::factory()->create()->profile, + 'an organization' => fn (): Profile => Organization::factory()->create()->profile, +]); + +it('lets only signed requests wait', function (): void { + $profile = Profile::factory()->create(); + + $this->postJson(route('api-pending-follow.store', $profile))->assertUnauthorized(); + $this->deleteJson(route('api-pending-follow.destroy', $profile))->assertUnauthorized(); + + $this->assertDatabaseEmpty('pending_follows'); +}); diff --git a/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php b/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php new file mode 100644 index 000000000..0aa8f8a55 --- /dev/null +++ b/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php @@ -0,0 +1,94 @@ +member = User::factory()->create(); + $this->keyPair = apiKeyPairFor($this->member); +}); + +it('says where looking a handle up on GitHub stands', function (Closure $setUp, string $status, bool $resumes): void { + $setUp(); + + signedApiRequest($this->keyPair, 'GET', route('api-profile-lookup.show', 'Octocat')) + ->assertOk() + ->assertJsonPath('status', $status) + ->assertJsonPath('resumes_at', fn (?string $resumesAt): bool => $resumes === ($resumesAt !== null)); +})->with([ + 'never looked up' => [fn (): null => null, 'idle', false], + 'being looked up' => [fn () => Cache::put('github-profiles:looking-up:octocat', true, 30), 'pending', false], + 'no GitHub account' => [fn () => Cache::put('github-profiles:not-found:octocat', 'missing', 60), 'missing', false], + 'waiting for the rate limit' => [fn () => Cache::put('github-organizations:paused', now()->addMinutes(30)->getTimestamp(), 60), 'paused', true], +]); + +it('answers not found for handles GitHub could not have, or of people who deleted their account', function (string $handle): void { + Cache::put('github-profiles:not-found:gone', 'deleted', 60); + + signedApiRequest($this->keyPair, 'GET', route('api-profile-lookup.show', $handle))->assertNotFound(); +})->with(['an underscore' => 'oct_cat', 'a trailing dash' => 'octocat-', 'too long' => str_repeat('a', 40), 'deleted' => 'gone']); + +it('looks a handle up, which then stands pending', function (): void { + Queue::fake([LookUpGitHubProfile::class]); + + signedApiRequest($this->keyPair, 'POST', route('api-profile-lookup.store'), ['handle' => 'Octocat'])->assertAccepted(); + + Queue::assertPushed(LookUpGitHubProfile::class, fn (LookUpGitHubProfile $job): bool => $job->handle === 'octocat'); + + signedApiRequest($this->keyPair, 'GET', route('api-profile-lookup.show', 'octocat'))->assertJsonPath('status', 'pending'); +}); + +it('answers not found once a lookup finds the handle, so the app opens its page instead', function (): void { + Cache::put('github-profiles:looking-up:octocat', true, 30); + signedApiRequest($this->keyPair, 'GET', route('api-profile-lookup.show', 'Octocat'))->assertJsonPath('status', 'pending'); + + Profile::factory()->create(['handle' => 'OctoCat']); + Cache::forget('github-profiles:looking-up:octocat'); + + signedApiRequest($this->keyPair, 'GET', route('api-profile-lookup.show', 'Octocat'))->assertNotFound(); +}); + +it('looks up only handles GitHub could have that nobody here has, and not again those it has no account for', function (string $handle): void { + Queue::fake([LookUpGitHubProfile::class]); + Profile::factory()->create(['handle' => 'taken']); + Cache::put('github-profiles:not-found:nobody', 'missing', 60); + + signedApiRequest($this->keyPair, 'POST', route('api-profile-lookup.store'), ['handle' => $handle]) + ->assertUnprocessable() + ->assertJsonValidationErrors('handle'); + + Queue::assertNothingPushed(); +})->with(['taken, whatever the case' => 'Taken', 'no GitHub account, whatever the case' => 'Nobody', 'an underscore' => 'oct_cat', 'empty' => '']); + +it('lets only signed requests look handles up', function (): void { + Queue::fake([LookUpGitHubProfile::class]); + + $this->getJson(route('api-profile-lookup.show', 'octocat'))->assertUnauthorized(); + $this->postJson(route('api-profile-lookup.store'), ['handle' => 'octocat'])->assertUnauthorized(); + + Queue::assertNothingPushed(); +}); + +it('shares the 30 lookups an hour with the web, then answers with a code', function (): void { + Queue::fake([LookUpGitHubProfile::class]); + + foreach (range(1, 15) as $index) { + $this->actingAs($this->member)->post(route('profile-lookup.store'), ['handle' => "octocat-{$index}"])->assertSessionHasNoErrors(); + } + + foreach (range(16, 30) as $index) { + signedApiRequest($this->keyPair, 'POST', route('api-profile-lookup.store'), ['handle' => "octocat-{$index}"])->assertAccepted(); + } + + signedApiRequest($this->keyPair, 'POST', route('api-profile-lookup.store'), ['handle' => 'octocat-31']) + ->assertTooManyRequests() + ->assertJsonPath('code', 'rate_limited') + ->assertHeader('Retry-After'); + + Queue::assertPushed(LookUpGitHubProfile::class, 30); +}); diff --git a/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php b/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php new file mode 100644 index 000000000..98d54a0ee --- /dev/null +++ b/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php @@ -0,0 +1,58 @@ +create([ + 'handle' => 'OctoCat', + 'name' => 'The Octocat', + 'avatar_url' => 'https://avatars.githubusercontent.com/u/583231', + 'bio' => 'I am the Octocat.', + 'location' => 'San Francisco', + 'website' => 'https://github.blog', + ]); + DB::table('pending_follows')->insert(['user_id' => User::factory()->create()->id, 'github_id' => $profile->github_id, 'created_at' => now()]); + + $this->getJson(route('api-unclaimed-profile.show', 'octocat')) + ->assertOk() + ->assertExactJson([ + 'data' => [ + 'id' => $profile->id, + 'handle' => 'OctoCat', + 'name' => 'The Octocat', + 'avatar_url' => 'https://avatars.githubusercontent.com/u/583231', + 'bio' => 'I am the Octocat.', + ], + 'waiting_count' => 1, + 'is_waiting' => false, + 'waiting_you_follow' => [], + ]); +}); + +it('tells a signed request whether its user waits, and up to three people they follow who do', function (): void { + $profile = Profile::factory()->create(['handle' => 'octocat']); + $member = User::factory()->create(); + $followed = User::factory()->count(4)->create()->sortBy('id')->values(); + $stranger = User::factory()->create(); + $member->following()->attach($followed->pluck('id')); + DB::table('pending_follows')->insert($followed->push($stranger, $member)->map(fn (User $user): array => ['user_id' => $user->id, 'github_id' => $profile->github_id, 'created_at' => now()])->all()); + + signedApiRequest(apiKeyPairFor($member), 'GET', route('api-unclaimed-profile.show', 'octocat')) + ->assertOk() + ->assertJsonPath('waiting_count', 6) + ->assertJsonPath('is_waiting', true) + ->assertJsonPath('waiting_you_follow', $followed->take(3)->map(fn (User $user): array => $user->only(['id', 'handle', 'name', 'avatar_url']))->all()); +}); + +it('answers not found for a handle that is no unclaimed developer, without asking GitHub', function (Closure $handle): void { + $this->getJson(route('api-unclaimed-profile.show', $handle()))->assertNotFound(); +})->with([ + 'a user' => fn (): string => User::factory()->create()->handle, + 'an organization' => fn (): string => Organization::factory()->create()->profile->handle, + 'unknown' => fn (): string => 'nobody', +]); From e9919fdda8b0c2458c777e73f16f1542e0a506cd Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 12 Nov 2026 17:25:27 +0000 Subject: [PATCH 3/5] docs: mention profile lookups and pending follows in the signed API --- KNOWLEDGE_BASE.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 6965f9e74..37ac132f3 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -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. 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 @@ -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; From 3c5359fb7519a78f919a9741c57221445f6b603f Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 12 Nov 2026 17:36:48 +0000 Subject: [PATCH 4/5] fix: answer 422 when a profile lookup handle isn't a string --- app/Http/Requests/CreateApiProfileLookupRequest.php | 1 + app/Http/Requests/CreateProfileLookupRequest.php | 1 + tests/Feature/Controllers/Api/ProfileLookupControllerTest.php | 4 ++-- tests/Feature/Controllers/ProfileLookupControllerTest.php | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Http/Requests/CreateApiProfileLookupRequest.php b/app/Http/Requests/CreateApiProfileLookupRequest.php index 2de78376d..3ec8da6da 100644 --- a/app/Http/Requests/CreateApiProfileLookupRequest.php +++ b/app/Http/Requests/CreateApiProfileLookupRequest.php @@ -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}$/', diff --git a/app/Http/Requests/CreateProfileLookupRequest.php b/app/Http/Requests/CreateProfileLookupRequest.php index 9e1405dc3..20ebc227e 100644 --- a/app/Http/Requests/CreateProfileLookupRequest.php +++ b/app/Http/Requests/CreateProfileLookupRequest.php @@ -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}$/', diff --git a/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php b/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php index 0aa8f8a55..70c085356 100644 --- a/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php +++ b/tests/Feature/Controllers/Api/ProfileLookupControllerTest.php @@ -53,7 +53,7 @@ signedApiRequest($this->keyPair, 'GET', route('api-profile-lookup.show', 'Octocat'))->assertNotFound(); }); -it('looks up only handles GitHub could have that nobody here has, and not again those it has no account for', function (string $handle): void { +it('looks up only handles GitHub could have that nobody here has, and not again those it has no account for', function (string|array $handle): void { Queue::fake([LookUpGitHubProfile::class]); Profile::factory()->create(['handle' => 'taken']); Cache::put('github-profiles:not-found:nobody', 'missing', 60); @@ -63,7 +63,7 @@ ->assertJsonValidationErrors('handle'); Queue::assertNothingPushed(); -})->with(['taken, whatever the case' => 'Taken', 'no GitHub account, whatever the case' => 'Nobody', 'an underscore' => 'oct_cat', 'empty' => '']); +})->with(['taken, whatever the case' => 'Taken', 'no GitHub account, whatever the case' => 'Nobody', 'an underscore' => 'oct_cat', 'empty' => '', 'not a string' => [['octocat']]]); it('lets only signed requests look handles up', function (): void { Queue::fake([LookUpGitHubProfile::class]); diff --git a/tests/Feature/Controllers/ProfileLookupControllerTest.php b/tests/Feature/Controllers/ProfileLookupControllerTest.php index a16c7f5db..125331626 100644 --- a/tests/Feature/Controllers/ProfileLookupControllerTest.php +++ b/tests/Feature/Controllers/ProfileLookupControllerTest.php @@ -119,7 +119,7 @@ expect(Cache::has('github-profiles:looking-up:octocat'))->toBeFalse(); }); -it('looks up only handles GitHub could have that nobody here has, and not again those it has no account for', function (string $handle): void { +it('looks up only handles GitHub could have that nobody here has, and not again those it has no account for', function (string|array $handle): void { Queue::fake(); Profile::factory()->create(['handle' => 'taken']); Cache::put('github-profiles:not-found:nobody', 'missing', 60); @@ -129,7 +129,7 @@ ->assertSessionHasErrors('handle'); Queue::assertNothingPushed(); -})->with(['taken, whatever the case' => 'Taken', 'no GitHub account, whatever the case' => 'Nobody', 'an underscore' => 'oct_cat', 'empty' => '']); +})->with(['taken, whatever the case' => 'Taken', 'no GitHub account, whatever the case' => 'Nobody', 'an underscore' => 'oct_cat', 'empty' => '', 'not a string' => [['octocat']]]); it('lets only members look handles up', function (): void { Queue::fake(); From 59daf7bcce3bb14993bcd5c0a5bef09ee75e239d Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 12 Nov 2026 18:42:23 +0000 Subject: [PATCH 5/5] feat: tell API clients how many commits mention an unclaimed developer --- KNOWLEDGE_BASE.md | 2 +- .../Controllers/Api/UnclaimedProfileController.php | 7 +++++-- .../Api/UnclaimedProfileControllerTest.php | 13 +++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 37ac132f3..4a17e2131 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -151,7 +151,7 @@ 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. -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. 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. +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). diff --git a/app/Http/Controllers/Api/UnclaimedProfileController.php b/app/Http/Controllers/Api/UnclaimedProfileController.php index 3a5935fe1..684fde075 100644 --- a/app/Http/Controllers/Api/UnclaimedProfileController.php +++ b/app/Http/Controllers/Api/UnclaimedProfileController.php @@ -8,6 +8,7 @@ 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; @@ -15,9 +16,10 @@ { /** * 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. A signed request also gets whether its user waits, and who they follow that does. + * 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): JsonResponse + public function show(ShowApiUnclaimedProfileRequest $request, #[CurrentUser] ?User $user, PendingFollowsQuery $pendingFollows, UnclaimedProfileMentionCountQuery $mentions): JsonResponse { $profile = $request->profile(); assert($profile instanceof Profile); @@ -25,6 +27,7 @@ public function show(ShowApiUnclaimedProfileRequest $request, #[CurrentUser] ?Us 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) : [], ]); diff --git a/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php b/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php index 98d54a0ee..489bdfe6a 100644 --- a/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php +++ b/tests/Feature/Controllers/Api/UnclaimedProfileControllerTest.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Models\Commit; use App\Models\Organization; use App\Models\Profile; use App\Models\User; @@ -29,6 +30,7 @@ 'bio' => 'I am the Octocat.', ], 'waiting_count' => 1, + 'mention_count' => 0, 'is_waiting' => false, 'waiting_you_follow' => [], ]); @@ -49,6 +51,17 @@ ->assertJsonPath('waiting_you_follow', $followed->take(3)->map(fn (User $user): array => $user->only(['id', 'handle', 'name', 'avatar_url']))->all()); }); +it('counts the approved commits that mention them, but not mentions in code or of a longer handle', function (): void { + Profile::factory()->create(['handle' => 'octocat']); + Commit::factory()->create(['body' => 'Thanks @octocat!']); + Commit::factory()->create(['body' => 'Paired with @OctoCat and @hubot today']); + Commit::factory()->create(['body' => 'Found @octocat-fan in the wild']); + Commit::factory()->create(['body' => 'Use `@octocat` in your config']); + Commit::factory()->pending()->create(['body' => 'Waiting on @octocat']); + + $this->getJson(route('api-unclaimed-profile.show', 'octocat'))->assertJsonPath('mention_count', 2); +}); + it('answers not found for a handle that is no unclaimed developer, without asking GitHub', function (Closure $handle): void { $this->getJson(route('api-unclaimed-profile.show', $handle()))->assertNotFound(); })->with([