From a0b8b87c74928bb5339b5c92f985eaad00f056a3 Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Tue, 12 May 2020 19:07:25 +0200
Subject: [PATCH] fix(manager): support newer kustomize urls (#6206)

---
 .../kustomize/__fixtures__/kustomizeHttp.yaml |  4 ++++
 .../__snapshots__/extract.spec.ts.snap        |  6 ++++++
 lib/manager/kustomize/extract.spec.ts         | 20 ++++++++++++++++++-
 lib/manager/kustomize/extract.ts              | 16 +++++++++++++++
 4 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/lib/manager/kustomize/__fixtures__/kustomizeHttp.yaml b/lib/manager/kustomize/__fixtures__/kustomizeHttp.yaml
index cea2d09d13..3f93c9f348 100644
--- a/lib/manager/kustomize/__fixtures__/kustomizeHttp.yaml
+++ b/lib/manager/kustomize/__fixtures__/kustomizeHttp.yaml
@@ -3,8 +3,12 @@ kind: Kustomization
 
 bases:
 - github.com/user/repo//deploy?ref=v0.0.1
+- github.com/fluxcd/flux/deploy?ref=1.19.0
 
 namespace: testing-namespace
 
 resources:
 - deployment.yaml
+
+images:
+- name: nginx
diff --git a/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap b/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap
index 746ff1bb98..270deb2d3e 100644
--- a/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/kustomize/__snapshots__/extract.spec.ts.snap
@@ -8,6 +8,12 @@ Array [
     "depName": "github.com/user/repo//deploy",
     "lookupName": "github.com/user/repo",
   },
+  Object {
+    "currentValue": "1.19.0",
+    "datasource": "github-tags",
+    "depName": "fluxcd/flux/deploy",
+    "lookupName": "fluxcd/flux",
+  },
 ]
 `;
 
diff --git a/lib/manager/kustomize/extract.spec.ts b/lib/manager/kustomize/extract.spec.ts
index a0e22f72f6..3f83e2bea5 100644
--- a/lib/manager/kustomize/extract.spec.ts
+++ b/lib/manager/kustomize/extract.spec.ts
@@ -1,6 +1,7 @@
 import { readFileSync } from 'fs';
 import * as datasourceDocker from '../../datasource/docker';
 import * as datasourceGitTags from '../../datasource/git-tags';
+import * as datasourceGitHubTags from '../../datasource/github-tags';
 import {
   extractBase,
   extractImage,
@@ -70,6 +71,20 @@ describe('manager/kustomize/extract', () => {
       const pkg = extractBase(`${base}?ref=${version}`);
       expect(pkg).toEqual(sample);
     });
+
+    it('should extract out the version of an github base', () => {
+      const base = 'fluxcd/flux/deploy';
+      const version = 'v1.0.0';
+      const sample = {
+        currentValue: version,
+        datasource: datasourceGitHubTags.id,
+        depName: base,
+        lookupName: 'fluxcd/flux',
+      };
+
+      const pkg = extractBase(`github.com/${base}?ref=${version}`);
+      expect(pkg).toEqual(sample);
+    });
     it('should extract out the version of a git base', () => {
       const base = 'git@github.com:user/repo.git';
       const version = 'v1.0.0';
@@ -193,8 +208,11 @@ describe('manager/kustomize/extract', () => {
     it('extracts http dependency', () => {
       const res = extractPackageFile(kustomizeHTTP);
       expect(res.deps).toMatchSnapshot();
-      expect(res.deps).toHaveLength(1);
+      expect(res.deps).toHaveLength(2);
       expect(res.deps[0].currentValue).toEqual('v0.0.1');
+      expect(res.deps[1].currentValue).toEqual('1.19.0');
+      expect(res.deps[1].depName).toEqual('fluxcd/flux/deploy');
+      expect(res.deps[1].lookupName).toEqual('fluxcd/flux');
     });
     it('should extract out image versions', () => {
       const res = extractPackageFile(gitImages);
diff --git a/lib/manager/kustomize/extract.ts b/lib/manager/kustomize/extract.ts
index d0b629ff75..b9a8f8a956 100644
--- a/lib/manager/kustomize/extract.ts
+++ b/lib/manager/kustomize/extract.ts
@@ -1,6 +1,7 @@
 import { safeLoad } from 'js-yaml';
 import * as datasourceDocker from '../../datasource/docker';
 import * as datasourceGitTags from '../../datasource/git-tags';
+import * as datasourceGitHubTags from '../../datasource/github-tags';
 import { logger } from '../../logger';
 import { PackageDependency, PackageFile } from '../common';
 
@@ -21,7 +22,22 @@ const versionMatch = /(?<basename>.*)\?ref=(?<version>.*)\s*$/;
 // extract the url from the base of a url with a subdir
 const extractUrl = /^(?<url>.*)(?:\/\/.*)$/;
 
+const githubUrl = /^github\.com\/(?<depName>(?<lookupName>[^/]+?\/[^/]+?)(?:\/[^/]+?)*)\?ref=(?<currentValue>.+)$/;
+
 export function extractBase(base: string): PackageDependency | null {
+  const githubMatch = githubUrl.exec(base);
+
+  if (githubMatch?.groups) {
+    const { currentValue, depName, lookupName } = githubMatch.groups;
+
+    return {
+      datasource: datasourceGitHubTags.id,
+      depName,
+      lookupName,
+      currentValue,
+    };
+  }
+
   const basenameVersion = versionMatch.exec(base);
   if (basenameVersion) {
     const currentValue = basenameVersion.groups.version;
-- 
GitLab