From 61e0ef24dfae0b6e42de585261f1867fe8e6dfec Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Sun, 17 Nov 2024 12:21:51 -0800 Subject: [PATCH 1/8] feat(poetry): support GCloud credentials for Google Artifact Registry when locking --- .../poetry/__fixtures__/pyproject.10.toml | 4 + lib/modules/manager/poetry/artifacts.spec.ts | 92 ++++++++++++++++++- lib/modules/manager/poetry/artifacts.ts | 41 +++++++-- 3 files changed, 126 insertions(+), 11 deletions(-) diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml index 65c5e06ba8..85fdee6e4e 100644 --- a/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml +++ b/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml @@ -16,6 +16,10 @@ url = "last.url" [[tool.poetry.source]] name = "five" +[[tool.poetry.source]] +name = "some-gar-repo" +url = "https://someregion-python.pkg.dev/some-project/some-repo/simple/" + [build-system] requires = ["poetry_core>=1.0", "wheel"] build-backend = "poetry.masonry.api" diff --git a/lib/modules/manager/poetry/artifacts.spec.ts b/lib/modules/manager/poetry/artifacts.spec.ts index 0ea60e8bb8..c7b659fdc2 100644 --- a/lib/modules/manager/poetry/artifacts.spec.ts +++ b/lib/modules/manager/poetry/artifacts.spec.ts @@ -1,4 +1,5 @@ import { codeBlock } from 'common-tags'; +import { GoogleAuth as _googleAuth } from 'google-auth-library'; import { mockDeep } from 'jest-mock-extended'; import { join } from 'upath'; import { envMock, mockExecAll } from '../../../../test/exec-util'; @@ -20,11 +21,13 @@ jest.mock('../../../util/exec/env'); jest.mock('../../../util/fs'); jest.mock('../../datasource', () => mockDeep()); jest.mock('../../../util/host-rules', () => mockDeep()); +jest.mock('google-auth-library'); process.env.CONTAINERBASE = 'true'; const datasource = mocked(_datasource); const hostRules = mocked(_hostRules); +const googleAuth = mocked(_googleAuth); const adminConfig: RepoGlobalConfig = { localDir: join('/tmp/github/some/repo'), @@ -181,6 +184,11 @@ describe('modules/manager/poetry/artifacts', () => { hostRules.find.mockReturnValueOnce({ username: 'usernameTwo' }); hostRules.find.mockReturnValueOnce({}); hostRules.find.mockReturnValueOnce({ password: 'passwordFour' }); + googleAuth.mockImplementationOnce( + jest.fn().mockImplementationOnce(() => ({ + getAccessToken: jest.fn().mockResolvedValue('some-token'), + })), + ); const updatedDeps = [{ depName: 'dep1' }]; expect( await updateArtifacts({ @@ -198,9 +206,89 @@ describe('modules/manager/poetry/artifacts', () => { }, }, ]); - expect(hostRules.find.mock.calls).toHaveLength(5); + expect(hostRules.find.mock.calls).toHaveLength(7); expect(execSnapshots).toMatchObject([ - { cmd: 'poetry update --lock --no-interaction dep1' }, + { + cmd: 'poetry update --lock --no-interaction dep1', + options: { + env: { + HOME: '/home/user', + HTTPS_PROXY: 'https://example.com', + HTTP_PROXY: 'http://example.com', + LANG: 'en_US.UTF-8', + LC_ALL: 'en_US', + NO_PROXY: 'localhost', + PATH: '/tmp/path', + POETRY_HTTP_BASIC_FOUR_OH_FOUR_PASSWORD: 'passwordFour', + POETRY_HTTP_BASIC_ONE_PASSWORD: 'passwordOne', + POETRY_HTTP_BASIC_ONE_USERNAME: 'usernameOne', + POETRY_HTTP_BASIC_TWO_USERNAME: 'usernameTwo', + POETRY_HTTP_BASIC_SOME_GAR_REPO_USERNAME: 'oauth2accesstoken', + POETRY_HTTP_BASIC_SOME_GAR_REPO_PASSWORD: 'some-token', + }, + }, + }, + ]); + }); + + it('continues if Google auth is not configured', async () => { + // poetry.lock + fs.getSiblingFileName.mockReturnValueOnce('poetry.lock'); + fs.readLocalFile.mockResolvedValueOnce(null); + // pyproject.lock + fs.getSiblingFileName.mockReturnValueOnce('pyproject.lock'); + fs.readLocalFile.mockResolvedValueOnce('[metadata]\n'); + const execSnapshots = mockExecAll(); + fs.readLocalFile.mockResolvedValueOnce('New poetry.lock'); + hostRules.find.mockReturnValueOnce({ + username: 'usernameOne', + password: 'passwordOne', + }); + hostRules.find.mockReturnValueOnce({ username: 'usernameTwo' }); + hostRules.find.mockReturnValueOnce({}); + hostRules.find.mockReturnValueOnce({ password: 'passwordFour' }); + googleAuth.mockImplementation( + jest.fn().mockImplementation(() => ({ + getAccessToken: jest.fn().mockResolvedValue(undefined), + })), + ); + const updatedDeps = [{ depName: 'dep1' }]; + expect( + await updateArtifacts({ + packageFileName: 'pyproject.toml', + updatedDeps, + newPackageFileContent: pyproject10toml, + config, + }), + ).toEqual([ + { + file: { + type: 'addition', + path: 'pyproject.lock', + contents: 'New poetry.lock', + }, + }, + ]); + expect(hostRules.find.mock.calls).toHaveLength(7); + expect(execSnapshots).toMatchObject([ + { + cmd: 'poetry update --lock --no-interaction dep1', + options: { + env: { + HOME: '/home/user', + HTTPS_PROXY: 'https://example.com', + HTTP_PROXY: 'http://example.com', + LANG: 'en_US.UTF-8', + LC_ALL: 'en_US', + NO_PROXY: 'localhost', + PATH: '/tmp/path', + POETRY_HTTP_BASIC_FOUR_OH_FOUR_PASSWORD: 'passwordFour', + POETRY_HTTP_BASIC_ONE_PASSWORD: 'passwordOne', + POETRY_HTTP_BASIC_ONE_USERNAME: 'usernameOne', + POETRY_HTTP_BASIC_TWO_USERNAME: 'usernameTwo', + }, + }, + }, ]); }); diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts index d5582f619c..98da1df7d3 100644 --- a/lib/modules/manager/poetry/artifacts.ts +++ b/lib/modules/manager/poetry/artifacts.ts @@ -17,7 +17,9 @@ import { find } from '../../../util/host-rules'; import { regEx } from '../../../util/regex'; import { Result } from '../../../util/result'; import { parse as parseToml } from '../../../util/toml'; +import { parseUrl } from '../../../util/url'; import { PypiDatasource } from '../../datasource/pypi'; +import { getGoogleAuthTokenRaw } from '../../datasource/util'; import type { UpdateArtifact, UpdateArtifactsResult } from '../types'; import { Lockfile, PoetrySchemaToml } from './schema'; import type { PoetryFile, PoetrySource } from './types'; @@ -92,7 +94,7 @@ export function getPoetryRequirement( return null; } -function getPoetrySources(content: string, fileName: string): PoetrySource[] { +function getPoetrySources(content: string): PoetrySource[] { let pyprojectFile: PoetryFile; try { pyprojectFile = parseToml(content) as PoetryFile; @@ -115,20 +117,41 @@ function getPoetrySources(content: string, fileName: string): PoetrySource[] { return sourceArray; } -function getMatchingHostRule(url: string | undefined): HostRule { +async function getMatchingHostRule(url: string | undefined): Promise { const scopedMatch = find({ hostType: PypiDatasource.id, url }); - return is.nonEmptyObject(scopedMatch) ? scopedMatch : find({ url }); + const hostRule = is.nonEmptyObject(scopedMatch) ? scopedMatch : find({ url }); + if (hostRule) { + return hostRule; + } + + const parsedUrl = parseUrl(url); + if (!parsedUrl) { + logger.once.debug({ url }, 'Failed to parse URL'); + return {}; + } + + if (parsedUrl.hostname.endsWith('.pkg.dev')) { + const accessToken = await getGoogleAuthTokenRaw(); + if (accessToken) { + return { + username: 'oauth2accesstoken', + password: accessToken, + }; + } + logger.once.debug({ url }, 'Could not get Google access token'); + } + + return {}; } -function getSourceCredentialVars( +async function getSourceCredentialVars( pyprojectContent: string, - packageFileName: string, -): NodeJS.ProcessEnv { - const poetrySources = getPoetrySources(pyprojectContent, packageFileName); +): Promise { + const poetrySources = getPoetrySources(pyprojectContent); const envVars: NodeJS.ProcessEnv = {}; for (const source of poetrySources) { - const matchingHostRule = getMatchingHostRule(source.url); + const matchingHostRule = await getMatchingHostRule(source.url); const formattedSourceName = source.name .replace(regEx(/(\.|-)+/g), '_') .toUpperCase(); @@ -192,7 +215,7 @@ export async function updateArtifacts({ config.constraints?.poetry ?? getPoetryRequirement(newPackageFileContent, existingLockFileContent); const extraEnv = { - ...getSourceCredentialVars(newPackageFileContent, packageFileName), + ...(await getSourceCredentialVars(newPackageFileContent)), ...getGitEnvironmentVariables(['poetry']), PIP_CACHE_DIR: await ensureCacheDir('pip'), }; From 96630e2e8eb490c9bd4beda1267369f80d842118 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Sun, 17 Nov 2024 14:30:22 -0800 Subject: [PATCH 2/8] Add an invalid URL to fixtures --- lib/modules/manager/poetry/__fixtures__/pyproject.10.toml | 4 ++++ lib/modules/manager/poetry/artifacts.spec.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml index 85fdee6e4e..35ab18afaa 100644 --- a/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml +++ b/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml @@ -20,6 +20,10 @@ name = "five" name = "some-gar-repo" url = "https://someregion-python.pkg.dev/some-project/some-repo/simple/" +[[tool.poetry.source]] +name = "invalid-url" +url = "invalid-url" + [build-system] requires = ["poetry_core>=1.0", "wheel"] build-backend = "poetry.masonry.api" diff --git a/lib/modules/manager/poetry/artifacts.spec.ts b/lib/modules/manager/poetry/artifacts.spec.ts index c7b659fdc2..dda071ca27 100644 --- a/lib/modules/manager/poetry/artifacts.spec.ts +++ b/lib/modules/manager/poetry/artifacts.spec.ts @@ -206,7 +206,7 @@ describe('modules/manager/poetry/artifacts', () => { }, }, ]); - expect(hostRules.find.mock.calls).toHaveLength(7); + expect(hostRules.find.mock.calls).toHaveLength(9); expect(execSnapshots).toMatchObject([ { cmd: 'poetry update --lock --no-interaction dep1', @@ -269,7 +269,7 @@ describe('modules/manager/poetry/artifacts', () => { }, }, ]); - expect(hostRules.find.mock.calls).toHaveLength(7); + expect(hostRules.find.mock.calls).toHaveLength(9); expect(execSnapshots).toMatchObject([ { cmd: 'poetry update --lock --no-interaction dep1', From 9410925e6396d4e2cf9366124abad17b36a8b7c9 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Tue, 19 Nov 2024 16:13:18 -0800 Subject: [PATCH 3/8] Separate fixture for GAR --- .../poetry/__fixtures__/pyproject.10.toml | 4 - .../poetry/__fixtures__/pyproject.13.toml | 7 ++ lib/modules/manager/poetry/artifacts.spec.ts | 90 ++++++++++--------- 3 files changed, 56 insertions(+), 45 deletions(-) create mode 100644 lib/modules/manager/poetry/__fixtures__/pyproject.13.toml diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml index 35ab18afaa..44e0eb41e2 100644 --- a/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml +++ b/lib/modules/manager/poetry/__fixtures__/pyproject.10.toml @@ -16,10 +16,6 @@ url = "last.url" [[tool.poetry.source]] name = "five" -[[tool.poetry.source]] -name = "some-gar-repo" -url = "https://someregion-python.pkg.dev/some-project/some-repo/simple/" - [[tool.poetry.source]] name = "invalid-url" url = "invalid-url" diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.13.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.13.toml new file mode 100644 index 0000000000..855b945199 --- /dev/null +++ b/lib/modules/manager/poetry/__fixtures__/pyproject.13.toml @@ -0,0 +1,7 @@ +[[tool.poetry.source]] +name = "some-gar-repo" +url = "https://someregion-python.pkg.dev/some-project/some-repo/simple/" + +[build-system] +requires = ["poetry_core>=1.0", "wheel"] +build-backend = "poetry.masonry.api" diff --git a/lib/modules/manager/poetry/artifacts.spec.ts b/lib/modules/manager/poetry/artifacts.spec.ts index dda071ca27..6a8ec86989 100644 --- a/lib/modules/manager/poetry/artifacts.spec.ts +++ b/lib/modules/manager/poetry/artifacts.spec.ts @@ -16,6 +16,7 @@ import { updateArtifacts } from '.'; const pyproject1toml = Fixtures.get('pyproject.1.toml'); const pyproject10toml = Fixtures.get('pyproject.10.toml'); +const pyproject13toml = Fixtures.get('pyproject.13.toml'); jest.mock('../../../util/exec/env'); jest.mock('../../../util/fs'); @@ -184,11 +185,6 @@ describe('modules/manager/poetry/artifacts', () => { hostRules.find.mockReturnValueOnce({ username: 'usernameTwo' }); hostRules.find.mockReturnValueOnce({}); hostRules.find.mockReturnValueOnce({ password: 'passwordFour' }); - googleAuth.mockImplementationOnce( - jest.fn().mockImplementationOnce(() => ({ - getAccessToken: jest.fn().mockResolvedValue('some-token'), - })), - ); const updatedDeps = [{ depName: 'dep1' }]; expect( await updateArtifacts({ @@ -206,23 +202,59 @@ describe('modules/manager/poetry/artifacts', () => { }, }, ]); - expect(hostRules.find.mock.calls).toHaveLength(9); + expect(hostRules.find.mock.calls).toHaveLength(7); expect(execSnapshots).toMatchObject([ { cmd: 'poetry update --lock --no-interaction dep1', options: { env: { - HOME: '/home/user', - HTTPS_PROXY: 'https://example.com', - HTTP_PROXY: 'http://example.com', - LANG: 'en_US.UTF-8', - LC_ALL: 'en_US', - NO_PROXY: 'localhost', - PATH: '/tmp/path', - POETRY_HTTP_BASIC_FOUR_OH_FOUR_PASSWORD: 'passwordFour', POETRY_HTTP_BASIC_ONE_PASSWORD: 'passwordOne', POETRY_HTTP_BASIC_ONE_USERNAME: 'usernameOne', POETRY_HTTP_BASIC_TWO_USERNAME: 'usernameTwo', + POETRY_HTTP_BASIC_FOUR_OH_FOUR_PASSWORD: 'passwordFour', + }, + }, + }, + ]); + }); + + it('passes Google Artifact Registry credentials environment vars', async () => { + // poetry.lock + fs.getSiblingFileName.mockReturnValueOnce('poetry.lock'); + fs.readLocalFile.mockResolvedValueOnce(null); + // pyproject.lock + fs.getSiblingFileName.mockReturnValueOnce('pyproject.lock'); + fs.readLocalFile.mockResolvedValueOnce('[metadata]\n'); + const execSnapshots = mockExecAll(); + fs.readLocalFile.mockResolvedValueOnce('New poetry.lock'); + googleAuth.mockImplementationOnce( + jest.fn().mockImplementationOnce(() => ({ + getAccessToken: jest.fn().mockResolvedValue('some-token'), + })), + ); + const updatedDeps = [{ depName: 'dep1' }]; + expect( + await updateArtifacts({ + packageFileName: 'pyproject.toml', + updatedDeps, + newPackageFileContent: pyproject13toml, + config, + }), + ).toEqual([ + { + file: { + type: 'addition', + path: 'pyproject.lock', + contents: 'New poetry.lock', + }, + }, + ]); + expect(hostRules.find.mock.calls).toHaveLength(3); + expect(execSnapshots).toMatchObject([ + { + cmd: 'poetry update --lock --no-interaction dep1', + options: { + env: { POETRY_HTTP_BASIC_SOME_GAR_REPO_USERNAME: 'oauth2accesstoken', POETRY_HTTP_BASIC_SOME_GAR_REPO_PASSWORD: 'some-token', }, @@ -240,13 +272,6 @@ describe('modules/manager/poetry/artifacts', () => { fs.readLocalFile.mockResolvedValueOnce('[metadata]\n'); const execSnapshots = mockExecAll(); fs.readLocalFile.mockResolvedValueOnce('New poetry.lock'); - hostRules.find.mockReturnValueOnce({ - username: 'usernameOne', - password: 'passwordOne', - }); - hostRules.find.mockReturnValueOnce({ username: 'usernameTwo' }); - hostRules.find.mockReturnValueOnce({}); - hostRules.find.mockReturnValueOnce({ password: 'passwordFour' }); googleAuth.mockImplementation( jest.fn().mockImplementation(() => ({ getAccessToken: jest.fn().mockResolvedValue(undefined), @@ -257,7 +282,7 @@ describe('modules/manager/poetry/artifacts', () => { await updateArtifacts({ packageFileName: 'pyproject.toml', updatedDeps, - newPackageFileContent: pyproject10toml, + newPackageFileContent: pyproject13toml, config, }), ).toEqual([ @@ -269,26 +294,9 @@ describe('modules/manager/poetry/artifacts', () => { }, }, ]); - expect(hostRules.find.mock.calls).toHaveLength(9); + expect(hostRules.find.mock.calls).toHaveLength(3); expect(execSnapshots).toMatchObject([ - { - cmd: 'poetry update --lock --no-interaction dep1', - options: { - env: { - HOME: '/home/user', - HTTPS_PROXY: 'https://example.com', - HTTP_PROXY: 'http://example.com', - LANG: 'en_US.UTF-8', - LC_ALL: 'en_US', - NO_PROXY: 'localhost', - PATH: '/tmp/path', - POETRY_HTTP_BASIC_FOUR_OH_FOUR_PASSWORD: 'passwordFour', - POETRY_HTTP_BASIC_ONE_PASSWORD: 'passwordOne', - POETRY_HTTP_BASIC_ONE_USERNAME: 'usernameOne', - POETRY_HTTP_BASIC_TWO_USERNAME: 'usernameTwo', - }, - }, - }, + { cmd: 'poetry update --lock --no-interaction dep1' }, ]); }); From 2320159fca7ab3936c6e894a7afdc341e54da76d Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Tue, 19 Nov 2024 16:24:24 -0800 Subject: [PATCH 4/8] Log packageFileName --- lib/modules/manager/poetry/artifacts.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts index 98da1df7d3..a64cfd1d4e 100644 --- a/lib/modules/manager/poetry/artifacts.ts +++ b/lib/modules/manager/poetry/artifacts.ts @@ -117,7 +117,10 @@ function getPoetrySources(content: string): PoetrySource[] { return sourceArray; } -async function getMatchingHostRule(url: string | undefined): Promise { +async function getMatchingHostRule( + url: string | undefined, + packageFileName: string, +): Promise { const scopedMatch = find({ hostType: PypiDatasource.id, url }); const hostRule = is.nonEmptyObject(scopedMatch) ? scopedMatch : find({ url }); if (hostRule) { @@ -126,7 +129,7 @@ async function getMatchingHostRule(url: string | undefined): Promise { const parsedUrl = parseUrl(url); if (!parsedUrl) { - logger.once.debug({ url }, 'Failed to parse URL'); + logger.once.debug({ url, packageFileName }, 'Failed to parse URL'); return {}; } @@ -138,7 +141,10 @@ async function getMatchingHostRule(url: string | undefined): Promise { password: accessToken, }; } - logger.once.debug({ url }, 'Could not get Google access token'); + logger.once.debug( + { url, packageFileName }, + 'Could not get Google access token', + ); } return {}; @@ -146,12 +152,16 @@ async function getMatchingHostRule(url: string | undefined): Promise { async function getSourceCredentialVars( pyprojectContent: string, + packageFileName: string, ): Promise { const poetrySources = getPoetrySources(pyprojectContent); const envVars: NodeJS.ProcessEnv = {}; for (const source of poetrySources) { - const matchingHostRule = await getMatchingHostRule(source.url); + const matchingHostRule = await getMatchingHostRule( + source.url, + packageFileName, + ); const formattedSourceName = source.name .replace(regEx(/(\.|-)+/g), '_') .toUpperCase(); @@ -215,7 +225,10 @@ export async function updateArtifacts({ config.constraints?.poetry ?? getPoetryRequirement(newPackageFileContent, existingLockFileContent); const extraEnv = { - ...(await getSourceCredentialVars(newPackageFileContent)), + ...(await getSourceCredentialVars( + newPackageFileContent, + packageFileName, + )), ...getGitEnvironmentVariables(['poetry']), PIP_CACHE_DIR: await ensureCacheDir('pip'), }; From 6e7248e0d3ed55d4687578d2a62ed8f792220b7b Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Thu, 21 Nov 2024 17:14:25 -0800 Subject: [PATCH 5/8] Inline fixture --- .../manager/poetry/__fixtures__/pyproject.13.toml | 7 ------- lib/modules/manager/poetry/artifacts.spec.ts | 9 ++++++++- 2 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 lib/modules/manager/poetry/__fixtures__/pyproject.13.toml diff --git a/lib/modules/manager/poetry/__fixtures__/pyproject.13.toml b/lib/modules/manager/poetry/__fixtures__/pyproject.13.toml deleted file mode 100644 index 855b945199..0000000000 --- a/lib/modules/manager/poetry/__fixtures__/pyproject.13.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[tool.poetry.source]] -name = "some-gar-repo" -url = "https://someregion-python.pkg.dev/some-project/some-repo/simple/" - -[build-system] -requires = ["poetry_core>=1.0", "wheel"] -build-backend = "poetry.masonry.api" diff --git a/lib/modules/manager/poetry/artifacts.spec.ts b/lib/modules/manager/poetry/artifacts.spec.ts index 6a8ec86989..f7db72a8c4 100644 --- a/lib/modules/manager/poetry/artifacts.spec.ts +++ b/lib/modules/manager/poetry/artifacts.spec.ts @@ -16,7 +16,14 @@ import { updateArtifacts } from '.'; const pyproject1toml = Fixtures.get('pyproject.1.toml'); const pyproject10toml = Fixtures.get('pyproject.10.toml'); -const pyproject13toml = Fixtures.get('pyproject.13.toml'); +const pyproject13toml = `[[tool.poetry.source]] +name = "some-gar-repo" +url = "https://someregion-python.pkg.dev/some-project/some-repo/simple/" + +[build-system] +requires = ["poetry_core>=1.0", "wheel"] +build-backend = "poetry.masonry.api" +`; jest.mock('../../../util/exec/env'); jest.mock('../../../util/fs'); From d3dc8a152ece8a2d9ffd7c9f376ac6fc58e0bff5 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Fri, 29 Nov 2024 14:09:17 -0800 Subject: [PATCH 6/8] Actually fix filename usage --- lib/modules/manager/poetry/artifacts.ts | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts index a64cfd1d4e..38aacfd495 100644 --- a/lib/modules/manager/poetry/artifacts.ts +++ b/lib/modules/manager/poetry/artifacts.ts @@ -94,7 +94,7 @@ export function getPoetryRequirement( return null; } -function getPoetrySources(content: string): PoetrySource[] { +function getPoetrySources(content: string, fileName: string): PoetrySource[] { let pyprojectFile: PoetryFile; try { pyprojectFile = parseToml(content) as PoetryFile; @@ -103,7 +103,7 @@ function getPoetrySources(content: string): PoetrySource[] { return []; } if (!pyprojectFile.tool?.poetry) { - logger.debug(`{$fileName} contains no poetry section`); + logger.debug(`${fileName} contains no poetry section`); return []; } @@ -117,10 +117,7 @@ function getPoetrySources(content: string): PoetrySource[] { return sourceArray; } -async function getMatchingHostRule( - url: string | undefined, - packageFileName: string, -): Promise { +async function getMatchingHostRule(url: string | undefined): Promise { const scopedMatch = find({ hostType: PypiDatasource.id, url }); const hostRule = is.nonEmptyObject(scopedMatch) ? scopedMatch : find({ url }); if (hostRule) { @@ -129,7 +126,7 @@ async function getMatchingHostRule( const parsedUrl = parseUrl(url); if (!parsedUrl) { - logger.once.debug({ url, packageFileName }, 'Failed to parse URL'); + logger.once.debug({ url }, 'Failed to parse URL'); return {}; } @@ -141,10 +138,7 @@ async function getMatchingHostRule( password: accessToken, }; } - logger.once.debug( - { url, packageFileName }, - 'Could not get Google access token', - ); + logger.once.debug({ url }, 'Could not get Google access token'); } return {}; @@ -154,14 +148,11 @@ async function getSourceCredentialVars( pyprojectContent: string, packageFileName: string, ): Promise { - const poetrySources = getPoetrySources(pyprojectContent); + const poetrySources = getPoetrySources(pyprojectContent, packageFileName); const envVars: NodeJS.ProcessEnv = {}; for (const source of poetrySources) { - const matchingHostRule = await getMatchingHostRule( - source.url, - packageFileName, - ); + const matchingHostRule = await getMatchingHostRule(source.url); const formattedSourceName = source.name .replace(regEx(/(\.|-)+/g), '_') .toUpperCase(); From 109be0fc4cdb7b6ee06d2718555ad416cd117ae5 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Wed, 18 Dec 2024 14:18:31 +0000 Subject: [PATCH 7/8] Adjust debug logs Co-authored-by: Rhys Arkins --- lib/modules/manager/poetry/artifacts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts index 38aacfd495..46613ef088 100644 --- a/lib/modules/manager/poetry/artifacts.ts +++ b/lib/modules/manager/poetry/artifacts.ts @@ -126,7 +126,7 @@ async function getMatchingHostRule(url: string | undefined): Promise { const parsedUrl = parseUrl(url); if (!parsedUrl) { - logger.once.debug({ url }, 'Failed to parse URL'); + logger.once.debug(`Failed to parse URL ${url}`); return {}; } @@ -138,7 +138,7 @@ async function getMatchingHostRule(url: string | undefined): Promise { password: accessToken, }; } - logger.once.debug({ url }, 'Could not get Google access token'); + logger.once.debug(`Could not get Google access token (url=${url)`); } return {}; From b1b1635886ac52ed009c87aea27d574d7f43ecc1 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Wed, 18 Dec 2024 11:28:12 -0300 Subject: [PATCH 8/8] typo --- lib/modules/manager/poetry/artifacts.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts index 46613ef088..ec77248288 100644 --- a/lib/modules/manager/poetry/artifacts.ts +++ b/lib/modules/manager/poetry/artifacts.ts @@ -138,7 +138,7 @@ async function getMatchingHostRule(url: string | undefined): Promise { password: accessToken, }; } - logger.once.debug(`Could not get Google access token (url=${url)`); + logger.once.debug(`Could not get Google access token (url=${url})`); } return {};