Skip to content

Commit

Permalink
refactor(maven): Exit early for HTML-based metadata extraction (#27752)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Mar 6, 2024
1 parent 14272f0 commit d64dc70
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions lib/modules/datasource/maven/index.ts
Expand Up @@ -114,6 +114,10 @@ export class MavenDatasource extends Datasource {
dependency: MavenDependency,
repoUrl: string,
): Promise<ReleaseMap> {
if (!repoUrl.startsWith(MAVEN_REPO)) {
return inputReleaseMap;
}

const cacheNs = 'datasource-maven:index-html-releases';
const cacheKey = `${repoUrl}${dependency.dependencyUrl}`;
let workingReleaseMap = await packageCache.get<ReleaseMap>(
Expand All @@ -124,27 +128,21 @@ export class MavenDatasource extends Datasource {
workingReleaseMap = {};
let retryEarlier = false;
try {
if (repoUrl.startsWith(MAVEN_REPO)) {
const indexUrl = getMavenUrl(dependency, repoUrl, 'index.html');
const res = await downloadHttpProtocol(this.http, indexUrl);
const { body = '' } = res;
for (const line of body.split(newlineRegex)) {
const match = line.trim().match(mavenCentralHtmlVersionRegex);
if (match) {
const { version, releaseTimestamp: timestamp } =
match?.groups ?? /* istanbul ignore next: hard to test */ {};
if (version && timestamp) {
const date = DateTime.fromFormat(
timestamp,
'yyyy-MM-dd HH:mm',
{
zone: 'UTC',
},
);
if (date.isValid) {
const releaseTimestamp = date.toISO();
workingReleaseMap[version] = { version, releaseTimestamp };
}
const indexUrl = getMavenUrl(dependency, repoUrl, 'index.html');
const res = await downloadHttpProtocol(this.http, indexUrl);
const { body = '' } = res;
for (const line of body.split(newlineRegex)) {
const match = line.trim().match(mavenCentralHtmlVersionRegex);
if (match) {
const { version, releaseTimestamp: timestamp } =
match?.groups ?? /* istanbul ignore next: hard to test */ {};
if (version && timestamp) {
const date = DateTime.fromFormat(timestamp, 'yyyy-MM-dd HH:mm', {
zone: 'UTC',
});
if (date.isValid) {
const releaseTimestamp = date.toISO();
workingReleaseMap[version] = { version, releaseTimestamp };
}
}
}
Expand Down

0 comments on commit d64dc70

Please sign in to comment.