feat: store the repository picker list and update it by webhook

The anonymize page's "Your repositories" picker now pages and searches a
per-user list stored in MongoDB instead of calling GitHub on every page and
search. GitHub is read only when the list is empty, when the user presses
the new refresh button, or after an installation change marks it stale.

- One sync per list (Mongo lock with a renewed lease); full pagination in
  the background after the first page is returned; rate limits pause syncs.
- GitHub App installation, installation_repositories and repository
  webhooks update the stored lists idempotently. The App must subscribe to
  the Repository event (documented in docs/github-app-setup.md).
- Legacy OAuth lists change only on refresh.
- Picker header shows "Updated 3 min ago" and a refresh button.
- dev-mock: stored list, simulated refresh and webhook endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-29 08:06:30 +00:00
1 parent 0640d741f1
commit c73e992b7c
22 files changed
+1026 -153

No files matched your search

+3
View File
@@ -6,6 +6,7 @@ import AnonymousError from "./AnonymousError";
import CredentialModel from "./model/credentials/credentials.model";
import InstallationModel from "./model/github-installation";
import UserModel from "./model/users/users.model";
import { UserRepositorySyncModel } from "./model/user-repositories";
import { credentialCipher, getCredentialToken } from "./credentials";
import { RepositoryAccess } from "./repository-access.types";
@@ -84,6 +85,8 @@ export async function saveAppGrant(ownerId: string, data: AppTokenResponse) {
$set: tokenFields(ownerId, data), $unset: { refreshLock: "", refreshLockUntil: "" },
}, { upsert: true, runValidators: true });
await UserModel.updateOne({ _id: ownerId }, { $set: { repositories: [] } });
// A new grant may see other installations: refresh the stored picker list.
await UserRepositorySyncModel.updateOne({ ownerId, connection: "github-app" }, { $set: { needsSyncAt: new Date() } });
}
export async function appUserToken(ownerId: string): Promise<string> {