From 0b160f6a270d5c31d8bd552d8a18707e299218ec Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Fri, 17 Apr 2020 20:42:16 +0200
Subject: [PATCH] fix(docker): detect if registryUrls is prefix of lookupName

---
 .../docker/__snapshots__/index.spec.ts.snap           |  7 +++++++
 lib/datasource/docker/index.spec.ts                   |  7 +++++++
 lib/datasource/docker/index.ts                        | 11 +++++++++++
 3 files changed, 25 insertions(+)

diff --git a/lib/datasource/docker/__snapshots__/index.spec.ts.snap b/lib/datasource/docker/__snapshots__/index.spec.ts.snap
index 84626fcb48..abba07ed47 100644
--- a/lib/datasource/docker/__snapshots__/index.spec.ts.snap
+++ b/lib/datasource/docker/__snapshots__/index.spec.ts.snap
@@ -7,6 +7,13 @@ Object {
 }
 `;
 
+exports[`api/docker getRegistryRepository supports registryUrls 1`] = `
+Object {
+  "registry": "my.local.registry/prefix/",
+  "repository": "image",
+}
+`;
+
 exports[`api/docker getReleases adds library/ prefix for Docker Hub (explicit) 1`] = `
 [MockFunction] {
   "calls": Array [
diff --git a/lib/datasource/docker/index.spec.ts b/lib/datasource/docker/index.spec.ts
index e6eaa4628d..24909e0b85 100644
--- a/lib/datasource/docker/index.spec.ts
+++ b/lib/datasource/docker/index.spec.ts
@@ -18,6 +18,13 @@ describe('api/docker', () => {
       const res = docker.getRegistryRepository('registry:5000/org/package', []);
       expect(res).toMatchSnapshot();
     });
+    it('supports registryUrls', () => {
+      const res = docker.getRegistryRepository(
+        'my.local.registry/prefix/image',
+        ['https://my.local.registry/prefix']
+      );
+      expect(res).toMatchSnapshot();
+    });
   });
   describe('getDigest', () => {
     beforeEach(() => {
diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts
index 9af8dec520..bd6906f548 100644
--- a/lib/datasource/docker/index.ts
+++ b/lib/datasource/docker/index.ts
@@ -60,6 +60,17 @@ export function getRegistryRepository(
   lookupName: string,
   registryUrls: string[]
 ): RegistryRepository {
+  if (is.nonEmptyArray(registryUrls)) {
+    const dockerRegistry = registryUrls[0]
+      .replace('https://', '')
+      .replace(/\/?$/, '/');
+    if (lookupName.startsWith(dockerRegistry)) {
+      return {
+        registry: dockerRegistry,
+        repository: lookupName.replace(dockerRegistry, ''),
+      };
+    }
+  }
   let registry: string;
   const split = lookupName.split('/');
   if (split.length > 1 && (split[0].includes('.') || split[0].includes(':'))) {
-- 
GitLab