0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/git/behind-base-branch-cache.ts
Tom Vervoort c82b9afb36
refactor: strongly type commit SHAs (#25207)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2023-11-22 06:30:19 +00:00

45 lines
1.0 KiB
TypeScript

import { logger } from '../../logger';
import { getCache } from '../cache/repository';
import type { LongCommitSha } from './types';
export function getCachedBehindBaseResult(
branchName: string,
branchSha: LongCommitSha | null,
baseBranch: string,
baseBranchSha: LongCommitSha | null,
): boolean | null {
const cache = getCache();
const branch = cache.branches?.find(
(branch) => branch.branchName === branchName,
);
if (
branch &&
branch.sha === branchSha &&
branch.baseBranch === baseBranch &&
branch.baseBranchSha === baseBranchSha &&
branch.isBehindBase !== undefined
) {
return branch.isBehindBase;
}
return null;
}
export function setCachedBehindBaseResult(
branchName: string,
isBehindBase: boolean,
): void {
const cache = getCache();
const branch = cache.branches?.find(
(branch) => branch.branchName === branchName,
);
if (!branch) {
logger.debug(`setCachedBehindBaseResult(): Branch cache not present`);
return;
}
branch.isBehindBase = isBehindBase;
}