Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Not sure about this one. There's something here, but I think it needs a lot more finetuning |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A commit can now have a type. The body stays required (3 to 280 characters) and acts as the headline, and the type adds structured data next to it. This PR adds the architecture for types and ships the first one, Release, with a project, a version, and an optional link and notes. Plain text stays the default; replies and CLI commits are always plain text.
This is the first of three stacked PRs: #153 adds polls, snippets, quotes and questions on top of it, and #154 moves body code blocks onto the shared highlighter #153 introduces.
Summary
commits.typecolumn (CommitTypeenum, defaulttext), and one data class per type behind a single contract.CommitType::Releasewith areleasestable, shown in the composer and as a card in the feed, threads, profiles and the moderation queue.CommitBuilder::withContentFor(), feeds every place that renders a commit card.level: max.Why this design
A new type should touch a small, known set of files and leave the request, the action, the controllers and the queries alone. Five pieces make that work:
CommitTypeis the one enum of types.CommitType::data()maps each case to its data class, ornullfor plain text, through an exhaustivematch, so PHPStan rejects a case that has no data class.App\Contracts\Dto\CommitTypeDatais the contract every type with data implements:rules(User $user)<type>.<field>allowsImages()fromValidated(ValidatedInput $input)type()attributes()saveFor(Commit $commit)CreateCommit::handle()takes an optional?CommitTypeData $dataafter$images. It merges$data->attributes()into the commit's insert, sets the type, and callssaveFor()inside the transaction, so the commit and its data are written together or not at all.CreateCommitRequestresolves the type, mergesdata()::rules(), and exposestypeData(); one controller line passes it to the action.CommitBuilder::withContentFor($viewer)eager-loads what a card renders. The two logs, the commit page with its ancestors and replies, both profile queries, saved commits and the moderation queue call it instead of each keeping awith([...])list. Adding a type's relation here loads it everywhere a card appears, with no N+1. (The pinned commit and saved commits also gain images, which they loaded without before.)On the frontend,
resources/js/components/commit-types/composer-types.tslists the composer's types, each with a label, icon, placeholder andFieldscomponent. The composer renders one toggle button per entry, a hiddentypeinput, and the active type's fields;commit-type-content.tsxswitches oncommit.typeto render the card.CommitCardand thread replies render that content right after the body, so the moderation queue shows a type's data too.What's included
The architecture
CommitType(Text,Release),CommitTypeData,CreateCommitandCreateCommitRequestwiring,withContentFor(), and the frontend registry described above. Replies are validated as text only (the enum rule narrows toTextwhenparent_idis set); an unknown type never passes validation. A type can forbid images:CreateCommitRequestprohibits theimagesfield when the active type'sallowsImages()is false, with the message "A {type} can't have images", and the composer hides the image picker and blocks switching to such a type while images are attached. Release allows images, so nothing is blocked here; the plumbing lands now for Poll in #153.Release
A
releasestable holds one row per commit (commit_idunique, cascade on delete):project(max 50),version(max 30, no whitespace), nullableurl(http/https, max 255) andnotes(max 1000).ReleaseDatavalidates those, thereleaseinput accepts no other keys, andsaveFor()writes the row. The card shows a monoproject versiontag, the notes clamped to four lines behind "Show more", and a "View release" link (samerelas other user links) when there is a URL.Mobile (390px): composer, card light / dark.
A non-admin creates a release, a moderator approves it, and it shows up in the feed (MP4):
How to add a new type
CommitType, and its arm todata().final readonlyDTO inapp/Dto/CommitTypesthat implementsCommitTypeData.CommitFactorystate, and the relation onCommit.CommitBuilder::withContentFor().types/commit.ts, a case tocommit-type-content.tsx, and an entry with itsFieldstocomposer-types.ts.Nothing in
CreateCommitRequest,CreateCommit, the controllers or the query classes changes. #153 adds four types this way.Performance & security
withContentFor()eager-loads every relation a card needs, so a feed page, a thread or the moderation queue costs the same number of queries whether it holds one commit or twenty, and whatever mix of types. feat: polls, snippets, quotes and questions #153 adds a test that triples every type on a page and asserts the query count does not move.pending → approvedflow unchanged; the queue renders their data through the sameCommitCard.rules(). Thetypeinput is checked against the enum and narrowed to text on replies.Testing
966 tests, 100% line and type coverage, PHPStan
level: max.CommitControllerTest: creating a release with and without a link and notes and with images; release validation; a release commit missing its release; unknown types rejected; replies text-only; a missing or emptytypecreating a text commit; a release on its commit page, with its replies and as an ancestor.LogControllerTest,ModerationControllerTest,PinnedProfileCommitTest: releases in both logs, in the moderation queue, and as a pinned card with its images.Cli/CommitControllerTest: the CLI only creates text commits.CreateCommitTest: text by default, and a release saved with its commit.Related work
productionand untouched here; refactor: render body code blocks with the shared highlighter #154 builds on it.CreateCommit::handle()and no new call site in the query classes. feat: polls, snippets, quotes and questions #153 shows four types built that way.withContentFor(), which now loads images for those cards too; happy to rebase around whichever merges first.Notes for reviewers
devnull commitstays text-only, pinned by a test.🤖 Generated with Claude Code