Skip to content
Snippets Groups Projects
Unverified Commit 9e441360 authored by Johannes Feichtner's avatar Johannes Feichtner Committed by GitHub
Browse files

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

parent d240aa91
No related branches found
No related tags found
No related merge requests found
......@@ -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]
......
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;
......
......@@ -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);
if (source === 'github.com') {
const repo = `${owner}/${name}`;
if (source === 'github.com') {
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',
};
}
});
const PoetryPypiDependency = z.union([
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment