From 282b073037c1a0d910b24c103252286d856fa271 Mon Sep 17 00:00:00 2001 From: Johannes Feichtner Date: Sun, 3 Mar 2024 21:03:04 +0100 Subject: [PATCH] feat(manager/poetry): add support for git tag dependencies in non-GitHub repos --- lib/modules/manager/poetry/extract.spec.ts | 43 ++++++++++++++-------- lib/modules/manager/poetry/index.ts | 4 ++ lib/modules/manager/poetry/schema.ts | 27 +++++++++----- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/lib/modules/manager/poetry/extract.spec.ts b/lib/modules/manager/poetry/extract.spec.ts index 62f43868f7287a..240511cf44351b 100644 --- a/lib/modules/manager/poetry/extract.spec.ts +++ b/lib/modules/manager/poetry/extract.spec.ts @@ -171,7 +171,7 @@ describe('modules/manager/poetry/extract', () => { }); }); - it('parses git dependencies long commit hashs on http urls', async () => { + it('parses git dependencies long commit hashes on http urls', async () => { const content = codeBlock` [tool.poetry.dependencies] fastapi = {git = "https://github.com/tiangolo/fastapi.git", rev="6f5aa81c076d22e38afbe7d602db6730e28bc3cc"} @@ -196,7 +196,7 @@ describe('modules/manager/poetry/extract', () => { ]); }); - it('parses git dependencies short commit hashs on http urls', async () => { + it('parses git dependencies short commit hashes on http urls', async () => { const content = codeBlock` [tool.poetry.dependencies] fastapi = {git = "https://github.com/tiangolo/fastapi.git", rev="6f5aa81"} @@ -221,7 +221,7 @@ describe('modules/manager/poetry/extract', () => { ]); }); - it('parses git dependencies long commit hashs on ssh urls', async () => { + it('parses git dependencies long commit hashes on ssh urls', async () => { const content = codeBlock` [tool.poetry.dependencies] fastapi = {git = "git@github.com:tiangolo/fastapi.git", rev="6f5aa81c076d22e38afbe7d602db6730e28bc3cc"} @@ -246,7 +246,7 @@ describe('modules/manager/poetry/extract', () => { ]); }); - it('parses git dependencies long commit hashs on http urls with branch marker', async () => { + it('parses git dependencies long commit hashes on http urls with branch marker', async () => { const content = codeBlock` [tool.poetry.dependencies] fastapi = {git = "https://github.com/tiangolo/fastapi.git", branch="develop", rev="6f5aa81c076d22e38afbe7d602db6730e28bc3cc"} @@ -302,6 +302,29 @@ describe('modules/manager/poetry/extract', () => { expect(res).toHaveLength(2); }); + it('parses git dependencies with tags that are not on GitHub', async () => { + const content = codeBlock` + [tool.poetry.dependencies] + aws-sam = {git = "https://gitlab.com/gitlab-examples/aws-sam.git", tag="1.2.3"} + platform-tools = {git = "https://some.company.com/platform-tools", tag="1.2.3"} + `; + const res = await extractPackageFile(content, filename); + expect(res?.deps).toMatchObject([ + { + datasource: 'gitlab-tags', + depName: 'aws-sam', + packageName: 'gitlab-examples/aws-sam', + currentValue: '1.2.3', + }, + { + datasource: 'git-tags', + depName: 'platform-tools', + packageName: 'https://some.company.com/platform-tools', + currentValue: '1.2.3', + }, + ]); + }); + it('skips git dependencies', async () => { const content = codeBlock` [tool.poetry.dependencies] @@ -327,18 +350,6 @@ describe('modules/manager/poetry/extract', () => { expect(res).toHaveLength(2); }); - it('skips git dependencies on tags that are not in github', async () => { - const content = codeBlock` - [tool.poetry.dependencies] - aws-sam = {git = "https://gitlab.com/gitlab-examples/aws-sam.git", tag="1.2.3"} - `; - const res = (await extractPackageFile(content, filename))!.deps; - expect(res[0].depName).toBe('aws-sam'); - expect(res[0].currentValue).toBe('1.2.3'); - expect(res[0].skipReason).toBe('git-dependency'); - expect(res).toHaveLength(1); - }); - it('skips path dependencies', async () => { const content = codeBlock` [tool.poetry.dependencies] diff --git a/lib/modules/manager/poetry/index.ts b/lib/modules/manager/poetry/index.ts index 82a131c8e26ea9..f8a52fb9467949 100644 --- a/lib/modules/manager/poetry/index.ts +++ b/lib/modules/manager/poetry/index.ts @@ -1,7 +1,9 @@ import type { Category } from '../../../constants'; import { GitRefsDatasource } from '../../datasource/git-refs'; +import { GitTagsDatasource } from '../../datasource/git-tags'; import { GithubReleasesDatasource } from '../../datasource/github-releases'; import { GithubTagsDatasource } from '../../datasource/github-tags'; +import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { PypiDatasource } from '../../datasource/pypi'; export { bumpPackageVersion } from '../pep621/update'; @@ -13,7 +15,9 @@ export const supportedDatasources = [ PypiDatasource.id, GithubTagsDatasource.id, GithubReleasesDatasource.id, + GitlabTagsDatasource.id, GitRefsDatasource.id, + GitTagsDatasource.id, ]; export const supportsLockFileMaintenance = true; diff --git a/lib/modules/manager/poetry/schema.ts b/lib/modules/manager/poetry/schema.ts index 621f844b7c5a48..b1cd00d7b04f03 100644 --- a/lib/modules/manager/poetry/schema.ts +++ b/lib/modules/manager/poetry/schema.ts @@ -5,7 +5,9 @@ import { regEx } from '../../../util/regex'; import { LooseArray, LooseRecord, Toml } from '../../../util/schema-utils'; import { uniq } from '../../../util/uniq'; import { GitRefsDatasource } from '../../datasource/git-refs'; +import { GitTagsDatasource } from '../../datasource/git-tags'; import { GithubTagsDatasource } from '../../datasource/github-tags'; +import { GitlabTagsDatasource } from '../../datasource/gitlab-tags'; import { PypiDatasource } from '../../datasource/pypi'; import * as gitVersioning from '../../versioning/git'; import * as pep440Versioning from '../../versioning/pep440'; @@ -42,19 +44,24 @@ const PoetryGitDependency = z .transform(({ git, tag, version, branch, rev }): PackageDependency => { if (tag) { const { source, owner, name } = parseGitUrl(git); + const repo = `${owner}/${name}`; if (source === 'github.com') { - const repo = `${owner}/${name}`; return { datasource: GithubTagsDatasource.id, currentValue: tag, packageName: repo, }; + } else if (source === 'gitlab.com') { + return { + datasource: GitlabTagsDatasource.id, + currentValue: tag, + packageName: repo, + }; } else { return { - datasource: GitRefsDatasource.id, + datasource: GitTagsDatasource.id, currentValue: tag, packageName: git, - skipReason: 'git-dependency', }; } } @@ -67,14 +74,14 @@ const PoetryGitDependency = z replaceString: rev, packageName: git, }; - } else { - return { - datasource: GitRefsDatasource.id, - currentValue: version, - packageName: git, - skipReason: 'git-dependency', - }; } + + return { + datasource: GitRefsDatasource.id, + currentValue: version, + packageName: git, + skipReason: 'git-dependency', + }; }); const PoetryPypiDependency = z.union([