Files
paseo/packages/server/src/services/pull-request-contains-commit.ts
T
Mohamed Boudra fedb40d112 fix(server): require membership in the pull request own commits
Exclude inherited base commits using forge commit lists. Carry membership evidence in the server snapshot so auto-archive uses the same rule without Git subprocesses or network fetches. Preserve GitHub batching and cache terminal commit reads.
2026-11-17 04:39:03 +01:00

22 lines
975 B
TypeScript

/** Only commits introduced by the request establish workspace ownership. */
export function pullRequestContainsCommit(input: {
workspaceCommit?: string;
pullRequestCommits?: readonly string[];
}): boolean {
return !!input.workspaceCommit && !!input.pullRequestCommits?.includes(input.workspaceCommit);
}
/** Cache immutable terminal-request commit lists, including failed reads, across polls. */
export function createPullRequestCommitReader(now: () => number = Date.now) {
const cache = new Map<string, { expiresAt: number; commits: Promise<string[]> }>();
return (key: string, load: () => Promise<string[]>): Promise<string[]> => {
const existing = cache.get(key);
if (existing && existing.expiresAt > now()) return existing.commits;
const entry = { expiresAt: now() + 300_000, commits: load() };
cache.delete(key);
cache.set(key, entry);
if (cache.size > 1024) cache.delete(cache.keys().next().value!);
return entry.commits;
};
}