Skip to content
Snippets Groups Projects
Unverified Commit a0d8d2be authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor: Simplify lambda function in lookup result filtering (#30018)

parent c13315e4
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,18 @@ import * as poetryVersioning from '../../../../modules/versioning/poetry'; ...@@ -9,6 +9,18 @@ import * as poetryVersioning from '../../../../modules/versioning/poetry';
import { getRegexPredicate } from '../../../../util/string-match'; import { getRegexPredicate } from '../../../../util/string-match';
import type { FilterConfig } from './types'; import type { FilterConfig } from './types';
function isReleaseStable(release: Release, versioning: VersioningApi): boolean {
if (!versioning.isStable(release.version)) {
return false;
}
if (release.isStable === false) {
return false;
}
return true;
}
export function filterVersions( export function filterVersions(
config: FilterConfig, config: FilterConfig,
currentVersion: string, currentVersion: string,
...@@ -18,17 +30,7 @@ export function filterVersions( ...@@ -18,17 +30,7 @@ export function filterVersions(
): Release[] { ): Release[] {
const { ignoreUnstable, ignoreDeprecated, respectLatest, allowedVersions } = const { ignoreUnstable, ignoreDeprecated, respectLatest, allowedVersions } =
config; config;
function isVersionStable(version: string): boolean {
if (!versioning.isStable(version)) {
return false;
}
// Check if the datasource returned isStable = false
const release = releases.find((r) => r.version === version);
if (release?.isStable === false) {
return false;
}
return true;
}
// istanbul ignore if: shouldn't happen // istanbul ignore if: shouldn't happen
if (!currentVersion) { if (!currentVersion) {
return []; return [];
...@@ -125,18 +127,19 @@ export function filterVersions( ...@@ -125,18 +127,19 @@ export function filterVersions(
return filteredVersions; return filteredVersions;
} }
if (isVersionStable(currentVersion)) { const currentRelease = releases.find((r) => r.version === currentVersion);
return filteredVersions.filter((v) => isVersionStable(v.version)); if (currentRelease && isReleaseStable(currentRelease, versioning)) {
return filteredVersions.filter((r) => isReleaseStable(r, versioning));
} }
// if current is unstable then allow unstable in the current major only // if current is unstable then allow unstable in the current major only
// Allow unstable only in current major // Allow unstable only in current major
return filteredVersions.filter((v) => { return filteredVersions.filter((r) => {
if (isVersionStable(v.version)) { if (isReleaseStable(r, versioning)) {
return true; return true;
} }
if ( if (
versioning.getMajor(v.version) !== versioning.getMajor(currentVersion) versioning.getMajor(r.version) !== versioning.getMajor(currentVersion)
) { ) {
return false; return false;
} }
...@@ -145,8 +148,8 @@ export function filterVersions( ...@@ -145,8 +148,8 @@ export function filterVersions(
return true; return true;
} }
return ( return (
versioning.getMinor(v.version) === versioning.getMinor(currentVersion) && versioning.getMinor(r.version) === versioning.getMinor(currentVersion) &&
versioning.getPatch(v.version) === versioning.getPatch(currentVersion) versioning.getPatch(r.version) === versioning.getPatch(currentVersion)
); );
}); });
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment