Skip to content

Commit

Permalink
fix(cache): improve repository cache robustness (#6689)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jul 7, 2020
1 parent e015875 commit 4459b11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/util/cache/repository/index.spec.ts
Expand Up @@ -45,6 +45,6 @@ describe('lib/util/cache/repository', () => {
expect(fs.outputFile.mock.calls).toHaveLength(1);
});
it('gets', () => {
expect(repositoryCache.getCache()).toEqual({ repository: 'abc/def' });
expect(repositoryCache.getCache()).toEqual({});
});
});
8 changes: 6 additions & 2 deletions lib/util/cache/repository/index.ts
Expand Up @@ -56,15 +56,19 @@ export async function initialize(config: RenovateConfig): Promise<void> {
} catch (err) {
logger.debug({ cacheFileName }, 'Repository cache not found');
}
cache = cache || { repository: config.repository };
cache = cache || Object.create({});
cache.repository = config.repository;
}

export function getCache(): Cache {
cache = cache || Object.create({});
return cache;
}

export async function finalize(): Promise<void> {
if (repositoryCache !== 'disabled') {
if (cacheFileName && cache && repositoryCache !== 'disabled') {
await fs.outputFile(cacheFileName, JSON.stringify(cache));
}
cacheFileName = null;
cache = Object.create({});
}

0 comments on commit 4459b11

Please sign in to comment.