From 7c4609e4189e7de8403ef28a40b824f58f58df66 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:24:23 +0300 Subject: [PATCH] refactor(poetry): More artifacts refactoring (#24095) --- lib/modules/manager/poetry/artifacts.ts | 28 ++++++++++--------------- lib/modules/manager/poetry/types.ts | 8 ------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts index 8f1a225c8b..8755936e3c 100644 --- a/lib/modules/manager/poetry/artifacts.ts +++ b/lib/modules/manager/poetry/artifacts.ts @@ -20,20 +20,15 @@ import { PypiDatasource } from '../../datasource/pypi'; import { dependencyPattern } from '../pip_requirements/extract'; import type { UpdateArtifact, UpdateArtifactsResult } from '../types'; import { Lockfile } from './schema'; -import type { PoetryFile, PoetryLock, PoetrySource } from './types'; +import type { PoetryFile, PoetrySource } from './types'; export function getPythonConstraint( existingLockFileContent: string -): string | undefined | null { - try { - const data = parse(existingLockFileContent) as PoetryLock; - if (is.string(data?.metadata?.['python-versions'])) { - return data?.metadata?.['python-versions']; - } - } catch (err) { - // Do nothing - } - return undefined; +): string | null { + return Result.parse( + existingLockFileContent, + Lockfile.transform(({ pythonVersions }) => pythonVersions) + ).unwrapOrNull(); } const pkgValRegex = regEx(`^${dependencyPattern}$`); @@ -112,11 +107,9 @@ function getPoetrySources(content: string, fileName: string): PoetrySource[] { return sourceArray; } -function getMatchingHostRule(source: PoetrySource): HostRule { - const scopedMatch = find({ hostType: PypiDatasource.id, url: source.url }); - return is.nonEmptyObject(scopedMatch) - ? scopedMatch - : find({ url: source.url }); +function getMatchingHostRule(url: string | undefined): HostRule { + const scopedMatch = find({ hostType: PypiDatasource.id, url }); + return is.nonEmptyObject(scopedMatch) ? scopedMatch : find({ url }); } function getSourceCredentialVars( @@ -127,7 +120,7 @@ function getSourceCredentialVars( const envVars: Record<string, string> = {}; for (const source of poetrySources) { - const matchingHostRule = getMatchingHostRule(source); + const matchingHostRule = getMatchingHostRule(source.url); const formattedSourceName = source.name .replace(regEx(/(\.|-)+/g), '_') .toUpperCase(); @@ -142,6 +135,7 @@ function getSourceCredentialVars( } return envVars; } + export async function updateArtifacts({ packageFileName, updatedDeps, diff --git a/lib/modules/manager/poetry/types.ts b/lib/modules/manager/poetry/types.ts index 0c2eaa7925..d88e278b78 100644 --- a/lib/modules/manager/poetry/types.ts +++ b/lib/modules/manager/poetry/types.ts @@ -37,11 +37,3 @@ export interface PoetryLockSection { name?: string; version?: string; } - -export interface PoetryLock { - metadata?: { - 'lock-version'?: string; - 'python-versions'?: string; - }; - package?: PoetryLockSection[]; -} -- GitLab