From ee582fe0e7c06e8c2a1d056cb280e8558dab30d8 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Thu, 14 Apr 2022 10:37:07 +0300 Subject: [PATCH] refactor(maven): Use explicit cacheability flag for datasource (#15110) --- lib/modules/datasource/maven/index.ts | 4 ++-- lib/modules/datasource/maven/types.ts | 2 +- lib/modules/datasource/maven/util.ts | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/modules/datasource/maven/index.ts b/lib/modules/datasource/maven/index.ts index 2a6d1bca4b..70b1da5881 100644 --- a/lib/modules/datasource/maven/index.ts +++ b/lib/modules/datasource/maven/index.ts @@ -112,7 +112,7 @@ export class MavenDatasource extends Datasource { return cachedVersions; } - const { authorization, xml: mavenMetadata } = await downloadMavenXml( + const { isCacheable, xml: mavenMetadata } = await downloadMavenXml( this.http, metadataUrl ); @@ -125,7 +125,7 @@ export class MavenDatasource extends Datasource { (acc, version) => ({ ...acc, [version]: null }), {} ); - if (!authorization) { + if (isCacheable) { await packageCache.set(cacheNamespace, cacheKey, releaseMap, 30); } return releaseMap; diff --git a/lib/modules/datasource/maven/types.ts b/lib/modules/datasource/maven/types.ts index c66c311f16..1a24f174d3 100644 --- a/lib/modules/datasource/maven/types.ts +++ b/lib/modules/datasource/maven/types.ts @@ -9,7 +9,7 @@ export interface MavenDependency { } export interface MavenXml { - authorization?: boolean; + isCacheable?: boolean; xml?: XmlDocument; } diff --git a/lib/modules/datasource/maven/util.ts b/lib/modules/datasource/maven/util.ts index 31dd6042de..4ce30dc51b 100644 --- a/lib/modules/datasource/maven/util.ts +++ b/lib/modules/datasource/maven/util.ts @@ -150,6 +150,9 @@ export async function downloadMavenXml( if (!pkgUrl) { return {}; } + + let isCacheable = false; + let rawContent: string | undefined; let authorization: boolean | undefined; let statusCode: number | undefined; @@ -178,7 +181,11 @@ export async function downloadMavenXml( return {}; } - return { authorization, xml: new XmlDocument(rawContent) }; + if (!authorization) { + isCacheable = true; + } + + return { isCacheable, xml: new XmlDocument(rawContent) }; } export function getDependencyParts(packageName: string): MavenDependency { -- GitLab