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): support git rev dependencies #26367

Merged
merged 9 commits into from
Jan 4, 2024
135 changes: 112 additions & 23 deletions lib/modules/manager/poetry/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { GitRefsDatasource } from '../../datasource/git-refs';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { extractPackageFile } from '.';
Expand Down Expand Up @@ -169,19 +170,96 @@ describe('modules/manager/poetry/extract', () => {
});
});

it('parses git dependencies long commit hashs on http urls', async () => {
const content = codeBlock`
[tool.poetry.dependencies]
fastapi = {git = "https://github.com/tiangolo/fastapi.git", rev="6f5aa81c076d22e38afbe7d602db6730e28bc3cc"}
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'fastapi',
datasource: GitRefsDatasource.id,
currentValue: undefined,
currentDigest: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
replaceString: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
pinDigests: true,
packageName: 'https://github.com/tiangolo/fastapi.git',
});
NextFire marked this conversation as resolved.
Show resolved Hide resolved
});

it('parses git dependencies short commit hashs on http urls', async () => {
const content = codeBlock`
[tool.poetry.dependencies]
fastapi = {git = "https://github.com/tiangolo/fastapi.git", rev="6f5aa81"}
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'fastapi',
datasource: GitRefsDatasource.id,
currentValue: undefined,
currentDigest: '6f5aa81',
replaceString: '6f5aa81',
pinDigests: true,
packageName: 'https://github.com/tiangolo/fastapi.git',
});
});

it('parses git dependencies long commit hashs on ssh urls', async () => {
const content = codeBlock`
[tool.poetry.dependencies]
fastapi = {git = "[email protected]:tiangolo/fastapi.git", rev="6f5aa81c076d22e38afbe7d602db6730e28bc3cc"}
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
NextFire marked this conversation as resolved.
Show resolved Hide resolved
depName: 'fastapi',
datasource: GitRefsDatasource.id,
currentValue: undefined,
currentDigest: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
replaceString: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
pinDigests: true,
packageName: '[email protected]:tiangolo/fastapi.git',
});
});

it('parses git dependencies long commit hashs 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"}
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'fastapi',
datasource: GitRefsDatasource.id,
currentValue: 'develop',
currentDigest: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
replaceString: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
pinDigests: true,
packageName: 'https://github.com/tiangolo/fastapi.git',
});
});

it('parses github dependencies tags on ssh urls', async () => {
const content = codeBlock`
[tool.poetry.dependencies]
fastapi = {git = "[email protected]:tiangolo/fastapi.git", tag="1.2.3"}
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res[0].depName).toBe('fastapi');
expect(res[0].packageName).toBe('tiangolo/fastapi');
expect(res[0].currentValue).toBe('1.2.3');
expect(res[0].skipReason).toBeUndefined();
expect(res[0].datasource).toBe(GithubTagsDatasource.id);
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
NextFire marked this conversation as resolved.
Show resolved Hide resolved
depName: 'fastapi',
packageName: 'tiangolo/fastapi',
currentValue: '1.2.3',
datasource: GithubTagsDatasource.id,
});
});

it('parses github dependencies tags on http urls', async () => {
Expand All @@ -191,12 +269,13 @@ describe('modules/manager/poetry/extract', () => {
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res[0].depName).toBe('fastapi');
expect(res[0].packageName).toBe('tiangolo/fastapi');
expect(res[0].currentValue).toBe('1.2.3');
expect(res[0].skipReason).toBeUndefined();
expect(res[0].datasource).toBe(GithubTagsDatasource.id);
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'fastapi',
packageName: 'tiangolo/fastapi',
currentValue: '1.2.3',
datasource: GithubTagsDatasource.id,
});
});

it('skips git dependencies', async () => {
Expand All @@ -206,9 +285,11 @@ describe('modules/manager/poetry/extract', () => {
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res[0].depName).toBe('flask');
expect(res[0].skipReason).toBe('git-dependency');
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'flask',
skipReason: 'git-dependency',
});
});

it('skips git dependencies with version', async () => {
Expand All @@ -218,10 +299,12 @@ describe('modules/manager/poetry/extract', () => {
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res[0].depName).toBe('flask');
expect(res[0].currentValue).toBe('1.2.3');
expect(res[0].skipReason).toBe('git-dependency');
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'flask',
currentValue: '1.2.3',
skipReason: 'git-dependency',
});
});

