Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(maven): Fetch latest when all releases are unstable #12647

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/datasource/maven/index.ts
Expand Up @@ -28,13 +28,17 @@ function isStableVersion(x: string): boolean {
return mavenVersion.isStable(x);
}

function getLatestStableVersion(releases: Release[]): string | undefined {
return releases
.map(({ version }) => version)
.filter(isStableVersion)
.reduce((latestVersion, version) =>
compare(version, latestVersion) === 1 ? version : latestVersion
);
function getLatestSuitableVersion(releases: Release[]): string | null {
// istanbul ignore if
if (!releases?.length) {
return null;
}
const allVersions = releases.map(({ version }) => version);
const stableVersions = allVersions.filter(isStableVersion);
const versions = stableVersions.length ? stableVersions : allVersions;
return versions.reduce((latestVersion, version) =>
compare(version, latestVersion) === 1 ? version : latestVersion
);
}

function extractVersions(metadata: XmlDocument): string[] {
Expand Down Expand Up @@ -261,10 +265,10 @@ export async function getReleases({
`Found ${releases.length} new releases for ${dependency.display} in repository ${repoUrl}`
);

const latestStableVersion = getLatestStableVersion(releases);
const latestSuitableVersion = getLatestSuitableVersion(releases);
const dependencyInfo =
latestStableVersion &&
(await getDependencyInfo(dependency, repoUrl, latestStableVersion));
latestSuitableVersion &&
(await getDependencyInfo(dependency, repoUrl, latestSuitableVersion));

return { ...dependency, ...dependencyInfo, releases };
}