Repository navigation
feat: show the commits that mention developers who aren't on /dev/null yet #1545
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
Closed
kachelle
wants to merge
3
commits into
dev-null-sh:production
from
kachelle:feat/github-ghost-profiles
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
fdf08de
feat: show the commits that mention developers who aren't on /dev/nul…
kachelle 0b54c15
fix: leave earlier mentions to a handle's previous page, and keep Und…
kachelle 48b8c77
fix: backfill developer mentions with a command, check Undo by profil…
kachelle 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
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
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,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, '\\%_').'%'); | ||
| } | ||
| }) | ||
| ->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())); | ||
| } | ||
| } | ||
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
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.