Repository navigation
feat: list organization pages in the sitemap #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Http\Requests\ShowOrganizationSitemapRequest; | ||
| use App\Queries\SitemapQuery; | ||
| use Illuminate\Http\Response; | ||
|
|
||
| final readonly class OrganizationSitemapController | ||
| { | ||
| public function show(ShowOrganizationSitemapRequest $request, SitemapQuery $sitemaps): Response | ||
| { | ||
| return response()->view('sitemaps.urls', [ | ||
| 'urls' => array_map(fn (array $organization): array => [ | ||
| 'loc' => route('user.show', $organization['handle']), | ||
| 'lastmod' => $organization['updated_at']->toAtomString(), | ||
| ], $sitemaps->organizationsIn($request->month())), | ||
| ], headers: ['Content-Type' => 'application/xml; charset=UTF-8']); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use App\Queries\SitemapQuery; | ||
| use Carbon\CarbonImmutable; | ||
| use Illuminate\Auth\Access\Response; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| final class ShowOrganizationSitemapRequest extends FormRequest | ||
| { | ||
| /** | ||
| * A month that doesn't exist, like 2026-13, or without an organization to list, has no sitemap, so search | ||
| * engines drop a sitemap once everything it listed is gone. | ||
| */ | ||
| public function authorize(): Response | ||
| { | ||
| return $this->month()->format('Y-m') === $this->route('month') && resolve(SitemapQuery::class)->hasOrganizationsIn($this->month()) | ||
| ? Response::allow() | ||
| : Response::denyAsNotFound(); | ||
| } | ||
|
|
||
| /** | ||
| * @return array{} | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| /** | ||
| * The start of the month whose new organizations the sitemap lists, in UTC. | ||
| */ | ||
| public function month(): CarbonImmutable | ||
| { | ||
| $month = $this->route('month'); | ||
| assert(is_string($month)); | ||
|
|
||
| $start = CarbonImmutable::createFromFormat('!Y-m', $month); | ||
| assert($start instanceof CarbonImmutable); | ||
|
|
||
| return $start; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/Feature/Controllers/OrganizationSitemapControllerTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use App\Actions\CreateCommitTopics; | ||
| use App\Models\Commit; | ||
| use App\Models\Profile; | ||
| use App\Models\User; | ||
|
|
||
| it('lists every organization whose page was made that month', function (): void { | ||
| $laravel = Profile::factory()->organization()->create(['handle' => 'laravel', 'created_at' => '2026-10-01 00:00:00']); | ||
| Profile::factory()->organization()->create(['handle' => 'symfony', 'created_at' => '2026-10-31 23:59:59']); | ||
| resolve(CreateCommitTopics::class)->handle(Commit::factory()->create(['body' => 'Thanks @laravel']), ['laravel' => $laravel->id]); | ||
| Profile::factory()->organization()->create(['handle' => 'last-month', 'created_at' => '2026-09-30 23:59:59']); | ||
| Profile::factory()->organization()->create(['handle' => 'next-month', 'created_at' => '2026-11-01 00:00:00']); | ||
| Profile::factory()->organization()->create(['handle' => '_renamed-123', 'created_at' => '2026-10-15 00:00:00']); | ||
| Commit::factory()->for(User::factory()->state(['handle' => 'octocat', 'created_at' => '2026-10-15 00:00:00']))->create(); | ||
|
|
||
| $response = $this->get(route('organization-sitemap.show', '2026-10')); | ||
|
|
||
| $response->assertOk() | ||
| ->assertHeader('Content-Type', 'application/xml; charset=UTF-8') | ||
| ->assertSeeInOrder([ | ||
| '<loc>'.route('user.show', 'laravel').'</loc>', | ||
| '<loc>'.route('user.show', 'symfony').'</loc>', | ||
| ], false) | ||
| ->assertDontSee('last-month') | ||
| ->assertDontSee('next-month') | ||
| ->assertDontSee('_renamed-123') | ||
| ->assertDontSee('octocat'); | ||
|
|
||
| expect(mb_substr_count($response->getContent(), '<url>'))->toBe(2); | ||
| }); | ||
|
|
||
| it('dates an organization by the last change of its GitHub profile or the approved commits that mention it', function (string $profile, string $mention, string $lastmod): void { | ||
| $this->travelTo('2026-10-01 00:00:00'); | ||
| $laravel = Profile::factory()->organization()->create(['handle' => 'laravel']); | ||
| Profile::query()->whereKey($laravel->id)->toBase()->update(['updated_at' => $profile]); | ||
| resolve(CreateCommitTopics::class)->handle(Commit::factory()->create(['body' => '@laravel', 'updated_at' => $mention]), ['laravel' => $laravel->id]); | ||
| resolve(CreateCommitTopics::class)->handle(Commit::factory()->pending()->create(['body' => '@laravel', 'updated_at' => '2026-10-29 00:00:00']), ['laravel' => $laravel->id]); | ||
| resolve(CreateCommitTopics::class)->handle(Commit::factory()->create(['body' => '@symfony', 'updated_at' => '2026-10-28 00:00:00']), ['symfony' => Profile::factory()->organization()->create()->id]); | ||
|
|
||
| $this->get(route('organization-sitemap.show', '2026-10')) | ||
| ->assertOk() | ||
| ->assertSee('<loc>'.route('user.show', 'laravel')."</loc>\n <lastmod>{$lastmod}</lastmod>", false); | ||
| })->with([ | ||
| 'its GitHub profile' => ['2026-10-20 10:00:00', '2026-10-10 10:00:00', '2026-10-20T10:00:00+00:00'], | ||
| 'a commit that mentions it' => ['2026-10-10 10:00:00', '2026-10-20 10:00:00', '2026-10-20T10:00:00+00:00'], | ||
| ]); | ||
|
|
||
| it('has no sitemap for a month without organizations', function (): void { | ||
| Profile::factory()->organization()->create(['created_at' => '2026-09-15 00:00:00']); | ||
| Profile::factory()->organization()->create(['handle' => '_renamed-123', 'created_at' => '2026-10-15 00:00:00']); | ||
|
|
||
| $this->get(route('organization-sitemap.show', '2026-10'))->assertNotFound(); | ||
| }); | ||
|
|
||
| it('has no sitemap for a month that does not exist', function (string $month): void { | ||
| $this->get("/sitemaps/organizations-{$month}.xml")->assertNotFound(); | ||
| })->with(['2026-13', '2026-00', '2026-1', 'abc']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 8434
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 42162
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 23699
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 6153
Touch affected organization profiles when deleting a mentioning commit.
The organization page removes the deleted commit because
OrganizationMentionsQueryuses the soft-deletedCommitmodel. The sitemap query then removes that commit fromlast_mentionswithout updatingprofiles.updated_at. The organization sitemap can report an older timestamp, and the sitemap index can remain stale.Update affected organization profiles in the deletion transaction only for approved commits.
Suggested fix
ast-grep (0.50.0)
[error] 234-239: Prevent raw SQL injections
Context: Profile::query()
->leftJoinSub($lastMentions, 'last_mentions', 'last_mentions.topic_id', '=', 'profiles.id')
->where('profiles.type', ProfileType::Organization)
->where('profiles.handle', 'not like', '_%')
->select(['profiles.handle', 'profiles.created_at'])
->selectRaw('greatest(profiles.updated_at, last_mentions.updated_at) as updated_at')
Note: [CWE-89] Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
(laravel-raw-sql-injection)
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 7950
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 10569
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 40824
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 19867
Update the organization timestamp when a new topic link is created.
UpdateCommitTopicscan add an organization link to an existing approved commit. When the organization is already fresh, that path does not update its profile.CreateCommitTopicsthen inserts the link without changing eithercommits.updated_atorprofiles.updated_at. The organization sitemap and its indexlastmodcan therefore remain stale.Suggested fix
ast-grep (0.50.0)
[error] 234-239: Prevent raw SQL injections
Context: Profile::query()
->leftJoinSub($lastMentions, 'last_mentions', 'last_mentions.topic_id', '=', 'profiles.id')
->where('profiles.type', ProfileType::Organization)
->where('profiles.handle', 'not like', '_%')
->select(['profiles.handle', 'profiles.created_at'])
->selectRaw('greatest(profiles.updated_at, last_mentions.updated_at) as updated_at')
Note: [CWE-89] Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
(laravel-raw-sql-injection)
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 15519
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 29646
Script executed:
Repository: dev-null-sh/dev-null.sh
Length of output: 4698
Touch affected organization profiles during account deletion.
DeleteUser::handle()removescommit_topicsand deletes or soft-deletes the user's commits without callingDeleteCommit. Therefore, a profile touch added toDeleteCommitwill not cover account deletion. When the deleted commits were the latest approved mentions, the organization page changes butprofiles.updated_atdoes not advance, so the organization sitemaplastmodcan remain stale.Suggested fix
$user->commits()->withTrashed()->topLevel()->orderBy('id')->lockForUpdate()->pluck('id'); $this->touchedCommits($user)->orderBy('id')->lockForUpdate()->pluck('id'); + $organizationIds = DB::table('commit_topics') + ->join('commits', 'commits.id', '=', 'commit_topics.commit_id') + ->whereIn('commits.id', $this->touchedCommits($user)->select('id')) + ->where('commits.status', CommitStatus::Approved->value) + ->where('commit_topics.topic_type', TopicType::Organization->value) + ->pluck('commit_topics.topic_id') + ->all(); + DB::table('commit_topics')->whereIn('commit_id', $this->touchedCommits($user)->select('id'))->delete(); $user->commits()->withTrashed()->topLevel()->forceDelete(); ... $user->commits()->delete(); $user->commits()->withTrashed()->update(['user_id' => null, 'body' => '', 'mentions' => null, 'embedding' => null, 'link_preview_id' => null]); + Profile::query() + ->whereIn('id', $organizationIds) + ->update(['updated_at' => now()]); + $this->deleteOrgs->handle($this->emptyOrgs($user));ast-grep (0.50.0)
[error] 234-239: Prevent raw SQL injections
Context: Profile::query()
->leftJoinSub($lastMentions, 'last_mentions', 'last_mentions.topic_id', '=', 'profiles.id')
->where('profiles.type', ProfileType::Organization)
->where('profiles.handle', 'not like', '_%')
->select(['profiles.handle', 'profiles.created_at'])
->selectRaw('greatest(profiles.updated_at, last_mentions.updated_at) as updated_at')
Note: [CWE-89] Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
(laravel-raw-sql-injection)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declining these on purpose, for the same reason as on #1287.
lastmodis a crawl hint, and keeping it exact on removals or late topic links would mean touchingprofilesfromDeleteCommit,DeleteUserand the commit topic actions: sitemap concerns spread across write paths outside this change. An organization page losing or gaining one mention is picked up on the regular recrawl. Listed as a known limitation; can be a follow-up if it ever matters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mnapoli Understood. Exact
lastmodtracking for removals and late topic links is an accepted limitation. I won’t press for profile timestamp updates across those write paths in this PR.Would you like a GitHub issue to track the optional follow-up?
You are interacting with an AI system.