Skip to content

Commit

Permalink
feat(maven): Lookup for additional info for latest stable versi… (#4970)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored and rarkins committed Dec 11, 2019
1 parent 898a3bb commit 75943de
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions lib/datasource/maven/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs-extra';
import { XmlDocument } from 'xmldoc';
import { logger } from '../../logger';
import { compare } from '../../versioning/maven/compare';
import mavenVersion from '../../versioning/maven';
import { containsPlaceholder } from '../../manager/maven/extract';
import { downloadHttpProtocol } from './util';
import { PkgReleaseConfig, ReleaseResult } from '../common';
Expand Down Expand Up @@ -91,11 +92,14 @@ async function getDependencyInfo(
return result;
}

function getLatestVersion(versions: string[]): string | null {
if (versions.length === 0) return null;
return versions.reduce((latestVersion, version) =>
compare(version, latestVersion) === 1 ? version : latestVersion
);
function getLatestStableVersion(versions: string[]): string | null {
const stableVersions = versions.filter(mavenVersion.isStable);
if (stableVersions.length) {
return stableVersions.reduce((latestVersion, version) =>
compare(version, latestVersion) === 1 ? version : latestVersion
);
}
return null;
}

interface MavenDependency {
Expand Down Expand Up @@ -154,7 +158,7 @@ export async function getPkgReleases({
const newVersions = extractVersions(mavenMetadata).filter(
version => !versions.includes(version)
);
const latestVersion = getLatestVersion(newVersions);
const latestVersion = getLatestStableVersion(newVersions);
if (latestVersion) {
repoForVersions[latestVersion] = repoUrl;
}
Expand All @@ -168,13 +172,17 @@ export async function getPkgReleases({
return null;
}
logger.debug(`Found ${versions.length} versions for ${dependency.display}`);
const latestVersion = getLatestVersion(versions);
const repoUrl = repoForVersions[latestVersion];
const dependencyInfo = await getDependencyInfo(
dependency,
repoUrl,
latestVersion
);

let dependencyInfo = {};
const latestVersion = getLatestStableVersion(versions);
if (latestVersion) {
const repoUrl = repoForVersions[latestVersion];
dependencyInfo = await getDependencyInfo(
dependency,
repoUrl,
latestVersion
);
}

return {
...dependency,
Expand Down

0 comments on commit 75943de

Please sign in to comment.