Support git over https without username for pip_requirements (#15231)

This commit is contained in:
Mikhail Advani 2022-04-29 06:11:11 +02:00 committed by GitHub
parent d288f1409e
commit 3fe66407f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 10 deletions

View file

@ -2,3 +2,4 @@ git+ssh://git@github.com/rwxd/python-pip-setup-test.git@v1.1.0
git+ssh://git@github.com/rwxd/test_package@1.0.0
git+ssh://git@gitlab.company.com/rwxd/python-package.git@abcde
git+https://peter@github.com/rwxd/python-pip-setup-test.git@v0.9.0
git+https://github.com/rwxd/python-pip-setup-test.git@v0.9.0

View file

@ -181,7 +181,7 @@ describe('modules/manager/pip_requirements/extract', () => {
'unused_file_name',
{}
);
expect(res.deps).toHaveLength(4);
expect(res.deps).toHaveLength(5);
expect(res).toEqual({
deps: [
{
@ -209,7 +209,15 @@ describe('modules/manager/pip_requirements/extract', () => {
depName: 'python-pip-setup-test',
currentValue: 'v0.9.0',
currentVersion: 'v0.9.0',
packageName: 'peter@github.com:rwxd/python-pip-setup-test.git',
packageName:
'https://peter@github.com/rwxd/python-pip-setup-test.git',
datasource: 'git-tags',
},
{
depName: 'python-pip-setup-test',
currentValue: 'v0.9.0',
currentVersion: 'v0.9.0',
packageName: 'https://github.com/rwxd/python-pip-setup-test.git',
datasource: 'git-tags',
},
],

View file

@ -13,7 +13,7 @@ export const packagePattern =
'[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]';
const extrasPattern = '(?:\\s*\\[[^\\]]+\\])?';
const packageGitRegex = regEx(
/(?<source>(?:git\+)(git|ssh|https):\/\/(?<gitUrl>(?<user>.*)@(?<hostname>[\w.-]+)(?<delimiter>\/)(?<scmPath>.*\/(?<depName>[\w/-]+))(\.git)?(?:@(?<version>.*))))/
/(?<source>(?:git\+)(?<protocol>git|ssh|https):\/\/(?<gitUrl>(?:(?<user>[^@]+)@)?(?<hostname>[\w.-]+)(?<delimiter>\/)(?<scmPath>.*\/(?<depName>[\w/-]+))(\.git)?(?:@(?<version>.*))))/
);
const rangePattern: string = RANGE_PATTERN;
@ -78,13 +78,19 @@ export function extractPackageFile(
if (gitPackageMatches?.groups) {
const currentVersion = gitPackageMatches.groups.version;
const depName = gitPackageMatches.groups.depName;
let packageName: string;
if (gitPackageMatches.groups.protocol === 'https') {
packageName = 'https://'
.concat(gitPackageMatches.groups.gitUrl)
.replace(`@${currentVersion}`, '');
} else {
// we need to replace the / with a :
const scmPath = gitPackageMatches.groups.scmPath;
const delimiter = gitPackageMatches.groups.delimiter;
const packageName = gitPackageMatches.groups.gitUrl
packageName = gitPackageMatches.groups.gitUrl
.replace(`${delimiter}${scmPath}`, `:${scmPath}`)
.replace(`@${currentVersion}`, '');
}
dep = {
...dep,
depName,