From 203a3600c8816a0180e84a8a1be10f3d7a0f53f4 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Fri, 13 Nov 2026 13:00:44 +0000 Subject: [PATCH 1/3] test: cover the changelog in the API --- .../Api/ChangelogControllerTest.php | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 tests/Feature/Controllers/Api/ChangelogControllerTest.php diff --git a/tests/Feature/Controllers/Api/ChangelogControllerTest.php b/tests/Feature/Controllers/Api/ChangelogControllerTest.php new file mode 100644 index 000000000..3577e20a2 --- /dev/null +++ b/tests/Feature/Controllers/Api/ChangelogControllerTest.php @@ -0,0 +1,99 @@ + + */ +function apiChangelogCommit(int $number, string $committedAt, ?int $parent): array +{ + return [ + 'sha' => "c897f867{$number}", + 'message' => "feat: turn emoji shortcodes into emoji in remotes (#{$number})", + 'url' => "https://github.com/dev-null-sh/dev-null.sh/commit/c897f867{$number}", + 'committed_at' => $committedAt, + 'parents' => $parent === null ? [] : ["c897f867{$parent}"], + 'author' => ['id' => 14284867, 'login' => 'xHeaven', 'avatar_url' => 'https://avatars.githubusercontent.com/u/1?v=4'], + ]; +} + +function mockApiChangelog(): void +{ + test()->mock(GitHubProvider::class)->shouldReceive('commits') + ->andReturnUsing(fn (string $repository, string $branch, int $page): array => $page === 1 ? [ + apiChangelogCommit(377, '2026-10-17T23:30:00Z', 376), + apiChangelogCommit(376, '2026-10-16T12:00:00Z', 375), + apiChangelogCommit(375, '2026-10-15T12:00:00Z', 374), + apiChangelogCommit(374, '2026-10-14T12:00:00Z', null), + ] : []); +} + +it('lists the latest days of commits on production, signed or not, with a link to every commit on production', function (bool $isSigned): void { + mockApiChangelog(); + $uri = route('api-changelog.index', ['timezone' => 'UTC']); + + $response = $isSigned ? signedApiRequest(apiKeyPairFor(User::factory()->create()), 'GET', $uri) : $this->getJson($uri); + + $response->assertOk() + ->assertJsonCount(3, 'data') + ->assertJsonPath('data.0.sha', 'c897f867377') + ->assertJsonPath('data.0.pull_request.number', 377) + ->assertJsonPath('data.0.type', 'feat') + ->assertJsonPath('data.0.title', 'Turn emoji shortcodes into emoji in remotes') + ->assertJsonPath('data.0.author.login', 'xHeaven') + ->assertJsonPath('older_before', '2026-10-15T00:00:00+00:00') + ->assertJsonPath('commits_url', 'https://github.com/dev-null-sh/dev-null.sh/commits/production'); +})->with(['unsigned' => false, 'signed' => true]); + +it('groups days in the reader’s time zone, and carries on from where the reader is', function (): void { + mockApiChangelog(); + + $this->getJson(route('api-changelog.index', ['timezone' => 'Europe/Budapest'])) + ->assertJsonCount(3, 'data') + ->assertJsonPath('data.2.pull_request.number', 375); + + $this->getJson(route('api-changelog.index', ['timezone' => 'UTC', 'before' => '2026-10-15T00:00:00+00:00'])) + ->assertJsonCount(1, 'data') + ->assertJsonPath('data.0.pull_request.number', 374) + ->assertJsonPath('older_before', null); +}); + +it('uses the signed user’s time zone when the request names none', function (): void { + mockApiChangelog(); + $keyPair = apiKeyPairFor(User::factory()->create(['timezone' => 'Europe/Budapest'])); + + signedApiRequest($keyPair, 'GET', route('api-changelog.index')) + ->assertJsonPath('older_before', '2026-10-14T22:00:00+00:00'); + + signedApiRequest($keyPair, 'GET', route('api-changelog.index', ['timezone' => 'UTC'])) + ->assertJsonPath('older_before', '2026-10-15T00:00:00+00:00'); +}); + +it('falls back to the app’s time zone for a signed user who saved none', function (): void { + mockApiChangelog(); + config(['app.timezone' => 'Europe/Budapest']); + + signedApiRequest(apiKeyPairFor(User::factory()->create(['timezone' => null])), 'GET', route('api-changelog.index')) + ->assertJsonPath('older_before', '2026-10-14T22:00:00+00:00'); +}); + +it('rejects a time zone or a starting point it cannot read', function (array $query, string $field): void { + $this->getJson(route('api-changelog.index', $query)) + ->assertUnprocessable() + ->assertJsonValidationErrors($field); +})->with([ + 'unknown time zone' => [['timezone' => 'Mars/Olympus'], 'timezone'], + 'not a date' => [['timezone' => 'UTC', 'before' => 'yesterday-ish'], 'before'], +]); + +it('says the changelog is unavailable when GitHub cannot be reached', function (): void { + $this->mock(GitHubProvider::class)->shouldReceive('commits')->andThrow(new ConnectionException('timed out')); + + $this->getJson(route('api-changelog.index', ['timezone' => 'UTC'])) + ->assertServiceUnavailable() + ->assertJsonPath('code', 'changelog_unavailable'); +}); From c1ac74db48fdef50ff5b6756cbf1323c4d76e45b Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Fri, 13 Nov 2026 13:00:44 +0000 Subject: [PATCH 2/3] feat: let API clients read the changelog --- app/Enums/ApiErrorCode.php | 3 +- app/Exceptions/ApiException.php | 8 ++++ .../Controllers/Api/ChangelogController.php | 31 ++++++++++++ app/Http/Requests/ListApiChangelogRequest.php | 47 +++++++++++++++++++ routes/api.php | 3 ++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Api/ChangelogController.php create mode 100644 app/Http/Requests/ListApiChangelogRequest.php diff --git a/app/Enums/ApiErrorCode.php b/app/Enums/ApiErrorCode.php index 8febaf980..75da52ed5 100644 --- a/app/Enums/ApiErrorCode.php +++ b/app/Enums/ApiErrorCode.php @@ -26,6 +26,7 @@ enum ApiErrorCode: string case GitHubIssueRefused = 'github_issue_refused'; case GitHubIssueUnanswered = 'github_issue_unanswered'; case GuildPaused = 'guild_paused'; + case ChangelogUnavailable = 'changelog_unavailable'; public function status(): int { @@ -37,7 +38,7 @@ public function status(): int self::PasteisExhausted, self::GuildPaused => 422, self::RateLimited => 429, self::GitHubIssueRefused, self::GitHubIssueUnanswered => 502, - self::GitHubSyncFailed => 503, + self::GitHubSyncFailed, self::ChangelogUnavailable => 503, }; } } diff --git a/app/Exceptions/ApiException.php b/app/Exceptions/ApiException.php index 0022d7742..eae916d66 100644 --- a/app/Exceptions/ApiException.php +++ b/app/Exceptions/ApiException.php @@ -87,6 +87,14 @@ public static function gitHubIssueUnanswered(): self return new self(ApiErrorCode::GitHubIssueUnanswered, __('GitHub did not respond. Check the upstream issues before trying again. Your draft is safe.')); } + /** + * GitHub could not be read, so the changelog has nothing to list until it can. + */ + public static function changelogUnavailable(): self + { + return new self(ApiErrorCode::ChangelogUnavailable, __("GitHub can't be reached right now, so the changelog is unavailable. Try again in a moment.")); + } + /** * The user is banned, so the only thing left for them is deleting their account. */ diff --git a/app/Http/Controllers/Api/ChangelogController.php b/app/Http/Controllers/Api/ChangelogController.php new file mode 100644 index 000000000..c86578b6e --- /dev/null +++ b/app/Http/Controllers/Api/ChangelogController.php @@ -0,0 +1,31 @@ +get($request->timeZone(), $request->before()); + + if ($days === null) { + throw ApiException::changelogUnavailable(); + } + + return response()->json([ + 'data' => $days['commits'], + 'older_before' => $days['olderBefore'], + 'commits_url' => 'https://github.com/'.config()->string('services.github.repository').'/commits/'.ChangelogQuery::Branch, + ]); + } +} diff --git a/app/Http/Requests/ListApiChangelogRequest.php b/app/Http/Requests/ListApiChangelogRequest.php new file mode 100644 index 000000000..70b1785a6 --- /dev/null +++ b/app/Http/Requests/ListApiChangelogRequest.php @@ -0,0 +1,47 @@ +> + */ + public function rules(): array + { + return [ + 'timezone' => ['nullable', 'string', 'timezone:all'], + 'before' => ['nullable', 'date'], + ]; + } + + /** + * The time zone that decides where one day of merges ends: the one asked for, else the signed user's. + */ + public function timeZone(): string + { + $user = $this->user(); + $saved = $user instanceof User ? $user->timezone ?? null : null; + + return $this->string('timezone')->value() ?: $saved ?? config()->string('app.timezone'); + } + + /** + * Where the reader got to, to list the days merged before it. + */ + public function before(): ?CarbonImmutable + { + return $this->date('before')?->toImmutable(); + } +} diff --git a/routes/api.php b/routes/api.php index ee64eceef..0a705c99d 100644 --- a/routes/api.php +++ b/routes/api.php @@ -5,6 +5,7 @@ use App\Exceptions\ApiException; use App\Http\Controllers\Api\BroadcastAuthorizationController; use App\Http\Controllers\Api\CallController; +use App\Http\Controllers\Api\ChangelogController; use App\Http\Controllers\Api\CommitController as ApiCommitController; use App\Http\Controllers\Api\CommitPastelController; use App\Http\Controllers\Api\CommitPinController; @@ -140,6 +141,8 @@ ->name('api-organization-commit.index'); Route::get('organizations/{handle}/mentions', [OrganizationMentionController::class, 'index']) ->name('api-organization-mention.index'); + Route::get('changelog', [ChangelogController::class, 'index']) + ->name('api-changelog.index'); // Mentioned profiles: the user or organization a commit's or message's mention captured, by the id it carries, // as the web's mention links open them, so they still lead there once they rename... From ffa01ca47b3964aa0efa1ce69f711e02b2805153 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Fri, 13 Nov 2026 13:00:44 +0000 Subject: [PATCH 3/3] docs: describe the changelog in the API --- KNOWLEDGE_BASE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KNOWLEDGE_BASE.md b/KNOWLEDGE_BASE.md index 6965f9e74..898a97292 100644 --- a/KNOWLEDGE_BASE.md +++ b/KNOWLEDGE_BASE.md @@ -574,7 +574,7 @@ Sources: [GitHub action](.github/actions/commit/action.yml). ### Public read API and Atom feeds -The read-only JSON API at `/api/v1` requires no authentication or token, except for who follows whom. Read a public profile at `/api/v1/users/{handle}`, that user's commits at `/api/v1/users/{handle}/commits`, or one commit at `/api/v1/commits/{commit}`. `/api/v1/users/{handle}/followers` and `/following` list people the way the profile's people lists do, newest follow first, with each person's lane and whether you follow each other, and `/api/v1/users/{handle}/following/organizations` lists the organizations they follow the same way, with whether you follow each one; like on the web, they are for members only and need a [signed request](#signed-api-and-devices). Add `?replies=1` to the user-commits endpoint to read their replies instead of top-level commits. Lists use cursor pagination: 20 commits, or 30 people or organizations, per page. Only public approved, non-deleted content is returned, not private profile data such as email. Unsigned requests are limited to **60 requests per minute per IP** and cannot create posts, follow, or star; terminal posting and the [signed API](#signed-api-and-devices) are separate signed interfaces. +The read-only JSON API at `/api/v1` requires no authentication or token, except for who follows whom. Read a public profile at `/api/v1/users/{handle}`, that user's commits at `/api/v1/users/{handle}/commits`, or one commit at `/api/v1/commits/{commit}`. `/api/v1/users/{handle}/followers` and `/following` list people the way the profile's people lists do, newest follow first, with each person's lane and whether you follow each other, and `/api/v1/users/{handle}/following/organizations` lists the organizations they follow the same way, with whether you follow each one; like on the web, they are for members only and need a [signed request](#signed-api-and-devices). Add `?replies=1` to the user-commits endpoint to read their replies instead of top-level commits. Lists use cursor pagination: 20 commits, or 30 people or organizations, per page. `/api/v1/changelog` lists the commits on `production` three days at a time, like the Changelog page: days split in `?timezone=`, or a signed user's saved timezone, and `?before=` takes the `older_before` it returns; it answers 503 when GitHub can't be reached. Only public approved, non-deleted content is returned, not private profile data such as email. Unsigned requests are limited to **60 requests per minute per IP** and cannot create posts, follow, or star; terminal posting and the [signed API](#signed-api-and-devices) are separate signed interfaces. Subscribe in a feed reader to `/@{handle}/feed.atom` for a profile's latest **50 approved top-level commits**, including image enclosures. Feeds are public and can be cached for five minutes.