it('skips git dependencies on tags that are not in github', async () => {
Expand All @@ -230,10 +313,12 @@ describe('modules/manager/poetry/extract', () => {
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);
expect(res[0]).toMatchObject({
depName: 'aws-sam',
currentValue: '1.2.3',
skipReason: 'git-dependency',
});
});

it('skips path dependencies', async () => {
Expand All @@ -243,9 +328,11 @@ describe('modules/manager/poetry/extract', () => {
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res[0].depName).toBe('flask');
expect(res[0].skipReason).toBe('path-dependency');
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'flask',
skipReason: 'path-dependency',
});
});

it('skips path dependencies with version', async () => {
Expand All @@ -255,10 +342,12 @@ describe('modules/manager/poetry/extract', () => {
werkzeug = ">=0.14"
`;
const res = (await extractPackageFile(content, filename))!.deps;
expect(res[0].depName).toBe('flask');
expect(res[0].currentValue).toBe('1.2.3');
expect(res[0].skipReason).toBe('path-dependency');
expect(res).toHaveLength(2);
expect(res[0]).toMatchObject({
depName: 'flask',
currentValue: '1.2.3',
skipReason: 'path-dependency',
});
});

it('does not include registry url for dependency python', async () => {
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/poetry/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Category } from '../../../constants';
import { GitRefsDatasource } from '../../datasource/git-refs';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { PypiDatasource } from '../../datasource/pypi';
Expand All @@ -11,6 +12,7 @@ export const supportedDatasources = [
PypiDatasource.id,
GithubTagsDatasource.id,
GithubReleasesDatasource.id,
GitRefsDatasource.id,
];

export const supportsLockFileMaintenance = true;
Expand Down
58 changes: 35 additions & 23 deletions lib/modules/manager/poetry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { uniq } from '../../../util/uniq';
import { GitRefsDatasource } from '../../datasource/git-refs';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { PypiDatasource } from '../../datasource/pypi';
import * as gitVersioning from '../../versioning/git';
import * as pep440Versioning from '../../versioning/pep440';
import * as poetryVersioning from '../../versioning/poetry';
import { dependencyPattern } from '../pip_requirements/extract';
Expand Down Expand Up @@ -35,39 +36,45 @@ const PoetryGitDependency = z
git: z.string(),
tag: z.string().optional().catch(undefined),
version: z.string().optional().catch(undefined),
branch: z.string().optional().catch(undefined),
rev: z.string().optional().catch(undefined),
})
.transform(({ git, tag, version }): PackageDependency => {
if (!tag) {
const res: PackageDependency = {
.transform(({ git, tag, version, branch, rev }): PackageDependency => {
if (tag) {
const parsedUrl = parseGitUrl(git);
if (parsedUrl.source === 'github.com') {
const { owner, name } = parsedUrl;
NextFire marked this conversation as resolved.
Show resolved Hide resolved
const repo = `${owner}/${name}`;
return {
datasource: GithubTagsDatasource.id,
currentValue: tag,
packageName: repo,
};
} else {
return {
datasource: GitRefsDatasource.id,
currentValue: tag,
packageName: git,
skipReason: 'git-dependency',
};
}
} else if (rev) {
return {
NextFire marked this conversation as resolved.
Show resolved Hide resolved
datasource: GitRefsDatasource.id,
currentValue: branch,
currentDigest: rev,
replaceString: rev,
pinDigests: true,
viceice marked this conversation as resolved.
Show resolved Hide resolved
packageName: git,
skipReason: 'git-dependency',
};

if (version) {
res.currentValue = version;
}

return res;
}

const parsedUrl = parseGitUrl(git);
if (parsedUrl.source !== 'github.com') {
} else {
return {
datasource: GitRefsDatasource.id,
currentValue: tag,
currentValue: version,
packageName: git,
skipReason: 'git-dependency',
};
}

const { owner, name } = parsedUrl;
const repo = `${owner}/${name}`;
return {
datasource: GithubTagsDatasource.id,
currentValue: tag,
packageName: repo,
};
});

const PoetryPypiDependency = z.union([
Expand Down Expand Up @@ -114,6 +121,11 @@ export const PoetryDependencies = LooseRecord(
return dep;
}

if (dep.datasource === GitRefsDatasource.id && dep.currentDigest) {
dep.versioning = gitVersioning.id;
return dep;
}

// istanbul ignore if: normaly should not happen
if (!dep.currentValue) {
dep.skipReason = 'unspecified-version';
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/manager/poetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface PoetryDependency {
git?: string;
tag?: string;
version?: string;
branch?: string;
rev?: string;
}

export interface PoetrySource {
Expand Down