From 83c03d897a4cc6dc241be10dbbc691e4b97512d1 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Sat, 21 Aug 2021 20:25:24 +0300 Subject: [PATCH 1/2] tests --- .../npm/extract/__snapshots__/index.spec.ts.snap | 13 +++++++++++++ lib/manager/npm/extract/index.spec.ts | 1 + 2 files changed, 14 insertions(+) diff --git a/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap b/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap index 8f96b954679a76..f36de7462706b6 100644 --- a/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap +++ b/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap @@ -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, diff --git a/lib/manager/npm/extract/index.spec.ts b/lib/manager/npm/extract/index.spec.ts index 83a3a08b5a639a..7468c4b9967953 100644 --- a/lib/manager/npm/extract/index.spec.ts +++ b/lib/manager/npm/extract/index.spec.ts @@ -317,6 +317,7 @@ describe(getName(), () => { 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); From 524754e4e9dd339ded3d947e8925775c455f35ef Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Sat, 21 Aug 2021 20:27:23 +0300 Subject: [PATCH 2/2] feat(manager/npm): support git@github.com repository urls --- lib/manager/npm/extract/index.ts | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/manager/npm/extract/index.ts b/lib/manager/npm/extract/index.ts index 56f0552712a705..3e3cfa313906b2 100644 --- a/lib/manager/npm/extract/index.ts +++ b/lib/manager/npm/extract/index.ts @@ -29,6 +29,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, @@ -257,17 +260,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) ||