Repository navigation
feat: render commit links as quote cards #1153
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
Open
MrPunyapal
wants to merge
4
commits into
dev-null-sh:production
Choose a base branch
from
MrPunyapal:feat/commit-link-preview-quote-card
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0d62538
feat: render commit links as quote cards
MrPunyapal a5c2ce8
Rework commit-link previews for profile authors and live updates
MrPunyapal 2b967a4
Fix linked quote previews and guest return URL
MrPunyapal ff52976
test: verify resolved commit cards inside quotes
MrPunyapal 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Requests; | ||
|
|
||
| use App\Models\Commit; | ||
| use Illuminate\Auth\Access\Response; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| final class ShowCommitPreviewRequest extends FormRequest | ||
| { | ||
| public function authorize(): Response | ||
| { | ||
| $commit = $this->route('commit'); | ||
| assert($commit instanceof Commit); | ||
|
|
||
| return $commit->isVisibleTo($this->user()) ? Response::allow() : Response::denyAsNotFound(); | ||
| } | ||
|
|
||
| /** | ||
| * @return array{} | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return []; | ||
| } | ||
| } |
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,21 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Queries; | ||
|
|
||
| use App\Models\Commit; | ||
| use App\Models\Profile; | ||
| use App\Models\User; | ||
|
|
||
| final readonly class CommitPreviewQuery | ||
| { | ||
| public function get(Commit $commit, Profile $author, ?User $viewer): Commit | ||
| { | ||
| return Commit::query() | ||
| ->with(['images', 'linkPreview']) | ||
| ->withPollFor($viewer) | ||
| ->findOrFail($commit->id) | ||
| ->setRelation('author', $author); | ||
| } | ||
| } |
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,45 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Services; | ||
|
|
||
| use Illuminate\Routing\Route; | ||
| use Illuminate\Routing\Router; | ||
| use Illuminate\Support\Str; | ||
| use Uri\WhatWg\Url; | ||
|
|
||
| final readonly class CommitLinks | ||
| { | ||
| public function __construct(private Router $router) | ||
| { | ||
| // | ||
| } | ||
|
|
||
| /** | ||
| * Reads this site's commit route without dispatching a request or loading its models. | ||
| */ | ||
| public function previewUrl(string $url): ?string | ||
| { | ||
| $parsed = Url::parse($url); | ||
| $site = Url::parse(config()->string('app.url')); | ||
| assert($site instanceof Url); | ||
|
|
||
| if (! $parsed instanceof Url | ||
| || ! in_array($parsed->getScheme(), ['http', 'https'], true) | ||
| || $parsed->getAsciiHost() !== $site->getAsciiHost() | ||
| || $parsed->getPort() !== $site->getPort()) { | ||
| return null; | ||
| } | ||
|
|
||
| $route = $this->router->getRoutes()->getByName('commit.show'); | ||
| assert($route instanceof Route); | ||
|
|
||
| if (preg_match($route->toSymfonyRoute()->compile()->getRegex(), mb_rtrim($parsed->getPath(), '/'), $matches) !== 1 | ||
| || ! Str::isUuid($matches['commit'])) { | ||
| return null; | ||
| } | ||
|
|
||
| return route('commit-preview.show', ['profile' => $matches['profile'], 'commit' => $matches['commit']], absolute: false); | ||
| } | ||
| } |
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,67 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { QuotedCommit } from '@/components/quoted-commit'; | ||
| import { Skeleton } from '@/components/ui/skeleton'; | ||
| import type { QuotedCommit as QuotedCommitData } from '@/types'; | ||
|
|
||
| export function CommitLinkPreview({ | ||
| url, | ||
| isStatic = false, | ||
| }: { | ||
| url: string; | ||
| isStatic?: boolean; | ||
| }) { | ||
| const [commit, setCommit] = useState<QuotedCommitData | null>(); | ||
|
|
||
| useEffect(() => { | ||
| const controller = new AbortController(); | ||
|
|
||
| void fetch(url, { | ||
| headers: { Accept: 'application/json' }, | ||
| cache: 'no-store', | ||
| signal: controller.signal, | ||
| }) | ||
| .then(async (response) => { | ||
| const data = response.ok | ||
| ? ((await response.json()) as { commit: QuotedCommitData }) | ||
| : null; | ||
|
|
||
| if (!controller.signal.aborted) { | ||
| setCommit(data?.commit ?? null); | ||
| } | ||
| }) | ||
| .catch(() => { | ||
| if (!controller.signal.aborted) { | ||
| setCommit(null); | ||
| } | ||
| }); | ||
|
|
||
| return () => controller.abort(); | ||
| }, [url]); | ||
|
|
||
| if (commit === undefined) { | ||
| return ( | ||
| <div | ||
| aria-busy="true" | ||
| aria-label="Loading linked commit" | ||
| className="mt-2 animate-in rounded-lg border px-3 py-2 delay-300 fill-mode-backwards fade-in" | ||
| data-test="commit-link-preview-skeleton" | ||
| > | ||
| <div className="flex items-center gap-1.5"> | ||
| <Skeleton className="size-5 rounded-full" /> | ||
| <Skeleton className="h-3 w-32" /> | ||
| </div> | ||
| <Skeleton className="mt-2 h-4 w-full" /> | ||
| <Skeleton className="mt-2 h-4 w-2/3" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <QuotedCommit | ||
| commit={commit} | ||
| label="Linked commit" | ||
| isPreview={isStatic} | ||
| suppressLinkedPreview | ||
| /> | ||
| ); | ||
| } |
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
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.