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 tag as git-dependency on github #21949

Merged
merged 7 commits into from May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 35 additions & 0 deletions lib/modules/manager/poetry/extract.spec.ts
@@ -1,5 +1,6 @@
import { Fixtures } from '../../../../test/fixtures';
import { fs } from '../../../../test/util';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { extractPackageFile } from '.';

jest.mock('../../../util/fs');
Expand Down Expand Up @@ -177,6 +178,30 @@ describe('modules/manager/poetry/extract', () => {
});
});

it('parses github dependencies tags on ssh urls', async () => {
const content =
'[tool.poetry.dependencies]\r\nfastapi = {git = "git@github.com:tiangolo/fastapi.git", tag="1.2.3"}\r\nwerkzeug = ">=0.14"';
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved
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);
});

it('parses github dependencies tags on http urls', async () => {
const content =
'[tool.poetry.dependencies]\r\nfastapi = {git = "https://github.com/tiangolo/fastapi.git", tag="1.2.3"}\r\nwerkzeug = ">=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);
});

it('skips git dependencies', async () => {
const content =
'[tool.poetry.dependencies]\r\nflask = {git = "https://github.com/pallets/flask.git"}\r\nwerkzeug = ">=0.14"';
Expand All @@ -197,6 +222,16 @@ describe('modules/manager/poetry/extract', () => {
expect(res).toHaveLength(2);
});

it('skips git dependencies on tags that are not in github', async () => {
const content =
'[tool.poetry.dependencies]\r\naws-sam = {git = "https://gitlab.com/gitlab-examples/aws-sam.git", tag="1.2.3"}\r\nwerkzeug = ">=0.14"';
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(2);
});

it('skips path dependencies', async () => {
const content =
'[tool.poetry.dependencies]\r\nflask = {path = "/some/path/"}\r\nwerkzeug = ">=0.14"';
Expand Down
53 changes: 45 additions & 8 deletions lib/modules/manager/poetry/extract.ts
Expand Up @@ -8,6 +8,7 @@ import {
readLocalFile,
} from '../../../util/fs';
import { regEx } from '../../../util/regex';
import { GithubTagsDatasource } from '../../datasource/github-tags';
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved
import { PypiDatasource } from '../../datasource/pypi';
import * as pep440Versioning from '../../versioning/pep440';
import * as poetryVersioning from '../../versioning/poetry';
Expand Down Expand Up @@ -56,16 +57,20 @@ function extractFromSection(
}

const pep503NormalizeRegex = regEx(/[-_.]+/g);
const packageName = depName
.toLowerCase()
.replace(pep503NormalizeRegex, '-');
let packageName = depName.toLowerCase().replace(pep503NormalizeRegex, '-');
let skipReason: SkipReason | null = null;
let currentValue = sectionContent[depName];
let nestedVersion = false;
let datasource = PypiDatasource.id;
let lockedVersion: string | null = null;
if (packageName in poetryLockfile) {
lockedVersion = poetryLockfile[packageName];
}
rarkins marked this conversation as resolved.
Show resolved Hide resolved
if (!is.string(currentValue)) {
const version = currentValue.version;
const path = currentValue.path;
const git = currentValue.git;
const tag = currentValue.tag;
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved
if (version) {
currentValue = version;
nestedVersion = true;
Expand All @@ -76,8 +81,19 @@ function extractFromSection(
currentValue = '';
skipReason = 'path-dependency';
} else if (git) {
currentValue = '';
skipReason = 'git-dependency';
if (tag) {
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved
currentValue = tag;
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved
datasource = GithubTagsDatasource.id;
const githubPackageName = extractGithubPackageName(git);
if (githubPackageName) {
packageName = githubPackageName;
} else {
skipReason = 'git-dependency';
}
} else {
currentValue = '';
skipReason = 'git-dependency';
}
} else {
currentValue = '';
skipReason = 'multiple-constraint-dep';
Expand All @@ -88,10 +104,10 @@ function extractFromSection(
depType,
currentValue,
managerData: { nestedVersion },
datasource: PypiDatasource.id,
datasource,
};
if (packageName in poetryLockfile) {
dep.lockedVersion = poetryLockfile[packageName];
if (lockedVersion) {
dep.lockedVersion = lockedVersion;
}
if (depName !== packageName) {
dep.packageName = packageName;
Expand Down Expand Up @@ -199,3 +215,24 @@ export async function extractPackageFile(
}
return res;
}

function extractGithubPackageName(url: string): string | null {
const httpRegex = regEx(/^(?:https?:\/\/)?(?:www\.)?github.com\/(.*)$/);
const sshRegex = regEx(/^git@github.com:(.*)?$/);
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved

const httpMatch = httpRegex.exec(url);
const sshMatch = sshRegex.exec(url);

function removeDotGit(packageName: string): string {
return packageName.replace('.git', '');
}
yetanotherion marked this conversation as resolved.
Show resolved Hide resolved

if (httpMatch) {
return removeDotGit(httpMatch[1]);
}

if (sshMatch) {
return removeDotGit(sshMatch[1]);
}
return null;
}
1 change: 1 addition & 0 deletions lib/modules/manager/poetry/types.ts
Expand Up @@ -20,6 +20,7 @@ export interface PoetryFile {
export interface PoetryDependency {
path?: string;
git?: string;
tag?: string;
version?: string;
}

Expand Down