mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
171a591d84
* feat(git): validate length commit shas * test: adapt test mocks * chore: update import paths * feat(git): make the validation more strict and support repositories using sha256 * test: add fakeSha function for deterministic git commit shas in tests
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { isNonEmptyObject } from '@sindresorhus/is';
|
|
import { logger } from '../../logger/index.ts';
|
|
import { getCache } from '../cache/repository/index.ts';
|
|
import type { LongCommitSha } from '../schema-utils/git.ts';
|
|
|
|
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 (
|
|
isNonEmptyObject(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;
|
|
}
|