Fix filtering deprecated charts (#3635)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-08-24 08:29:36 -04:00
1 parent 54ac311933
commit 5f89b3e31f
10 files changed
+324 -284

No files matched your search

+33 -1
View File
@@ -19,7 +19,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import semver, { SemVer } from "semver";
import semver, { coerce, SemVer } from "semver";
import * as iter from "./iter";
import type { RawHelmChart } from "../k8s-api/endpoints/helm-charts.api";
import logger from "../logger";
export function sortCompare<T>(left: T, right: T): -1 | 0 | 1 {
if (left < right) {
@@ -53,3 +56,32 @@ export function sortCompareChartVersions(left: ChartVersion, right: ChartVersion
return sortCompare(left.version, right.version);
}
export function sortCharts(charts: RawHelmChart[]) {
interface ExtendedHelmChart extends RawHelmChart {
__version: SemVer;
}
const chartsWithVersion = Array.from(
iter.map(
charts,
(chart => {
const __version = coerce(chart.version, { includePrerelease: true, loose: true });
if (!__version) {
logger.warn(`[HELM-SERVICE]: Version from helm chart is not loosely coercable to semver.`, { name: chart.name, version: chart.version, repo: chart.repo });
}
(chart as ExtendedHelmChart).__version = __version;
return chart as ExtendedHelmChart;
})
),
);
return chartsWithVersion
.sort(sortCompareChartVersions)
.map(chart => (delete chart.__version, chart));
}