Repository navigation
feat: Wrapped - Year Review #1550
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
PacketByte
wants to merge
13
commits into
dev-null-sh:production
Choose a base branch
from
PacketByte:feat/wrapped
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
13 commits
Select commit
Hold shift + click to select a range
befd3ff
feat: wrap the year in review for every profile
PacketByte 2888ee7
feat: monthly breakdown, heatmap, archetype and share summary for wra…
PacketByte 480d5b7
feat: fireworks finale and team sign-off for wrapped
PacketByte 8702458
feat: github-themed archetypes with night, weekend and comeback detec…
PacketByte 9571a3b
feat: top-level counts everywhere, top commit link, zero-state copy f…
PacketByte 2200cfa
feat: swipe sideways to move through wrapped on touch devices
PacketByte bcbe99c
feat: top 3 tech stack slide for wrapped from fence tags
PacketByte 66143bc
feat: notify handles when their Year in Review is ready
PacketByte 58e3a4c
Merge upstream production: keep timed_out beside wrapped_ready
PacketByte dc0f7f1
feat: lock wrapped behind a December 3rd countdown teaser
PacketByte 5889f19
feat: auto-open wrapped when the countdown hits zero
PacketByte 2dcc673
fix: address review findings on wrapped notifications, stats, and unlock
PacketByte c751ba8
fix: year-aware wrapped share urls and numeric fence regression test
PacketByte 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,62 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Actions; | ||
|
|
||
| use App\Enums\CommitStatus; | ||
| use App\Enums\NotificationType; | ||
| use App\Enums\UserUpdate; | ||
| use App\Events\UsersUpdated; | ||
| use App\Models\Notification; | ||
| use App\Models\User; | ||
| use Illuminate\Database\Eloquent\Builder; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| final readonly class CreateWrappedNotifications | ||
| { | ||
| /** | ||
| * Tells every handle with an approved commit that year that their Wrapped is ready, linking them to their own | ||
| * review. One row per handle per year, so running it again changes nothing. Never to bots. Safe to call more | ||
| * than once. | ||
| */ | ||
| public function handle(int $year): int | ||
| { | ||
| $recipientIds = User::query() | ||
| ->whereNotIn('github_id', User::BOT_GITHUB_IDS) | ||
| ->whereHas( | ||
| 'commits', | ||
| fn (Builder $commits): Builder => $commits | ||
| ->where('status', CommitStatus::Approved) | ||
| ->whereYear('created_at', $year), | ||
| ) | ||
| ->pluck('users.id'); | ||
|
|
||
| $now = now(); | ||
|
|
||
| $notifications = []; | ||
|
|
||
| foreach ($recipientIds as $recipientId) { | ||
| $notifications[] = [ | ||
| 'id' => Str::uuid7()->toString(), | ||
| 'recipient_id' => $recipientId, | ||
| 'actor_id' => $recipientId, | ||
| 'type' => NotificationType::WrappedReady->value, | ||
| 'commit_id' => null, | ||
| 'key' => 'wrapped:'.$year, | ||
| 'created_at' => $now, | ||
| 'updated_at' => $now, | ||
| ]; | ||
| } | ||
|
|
||
| foreach (array_chunk($notifications, 500) as $chunk) { | ||
| Notification::query()->insertOrIgnore($chunk); | ||
| } | ||
|
|
||
| if ($recipientIds->isNotEmpty()) { | ||
| event(new UsersUpdated($recipientIds->all(), UserUpdate::Notifications)); | ||
| } | ||
|
|
||
| return count($notifications); | ||
| } | ||
| } |
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,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Actions\CreateWrappedNotifications; | ||
| use Illuminate\Console\Attributes\Description; | ||
| use Illuminate\Console\Attributes\Signature; | ||
| use Illuminate\Console\Command; | ||
|
|
||
| #[Signature('wrapped:notify {--year= : The year to wrap, defaults to the current year}')] | ||
| #[Description('Tell every handle with a commit that year that their Wrapped is ready')] | ||
| final class NotifyWrappedCommand extends Command | ||
| { | ||
| public function handle(CreateWrappedNotifications $createWrappedNotifications): int | ||
| { | ||
| $year = (int) ($this->option('year') ?? date('Y')); | ||
|
|
||
| if ($year !== (int) date('Y')) { | ||
| $this->components->error('Wrapped notifications can only be queued for the current year.'); | ||
|
|
||
| return self::FAILURE; | ||
| } | ||
|
|
||
| $count = $createWrappedNotifications->handle($year); | ||
|
|
||
| $this->components->info("Wrapped notifications queued for {$count} handles for {$year}."); | ||
|
|
||
| return self::SUCCESS; | ||
| } | ||
| } | ||
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,70 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Models\Profile; | ||
| use App\Models\User; | ||
| use App\Queries\YearInReviewQuery; | ||
| use App\Services\PageMetadata; | ||
| use Illuminate\Container\Attributes\CurrentUser; | ||
| use Illuminate\Http\Request; | ||
| use Inertia\Inertia; | ||
| use Inertia\Response; | ||
|
|
||
| final readonly class YearInReviewController | ||
| { | ||
| public function show(#[CurrentUser] ?User $currentUser, Profile $profile, YearInReviewQuery $review, PageMetadata $metadata, Request $request): Response | ||
| { | ||
| $user = $profile->user; | ||
| $currentYear = (int) now()->year; | ||
| $requestedYear = $request->integer('year'); | ||
| $year = $requestedYear > 0 && $requestedYear <= $currentYear ? $requestedYear : $currentYear; | ||
|
|
||
| abort_unless($user instanceof User, 404); | ||
|
|
||
| $parameters = ['profile' => $profile->handle]; | ||
|
|
||
| if ($year !== $currentYear) { | ||
| $parameters['year'] = $year; | ||
| } | ||
|
|
||
| $shareUrl = route('wrapped.show', $parameters); | ||
|
|
||
| // Wrapped drops with the notification, every December 3rd at 09:00. | ||
| $unlocksAt = now()->setDate($year, 12, 3)->setTime(9, 0); | ||
|
|
||
| if (now()->lt($unlocksAt)) { | ||
| return Inertia::render('wrapped/show', [ | ||
| 'handle' => $profile->handle, | ||
| 'name' => $user->name, | ||
| 'avatarUrl' => $user->avatar_url, | ||
| 'stats' => null, | ||
| 'shareUrl' => $shareUrl, | ||
| 'locked' => true, | ||
| 'unlocksAt' => $unlocksAt->toIso8601String(), | ||
| ])->withViewData(['preview' => $metadata->page( | ||
| "{$profile->handle}'s {$year} Wrapped - /dev/null", | ||
| "The {$year} Wrapped for @{$profile->handle} unwraps December 3rd.", | ||
| $shareUrl, | ||
| )]); | ||
| } | ||
|
|
||
| $stats = $review->get($user, $currentUser, $year); | ||
|
|
||
| return Inertia::render('wrapped/show', [ | ||
| 'handle' => $profile->handle, | ||
| 'name' => $user->name, | ||
| 'avatarUrl' => $user->avatar_url, | ||
| 'stats' => $stats, | ||
| 'shareUrl' => $shareUrl, | ||
| 'locked' => false, | ||
| 'unlocksAt' => null, | ||
| ])->withViewData(['preview' => $metadata->page( | ||
| "{$profile->handle}'s {$year} in review - /dev/null", | ||
| "What @{$profile->handle} shipped in {$year}: {$stats['commits']} commits, {$stats['starsEarned']} stars and a {$stats['longestStreak']}-day streak.", | ||
| $shareUrl, | ||
| )]); | ||
| } | ||
| } |
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.