From 371c10f25926c1c0becc197be64f482ec603608f Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 11 Jun 2018 07:15:54 +0200
Subject: [PATCH] refactor: rename clean=true to sanitize=true

---
 lib/datasource/github.js                                  | 5 +++--
 lib/manager/npm/extract/index.js                          | 2 +-
 lib/manager/nvm/extract.js                                | 2 +-
 lib/manager/travis/package.js                             | 2 +-
 test/datasource/__snapshots__/github.spec.js.snap         | 2 --
 test/datasource/github.spec.js                            | 4 ++--
 test/manager/npm/extract/__snapshots__/index.spec.js.snap | 2 +-
 test/manager/nvm/__snapshots__/extract.spec.js.snap       | 4 ++--
 8 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/lib/datasource/github.js b/lib/datasource/github.js
index ddc3caa7e1..1b2193ac84 100644
--- a/lib/datasource/github.js
+++ b/lib/datasource/github.js
@@ -1,4 +1,5 @@
 const ghGot = require('../platform/github/gh-got-wrapper');
+const { isVersion } = require('../versioning/semver');
 
 module.exports = {
   getDependency,
@@ -45,8 +46,8 @@ async function getDependency(purl) {
     return null;
   }
   // Filter by semver if no versionScheme provided
-  if (options.clean === 'true') {
-    versions = versions.map(version => version.replace(/^v(\d)/, '$1'));
+  if (options.sanitize === 'true') {
+    versions = versions.map(version => isVersion(version)).filter(Boolean);
   }
   const dependency = {
     repositoryUrl: 'https://github.com/' + repo,
diff --git a/lib/manager/npm/extract/index.js b/lib/manager/npm/extract/index.js
index d99d6cc1a2..c34bd5c970 100644
--- a/lib/manager/npm/extract/index.js
+++ b/lib/manager/npm/extract/index.js
@@ -118,7 +118,7 @@ async function extractDependencies(content, packageFile, config) {
           dep.currentValue = version.trim();
           if (depType === 'engines') {
             if (depName === 'node') {
-              dep.purl = 'pkg:github/nodejs/node?clean=true';
+              dep.purl = 'pkg:github/nodejs/node?sanitize=true';
             } else if (depName === 'yarn') {
               dep.purl = 'pkg:npm/yarn';
               dep.commitMessageTopic = 'Yarn';
diff --git a/lib/manager/nvm/extract.js b/lib/manager/nvm/extract.js
index 1f598f0a61..0d6e6cd389 100644
--- a/lib/manager/nvm/extract.js
+++ b/lib/manager/nvm/extract.js
@@ -8,7 +8,7 @@ function extractDependencies(content) {
   const dep = {
     depName: 'node',
     currentValue: content.trim(),
-    purl: 'pkg:github/nodejs/node?clean=true',
+    purl: 'pkg:github/nodejs/node?sanitize=true',
     versionScheme: 'semver',
   };
   if (!semver.isVersion(dep.currentValue)) {
diff --git a/lib/manager/travis/package.js b/lib/manager/travis/package.js
index 386fa903af..b52bcc327d 100644
--- a/lib/manager/travis/package.js
+++ b/lib/manager/travis/package.js
@@ -38,7 +38,7 @@ async function getPackageUpdates(config) {
   const newMajor = newValue[newValue.length - 1];
   if (config.rangeStrategy === 'pin' || isVersion(config.currentValue[0])) {
     const releases = Object.keys(
-      (await getDependency('nodejs/node', { clean: 'true' })).versions
+      (await getDependency('nodejs/node', { sanitize: 'true' })).versions
     );
     newValue = newValue.map(version =>
       maxSatisfyingVersion(releases, `${version}`)
diff --git a/test/datasource/__snapshots__/github.spec.js.snap b/test/datasource/__snapshots__/github.spec.js.snap
index a314db87c2..88f6361ed1 100644
--- a/test/datasource/__snapshots__/github.spec.js.snap
+++ b/test/datasource/__snapshots__/github.spec.js.snap
@@ -6,8 +6,6 @@ Object {
   "versions": Object {
     "1.0.0": Object {},
     "1.1.0": Object {},
-    "a": Object {},
-    "v": Object {},
   },
 }
 `;
diff --git a/test/datasource/github.spec.js b/test/datasource/github.spec.js
index 5e92ede6da..b89231ffa5 100644
--- a/test/datasource/github.spec.js
+++ b/test/datasource/github.spec.js
@@ -15,10 +15,10 @@ describe('datasource/github', () => {
       ];
       ghGot.mockReturnValueOnce({ headers: {}, body });
       const res = await datasource.getDependency(
-        'pkg:github/some/dep?clean=true'
+        'pkg:github/some/dep?sanitize=true'
       );
       expect(res).toMatchSnapshot();
-      expect(Object.keys(res.versions)).toHaveLength(4);
+      expect(Object.keys(res.versions)).toHaveLength(2);
       expect(res.versions['1.1.0']).toBeDefined();
     });
     it('returns releases', async () => {
diff --git a/test/manager/npm/extract/__snapshots__/index.spec.js.snap b/test/manager/npm/extract/__snapshots__/index.spec.js.snap
index d714d53e51..5d102ec103 100644
--- a/test/manager/npm/extract/__snapshots__/index.spec.js.snap
+++ b/test/manager/npm/extract/__snapshots__/index.spec.js.snap
@@ -62,7 +62,7 @@ Object {
       "major": Object {
         "enabled": false,
       },
-      "purl": "pkg:github/nodejs/node?clean=true",
+      "purl": "pkg:github/nodejs/node?sanitize=true",
       "versionScheme": "semver",
     },
     Object {
diff --git a/test/manager/nvm/__snapshots__/extract.spec.js.snap b/test/manager/nvm/__snapshots__/extract.spec.js.snap
index 2596e50c26..b87a2497c6 100644
--- a/test/manager/nvm/__snapshots__/extract.spec.js.snap
+++ b/test/manager/nvm/__snapshots__/extract.spec.js.snap
@@ -5,7 +5,7 @@ Array [
   Object {
     "currentValue": "8.4.0",
     "depName": "node",
-    "purl": "pkg:github/nodejs/node?clean=true",
+    "purl": "pkg:github/nodejs/node?sanitize=true",
     "versionScheme": "semver",
   },
 ]
@@ -16,7 +16,7 @@ Array [
   Object {
     "currentValue": "8.4",
     "depName": "node",
-    "purl": "pkg:github/nodejs/node?clean=true",
+    "purl": "pkg:github/nodejs/node?sanitize=true",
     "skipReason": "unsupported-version",
     "versionScheme": "semver",
   },
-- 
GitLab