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
73 changes: 73 additions & 0 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,6 +170,78 @@ 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',
packageName: 'https://github.com/tiangolo/fastapi.git',
});
});

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',
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 = "git@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({
NextFire marked this conversation as resolved.
Show resolved Hide resolved
depName: 'fastapi',
datasource: GitRefsDatasource.id,
currentValue: undefined,
currentDigest: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
replaceString: '6f5aa81c076d22e38afbe7d602db6730e28bc3cc',
packageName: 'git@github.com: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',
packageName: 'https://github.com/tiangolo/fastapi.git',
});
});

it('parses github dependencies tags on ssh urls', async () => {
const content = codeBlock`
[tool.poetry.dependencies]
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 = {
datasource: GitRefsDatasource.id,
packageName: git,
skipReason: 'git-dependency',
};

if (version) {
res.currentValue = version;
.transform(({ git, tag, version, branch, rev }): PackageDependency => {
if (tag) {
const { source, owner, name } = parseGitUrl(git);
if (source === 'github.com') {
const repo = `${owner}/${name}`;
return {
datasource: GithubTagsDatasource.id,
currentValue: tag,
packageName: repo,
};
} else {
return {
datasource: GitRefsDatasource.id,
currentValue: tag,
packageName: git,
skipReason: 'git-dependency',
};
}

return res;
}

const parsedUrl = parseGitUrl(git);
if (parsedUrl.source !== 'github.com') {
if (rev) {
return {
datasource: GitRefsDatasource.id,
currentValue: branch,
currentDigest: rev,
replaceString: rev,
packageName: git,
};
} 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