Merge origin/main (#993) into feat/admin-errors-ux; rebuild bundles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 16:35:53 +00:00
commit dff9f580ee
5 files changed
+134 -98

No files matched your search

+30 -33
View File
@@ -161,45 +161,42 @@ export class GitHubRepository {
throw new AnonymousError("repo_not_found", { httpStatus: 404 });
}
this._data.branches = await this.branches(opt);
model.branches = this._data.branches;
// Serve the cached README without touching GitHub. Otherwise fetch it by
// branch name: listing every branch first (one GitHub page per 100
// branches) only to look up the head commit made the anonymize form's
// preview wait on the whole branch list.
const selected = (model.branches || []).filter((f) => f.name == opt.branch)[0];
if (selected?.readme && opt?.force !== true) return selected.readme;
const selected = model.branches.filter((f) => f.name == opt.branch)[0];
if (selected && (!selected.readme || opt?.force === true)) {
// get the list of repo from github
const oct = octokit(opt.accessToken);
try {
const ghRes = await oct.repos.getReadme({
owner: this.owner,
repo: this.repo,
ref: selected?.commit,
});
const readme = Buffer.from(
ghRes.data.content,
ghRes.data.encoding as BufferEncoding
).toString("utf-8");
selected.readme = readme;
await RepositoryModel.updateOne(
{ externalId: this.id, "branches.name": opt.branch },
{ $set: { "branches.$.readme": readme } }
).exec();
} catch (error) {
throw new AnonymousError("readme_not_available", {
httpStatus: 404,
cause: error as Error,
object: this,
});
}
}
if (!selected) {
const oct = octokit(opt.accessToken);
let readme: string;
try {
const ghRes = await oct.repos.getReadme({
owner: this.owner,
repo: this.repo,
ref: opt.force === true || !selected?.commit ? opt.branch : selected.commit,
});
readme = Buffer.from(
ghRes.data.content,
ghRes.data.encoding as BufferEncoding
).toString("utf-8");
} catch (error) {
throw new AnonymousError("readme_not_available", {
httpStatus: 404,
cause: error as Error,
object: this,
});
}
return selected.readme;
// Cache it on the branch entry when the branch list is already stored;
// the branches endpoint keeps cached READMEs when it refreshes the list.
if (selected) {
selected.readme = readme;
await RepositoryModel.updateOne(
{ externalId: this.id, "branches.name": opt.branch },
{ $set: { "branches.$.readme": readme } }
).exec();
}
return readme;
}
public get owner(): string {
+4 -1
View File
@@ -270,7 +270,10 @@ export default async function start() {
apiRouter.use("/pr", speedLimiter, router.pullRequestPrivate);
apiRouter.use("/gist", speedLimiter, router.gistPublic);
apiRouter.use("/gist", speedLimiter, router.gistPrivate);
apiRouter.use("/anonymize-preview", speedLimiter, router.anonymizePreview);
// The form previews on every edit, and slowing it down after 50 calls made
// typing feel broken. It only runs the anonymizer on posted text, never
// GitHub, so the shared API rate limit is enough.
apiRouter.use("/anonymize-preview", router.anonymizePreview);
// Cache message.txt presence so /api/message doesn't hit the filesystem
// synchronously on every request. Re-checked on a 60s interval — the file