From 7e7ec8cc56a6c82d5b9f18c6ef5adbc5d41b3c28 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Tue, 29 Jan 2019 12:53:37 +0100
Subject: [PATCH] refactor: remove purl namespace and name

---
 lib/datasource/maven.js                   | 10 ++++++----
 lib/util/purl.js                          |  2 ++
 test/util/__snapshots__/purl.spec.js.snap |  8 --------
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/datasource/maven.js b/lib/datasource/maven.js
index be6b8a709e..5cac133bbc 100644
--- a/lib/datasource/maven.js
+++ b/lib/datasource/maven.js
@@ -47,10 +47,11 @@ async function getPkgReleases(purl, config) {
 }
 
 function getDependencyParts(purl) {
+  const [group, name] = purl.lookupName.split('/');
   return {
-    display: `${purl.namespace}:${purl.name}`,
-    group: purl.namespace,
-    name: purl.name,
+    display: purl.lookupName.replace('/', ':'),
+    group,
+    name,
     dependencyUrl: generateMavenUrl(purl),
   };
 }
@@ -132,7 +133,8 @@ async function downloadHttpProtocol(pkgUrl) {
 }
 
 function generateMavenUrl(purl) {
-  return purl.namespace.replace(/\./g, '/') + `/${purl.name}`;
+  const [group, name] = purl.lookupName.split('/');
+  return group.replace(/\./g, '/') + `/${name}`;
 }
 
 function isMavenCentral(pkgUrl) {
diff --git a/lib/util/purl.js b/lib/util/purl.js
index 02dc695e3f..aa1ff81d31 100644
--- a/lib/util/purl.js
+++ b/lib/util/purl.js
@@ -44,6 +44,8 @@ function parse(input) {
   } else {
     res.qualifiers = {};
   }
+  delete res.namespace;
+  delete res.name;
   delete res.version; // we don't use it
   return res;
 }
diff --git a/test/util/__snapshots__/purl.spec.js.snap b/test/util/__snapshots__/purl.spec.js.snap
index ed34ee1490..81f9876f11 100644
--- a/test/util/__snapshots__/purl.spec.js.snap
+++ b/test/util/__snapshots__/purl.spec.js.snap
@@ -4,8 +4,6 @@ exports[`util/purl parse() parses namespaced npm 1`] = `
 Object {
   "datasource": "npm",
   "lookupName": "@foo/bar",
-  "name": "bar",
-  "namespace": "@foo",
   "qualifiers": Object {},
 }
 `;
@@ -14,8 +12,6 @@ exports[`util/purl parse() parses namespaced npm with version 1`] = `
 Object {
   "datasource": "npm",
   "lookupName": "@foo/bar",
-  "name": "bar",
-  "namespace": "@foo",
   "qualifiers": Object {},
 }
 `;
@@ -24,7 +20,6 @@ exports[`util/purl parse() parses npm with version and 1 qualifier 1`] = `
 Object {
   "datasource": "npm",
   "lookupName": "foo",
-  "name": "foo",
   "qualifiers": Object {
     "a": "b",
   },
@@ -35,7 +30,6 @@ exports[`util/purl parse() parses npm with version and 2 qualifiers 1`] = `
 Object {
   "datasource": "npm",
   "lookupName": "foo",
-  "name": "foo",
   "qualifiers": Object {
     "a": "b",
     "c": "d",
@@ -47,7 +41,6 @@ exports[`util/purl parse() parses npm with version and 2 qualifiers and subpath
 Object {
   "datasource": "npm",
   "lookupName": "foo",
-  "name": "foo",
   "qualifiers": Object {
     "a": "b",
     "c": "d",
@@ -60,7 +53,6 @@ exports[`util/purl parse() parses simple npm 1`] = `
 Object {
   "datasource": "npm",
   "lookupName": "foo",
-  "name": "foo",
   "qualifiers": Object {},
 }
 `;
-- 
GitLab