Repository navigation
feat: public read API and Atom feeds - #98
Merged
Merged
Conversation
# Conflicts: # app/Queries/CommitBuilder.php
# Conflicts: # PRODUCT.md
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.
Summary
A public, read-only JSON API under
/api/v1, and an Atom feed for every profile. No tokens and no sign-in. It returns exactly what a guest's link preview may already show, so pending, rejected and deleted commits never leak.Endpoints
GET /api/v1/users/{username}commits_count,followers_count,following_countGET /api/v1/users/{username}/commits?replies=1lists the user's replies instead, like the profile's Replies tabGET /api/v1/commits/{id}GET /@{username}/feed.atomA commit has
id,short_hash(last 7 hex characters of the UUID, the same asshortHash()inutils.ts),body,parent_id,html_url(commit.show),created_at(ISO 8601 UTC),stars_count,replies_count,link_preview(url,title,description,image_url,site_name, ornull) andauthor.A user has
id,username,name,avatar_url,bio,company,location,website,github_url,html_url,feed_urlandcreated_at, plus the counts on the profile endpoint. Email,github_id,preferred_laneandremember_tokenare never included, and the resources list every field explicitly.Visibility
The rules are the ones
loadPublicPreview()andloadPublicCounts()already use. They are now also aCommitBuilder::withPublicPreview()scope, so lists don't make a query per commit:approved()commits. Soft-deleted commits are left out of lists, and asking for one directly is a 404.replies_countonly counts approved, non-deleted replies.commits_countonly counts approved commits.parent_idis only set while the parent is approved and not deleted. Otherwise it isnull, so a reply under a pending parent can't reveal that the parent exists, or its UUIDv7 timestamp.Atom feed
XMLWriterin aRenderUserFeedaction, like the OG image actions, so escaping is handled by the writer. Control characters that XML 1.0 can't carry, even escaped, are stripped, which keeps the feed well-formed for any commit body.<id>isurn:uuid:{user id}and each entry's<id>isurn:uuid:{commit id}. They stay the same when a GitHub username changes, even though thelinks change.titleis the squished body cut at 72 characters on a word boundary (a git subject line), andcontent type="text"holds the full body.Cache-Control: public, max-age=300and an ETag through Laravel'scache.headersmiddleware, so readers that revalidate get a304.<link rel="alternate" type="application/atom+xml">is added to the profile's guest preview inapp.blade.php, next to the OG tags. Crawlers and feed readers are guests, so that's the HTML they get.Rate limit and CORS
apilimiter of 60 requests a minute per IP, defined next tocommitsinAppServiceProvider. It returns Laravel's standard JSON 429 withRetry-AfterandX-RateLimit-*headers.config/cors.php. The framework default already allows any origin onapi/*, and a test now covers it (Access-Control-Allow-Origin: *).routes/api.phpfollows thecligroup:Route::prefix('v1')->middleware('throttle:api'), withapi-user.show,api-user-commit.indexandapi-commit.show. Errors underapi/*were already JSON.Try it
README.mdhas a short "Public API" section with the endpoints and the feed URL.Media
These are backend changes, so every image is a local mock page that shows real
curl/jqoutput and responses from my worktree onlocalhost:8105, with realistic seeded data. The local server ran withAPP_DEBUG=false, so errors look like they do in production.Paging through
next_cursorMP4
GET /api/v1/users/{username}GET /api/v1/users/{username}/commitsOne commit with a link preview, plus
meta.GET /api/v1/commits/{id}A reply with its public parent, a pending commit (404), and a link preview.
Rate limit and CORS
The feed: discovery link, cache headers, 304, XML
In a feed reader
A local mock reader that parses the real
feed.atomwithDOMParser. The selected entry has&and<script>in its body, and they come through as text.Testing
Api/UserControllerTest: the exact profile JSON with public counts (pending, rejected and deleted commits don't count), hidden fields never present, and a 404 for an unknown username.Api/UserCommitControllerTest: top-level only and newest first, with pending, rejected, deleted and other users' commits left out. Also?replies=1, cursor paging that keepsrepliesinlinks.next, validation ofreplies, a 404 for an unknown user, and the same query count for 1 and 6 commits (no N+1) on both lists.Api/CommitControllerTest: the exact commit JSON (short hash, URLs, author), approved-only reply count and star count,parent_idonly for a public parent (approved, pending, rejected and deleted cases), link preview fields, hidden user fields, a 404 for pending, rejected, deleted, unknown and malformed ids, JSON without anAcceptheader, CORS, and 60 requests then a 429, with other IPs unaffected.UserFeedControllerTest: a parsed feed with its id, title, subtitle, updated, author, self and alternate links, and entry ids, links, dates and content. Also what's excluded, the 50 limit, 72-character titles, escaping (&,",<script>,]]>) and stripped control characters, an empty feed, cache headers with an ETag and a304, and a 404 for an unknown user.UserControllerTest: the guest preview has therel="alternate"feed link, and the signed-in page doesn't.AppServiceProviderTest: theapilimiter.peston the new and affected files, plusArchTest,CommitBuilderTest,CommitControllerTestand theClicontrollers: 135 passed. Pint and Rector are clean on the touched files, PHPStan (level max) reports no errors on the touched app and route files, andpest --type-coverage --min=100reports 100%.bun run buildandtsc --noEmitpass (no frontend changes).xmllint --nooutaccepts the seeded feed.Known gaps
webroute like the OG image routes, so every fetch sets session and XSRF cookies, and with the database session driver each new reader writes a session row. Moving public read routes off the session middleware would be a separate change across all of them.<link rel="alternate">. Readers and crawlers are guests, so they find it.No query results for model [App\Models\Commit] {id}). They look the same for pending, rejected, deleted and unknown ids, so they don't reveal whether a commit exists.