fix(cache): correct revision

This commit is contained in:
Rhys Arkins 2021-02-22 19:39:33 +01:00
parent 9171e712d4
commit 728082b3c3
3 changed files with 13 additions and 9 deletions

View file

@ -34,7 +34,7 @@ describe('lib/util/cache/repository', () => {
});
expect(repositoryCache.getCache()).toEqual({
repository: 'abc/def',
scan: {},
revision: repositoryCache.CACHE_REVISION,
});
});
it('reads from cache and finalizes', async () => {
@ -50,6 +50,6 @@ describe('lib/util/cache/repository', () => {
expect(fs.outputFile.mock.calls).toHaveLength(1);
});
it('gets', () => {
expect(repositoryCache.getCache()).toEqual({ scan: {} });
expect(repositoryCache.getCache()).toEqual({});
});
});

View file

@ -73,6 +73,13 @@ function validate(config: RenovateConfig, input: any): Cache | null {
return null;
}
function createCache(repository?: string): Cache {
const res: Cache = Object.create({});
res.repository = repository;
res.revision = CACHE_REVISION;
return res;
}
export async function initialize(config: RenovateConfig): Promise<void> {
cache = null;
try {
@ -87,15 +94,11 @@ export async function initialize(config: RenovateConfig): Promise<void> {
} catch (err) {
logger.debug({ cacheFileName }, 'Repository cache not found');
}
cache = cache || Object.create({ revision: CACHE_REVISION });
cache.repository = config.repository;
cache ||= createCache(config.repository);
}
export function getCache(): Cache {
cache = cache || Object.create({ revision: CACHE_REVISION });
delete cache.init;
cache.scan = cache.scan || Object.create({});
return cache;
return cache || createCache();
}
export async function finalize(): Promise<void> {

View file

@ -55,7 +55,8 @@ export async function extract(
const baseBranchSha = getBranchCommit(baseBranch);
let packageFiles: Record<string, PackageFile[]>;
const cache = getCache();
const cachedExtract = cache?.scan?.[baseBranch];
cache.scan ||= {};
const cachedExtract = cache.scan[baseBranch];
const configHash = hasha(JSON.stringify(config));
// istanbul ignore if
if (