Files

25 lines
1.0 KiB
TypeScript

/**
* Pure, deterministic dedup key for maintenance threads.
*
* Derives a stable key from the merge-base + head SHAs so that repeated
* scheduled sync runs against the same upstream state collapse onto a single
* maintenance thread instead of creating a new one each run. NEVER involves
* Date.now()/random — the key must be identical for identical inputs.
*
* Returns `null` when the head SHA is missing/empty (unresolvable head → the
* caller cannot dedup and should SKIP thread creation rather than mint a
* unique key).
*/
export const maintenanceDedupKey = (input: {
mergeBaseSha?: string;
headSha?: string;
}): string | null => {
const head = input.headSha?.trim();
if (!head) return null;
// Intentional `||`: an empty/whitespace merge base must collapse to the
// 'nobase' sentinel, which `??` would not do (it keeps the empty string).
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const base = input.mergeBaseSha?.trim() || 'nobase';
return `${base}:${head}`;
};