Skip to content

feat: commit types, starting with releases - #152

Closed
ArtMin96 wants to merge 1 commit into
dev-null-sh:productionfrom
ArtMin96:feat/commit-types-foundation
Closed

ArtMin96 wants to merge 1 commit into
dev-null-sh:productionfrom
ArtMin96:feat/commit-types-foundation

Conversation

@ArtMin96

@ArtMin96 ArtMin96 commented Oct 15, 2026 •

Copy link
Copy Markdown

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.type column (CommitType enum, default text), and one data class per type behind a single contract.
  • CommitType::Release with a releases table, shown in the composer and as a card in the feed, threads, profiles and the moderation queue.
  • One eager-loading point, CommitBuilder::withContentFor(), feeds every place that renders a commit card.
  • 966 tests, 100% line and type coverage, PHPStan at 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:

  • CommitType is the one enum of types. CommitType::data() maps each case to its data class, or null for plain text, through an exhaustive match, so PHPStan rejects a case that has no data class.

  • App\Contracts\Dto\CommitTypeData is the contract every type with data implements:

    Method Does
    rules(User $user) the type's validation rules, keyed <type>.<field>
    allowsImages() whether a commit of this type may carry images
    fromValidated(ValidatedInput $input) builds the DTO from the validated input
    type() the enum case
    attributes() columns the type sets on the commit itself, written by the same insert
    saveFor(Commit $commit) persists the type's own rows, inside the create transaction
  • CreateCommit::handle() takes an optional ?CommitTypeData $data after $images. It merges $data->attributes() into the commit's insert, sets the type, and calls saveFor() inside the transaction, so the commit and its data are written together or not at all. CreateCommitRequest resolves the type, merges data()::rules(), and exposes typeData(); 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 a with([...]) 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.ts lists the composer's types, each with a label, icon, placeholder and Fields component. The composer renders one toggle button per entry, a hidden type input, and the active type's fields; commit-type-content.tsx switches on commit.type to render the card. CommitCard and 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, CreateCommit and CreateCommitRequest wiring, withContentFor(), and the frontend registry described above. Replies are validated as text only (the enum rule narrows to Text when parent_id is set); an unknown type never passes validation. A type can forbid images: CreateCommitRequest prohibits the images field when the active type's allowsImages() 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 releases table holds one row per commit (commit_id unique, cascade on delete): project (max 50), version (max 30, no whitespace), nullable url (http/https, max 255) and notes (max 1000). ReleaseData validates those, the release input accepts no other keys, and saveFor() writes the row. The card shows a mono project version tag, the notes clamped to four lines behind "Show more", and a "View release" link (same rel as other user links) when there is a URL.

Light Dark
Composer
Card, notes folded
Card, notes expanded
Pending, in moderation
Feed

Mobile (390px): composer, card light / dark.

A non-admin creates a release, a moderator approves it, and it shows up in the feed (MP4):

Release created, approved, then shown in the feed

How to add a new type

  1. Add the case to CommitType, and its arm to data().
  2. Write a final readonly DTO in app/Dto/CommitTypes that implements CommitTypeData.
  3. Add the migration, model and factory, a CommitFactory state, and the relation on Commit.
  4. Load the relation in CommitBuilder::withContentFor().
  5. Frontend: add the union member and field to types/commit.ts, a case to commit-type-content.tsx, and an entry with its Fields to composer-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.
  • Typed commits go through the existing pending → approved flow unchanged; the queue renders their data through the same CommitCard.
  • The body stays 3 to 280 characters. Type fields are validated by the type's own rules(). The type input 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 empty type creating 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

Notes for reviewers

  • Types are created from the web composer only. devnull commit stays text-only, pinned by a test.
  • The commit message trailer credits Claude Code, which wrote the branch under my direction.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@brendt

brendt commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Not sure about this one. There's something here, but I think it needs a lot more finetuning

@ArtMin96 ArtMin96 closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants