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

fix(manager/npm): support git@github.com repository urls #11362

Merged
merged 4 commits into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions lib/manager/npm/extract/__snapshots__/index.spec.ts.snap
Expand Up @@ -296,6 +296,19 @@ Object {
"prettyDepType": "dependency",
"sourceUrl": "https://github.com/owner/n",
},
Object {
"currentRawValue": "git@github.com:owner/o.git#v2.0.0",
"currentValue": "v2.0.0",
"datasource": "github-tags",
"depName": "o",
"depType": "dependencies",
"gitRef": true,
"githubRepo": "owner/o",
"lookupName": "owner/o",
"pinDigests": false,
"prettyDepType": "dependency",
"sourceUrl": "https://github.com/owner/o",
},
],
"lernaClient": undefined,
"lernaPackages": undefined,
Expand Down
1 change: 1 addition & 0 deletions lib/manager/npm/extract/index.spec.ts
Expand Up @@ -332,6 +332,7 @@ describe('manager/npm/extract/index', () => {
l: 'github:owner/l.git#abcdef0',
m: 'https://github.com/owner/m.git#v1.0.0',
n: 'git+https://github.com/owner/n#v2.0.0',
o: 'git@github.com:owner/o.git#v2.0.0',
},
};
const pJsonStr = JSON.stringify(pJson);
Expand Down
34 changes: 24 additions & 10 deletions lib/manager/npm/extract/index.ts
Expand Up @@ -30,6 +30,9 @@ function parseDepName(depType: string, key: string): string {
return depName;
}

const RE_REPOSITORY_GITHUB_SSH_FORMAT =
/(?:git@)github.com:([^/]+)\/([^/.]+)(?:\.git)?/;

export async function extractPackageFile(
content: string,
fileName: string,
Expand Down Expand Up @@ -258,17 +261,28 @@ export async function extractPackageFile(
return dep;
}
const [depNamePart, depRefPart] = hashSplit;
const githubOwnerRepo = depNamePart
.replace(/^github:/, '')
.replace(/^git\+/, '')
.replace(/^https:\/\/github\.com\//, '')
rarkins marked this conversation as resolved.
Show resolved Hide resolved
.replace(/\.git$/, '');
const githubRepoSplit = githubOwnerRepo.split('/');
if (githubRepoSplit.length !== 2) {
dep.skipReason = SkipReason.UnknownVersion;
return dep;

let githubOwnerRepo: string;
let githubOwner: string;
let githubRepo: string;
const matchUrlSshFormat = RE_REPOSITORY_GITHUB_SSH_FORMAT.exec(depNamePart);
rarkins marked this conversation as resolved.
Show resolved Hide resolved
if (matchUrlSshFormat === null) {
githubOwnerRepo = depNamePart
.replace(/^github:/, '')
.replace(/^git\+/, '')
.replace(/^https:\/\/github\.com\//, '')
.replace(/\.git$/, '');
const githubRepoSplit = githubOwnerRepo.split('/');
if (githubRepoSplit.length !== 2) {
dep.skipReason = SkipReason.UnknownVersion;
return dep;
}
[githubOwner, githubRepo] = githubRepoSplit;
} else {
githubOwner = matchUrlSshFormat[1];
githubRepo = matchUrlSshFormat[2];
githubOwnerRepo = `${githubOwner}/${githubRepo}`;
}
const [githubOwner, githubRepo] = githubRepoSplit;
const githubValidRegex = /^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/;
if (
!githubValidRegex.test(githubOwner) ||
Expand Down