Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager/poetry): add support for git tag dependencies in non-GitHub repos #27693

Merged
merged 1 commit into from Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 27 additions & 16 deletions lib/modules/manager/poetry/extract.spec.ts
Expand Up @@ -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"}
Expand All @@ -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"}
Expand All @@ -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"}
Expand All @@ -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"}
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions 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';
Expand All @@ -13,7 +15,9 @@ export const supportedDatasources = [
PypiDatasource.id,
GithubTagsDatasource.id,
GithubReleasesDatasource.id,
GitlabTagsDatasource.id,
GitRefsDatasource.id,
GitTagsDatasource.id,
];

export const supportsLockFileMaintenance = true;
Expand Down
27 changes: 17 additions & 10 deletions lib/modules/manager/poetry/schema.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
};
}
}
Expand All @@ -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([
Expand Down