Skip to content

Commit

Permalink
fix(manager/npm): support git@github.com repository urls (#11362)
Browse files Browse the repository at this point in the history
  • Loading branch information
stroncium committed Sep 6, 2021
1 parent a163306 commit b00cca0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
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\//, '')
.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);
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

0 comments on commit b00cca0

Please sign in to comment.