mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 10:33:39 +00:00
ff6761ed23
* fix(config/global): return default values for `GlobalConfig.get` As noted in #39949, it can be awkward working with in `GlobalConfig.get`, where we would previously need to specify the default value when calling `.get`, which could lead to drift with the defaults for a given config option. To reduce this risk, we can rely on a given `default` for a configuration option, providing that as a default. Because this now definitely returns a value that matches the config option, it now allows us to remove `!` assertions. * fixup! fix(config/global): return default values for `GlobalConfig.get` Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * fixup! fix(config/global): return default values for `GlobalConfig.get` * test(presets): remove impossible test As it's now not possible to set a value as `undefined` (as `GlobalConfig` will then use the default), this test no longer validates anything. * test(workers/repository): add mock Now `platform` defaults to `github`, we need to mock out the call to fetch config. Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io> * test: coverage * test: coverage --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { DateTime } from 'luxon';
|
|
import { GlobalConfig } from '../../../config/global.ts';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { HttpCache } from '../../http/cache/schema.ts';
|
|
import type { RepoCacheData } from './types.ts';
|
|
|
|
export function cleanupHttpCache(cacheData: RepoCacheData): void {
|
|
const { httpCache } = cacheData;
|
|
if (!httpCache) {
|
|
logger.trace('cleanupHttpCache: no http cache to clean up');
|
|
return;
|
|
}
|
|
|
|
const ttlDays = GlobalConfig.get('httpCacheTtlDays');
|
|
if (ttlDays === 0) {
|
|
logger.trace('cleanupHttpCache: zero value received, removing the cache');
|
|
delete cacheData.httpCache;
|
|
return;
|
|
}
|
|
|
|
const now = DateTime.now();
|
|
for (const [url, item] of Object.entries(httpCache)) {
|
|
const parsed = HttpCache.safeParse(item);
|
|
// v8 ignore else -- TODO: add test #40625
|
|
if (parsed.success && parsed.data) {
|
|
const item = parsed.data;
|
|
const expiry = DateTime.fromISO(item.timestamp).plus({ days: ttlDays });
|
|
if (expiry < now) {
|
|
logger.debug(`http cache: removing expired cache for ${url}`);
|
|
delete httpCache[url];
|
|
}
|
|
}
|
|
}
|
|
}
|