From 23bb573cd18e1957f36f278889a84241d022c5cc Mon Sep 17 00:00:00 2001
From: Sebastian Poxhofer <secustor@users.noreply.github.com>
Date: Mon, 11 Sep 2023 16:09:40 +0200
Subject: [PATCH] fix(manager/argocd): allow the apiVersion to be quoted
 (#24355)

---
 lib/modules/manager/argocd/extract.spec.ts | 54 ++++++++++++++++++++++
 lib/modules/manager/argocd/extract.ts      |  3 ++
 lib/modules/manager/argocd/util.ts         |  4 +-
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/lib/modules/manager/argocd/extract.spec.ts b/lib/modules/manager/argocd/extract.spec.ts
index 003276cd78..7d6537b92d 100644
--- a/lib/modules/manager/argocd/extract.spec.ts
+++ b/lib/modules/manager/argocd/extract.spec.ts
@@ -31,6 +31,60 @@ describe('modules/manager/argocd/extract', () => {
       expect(result).toBeNull();
     });
 
+    it('return result for double quoted argoproj.io apiVersion reference', () => {
+      const result = extractPackageFile(
+        `
+apiVersion: "argoproj.io/v1alpha1"
+kind: Application
+spec:
+  source:
+    chart: kube-state-metrics
+    repoURL: https://prometheus-community.github.io/helm-charts
+    targetRevision: 2.4.1
+        `,
+        'applications.yml'
+      );
+      expect(result).toMatchObject({
+        deps: [
+          {
+            currentValue: '2.4.1',
+            datasource: 'helm',
+            depName: 'kube-state-metrics',
+            registryUrls: [
+              'https://prometheus-community.github.io/helm-charts',
+            ],
+          },
+        ],
+      });
+    });
+
+    it('return result for single quoted argoproj.io apiVersion reference', () => {
+      const result = extractPackageFile(
+        `
+apiVersion: 'argoproj.io/v1alpha1'
+kind: Application
+spec:
+  source:
+    chart: kube-state-metrics
+    repoURL: https://prometheus-community.github.io/helm-charts
+    targetRevision: 2.4.1
+        `,
+        'applications.yml'
+      );
+      expect(result).toMatchObject({
+        deps: [
+          {
+            currentValue: '2.4.1',
+            datasource: 'helm',
+            depName: 'kube-state-metrics',
+            registryUrls: [
+              'https://prometheus-community.github.io/helm-charts',
+            ],
+          },
+        ],
+      });
+    });
+
     it('full test', () => {
       const result = extractPackageFile(validApplication, 'applications.yml');
       expect(result).toEqual({
diff --git a/lib/modules/manager/argocd/extract.ts b/lib/modules/manager/argocd/extract.ts
index 92947d8ce8..4bdb704d78 100644
--- a/lib/modules/manager/argocd/extract.ts
+++ b/lib/modules/manager/argocd/extract.ts
@@ -25,6 +25,9 @@ export function extractPackageFile(
 ): PackageFileContent | null {
   // check for argo reference. API version for the kind attribute is used
   if (fileTestRegex.test(content) === false) {
+    logger.debug(
+      `Skip file ${packageFile} as no argoproj.io apiVersion could be found in matched file`
+    );
     return null;
   }
 
diff --git a/lib/modules/manager/argocd/util.ts b/lib/modules/manager/argocd/util.ts
index 6bc7fd344b..720db2bddf 100644
--- a/lib/modules/manager/argocd/util.ts
+++ b/lib/modules/manager/argocd/util.ts
@@ -3,5 +3,5 @@ import { regEx } from '../../../util/regex';
 export const keyValueExtractionRegex = regEx(
   /^\s*(?<key>[^\s]+):\s+"?(?<value>[^"\s]+)"?\s*$/
 );
-// looks for `apiVersion: argoproj.io/
-export const fileTestRegex = regEx(/\s*apiVersion:\s*argoproj.io\/\s*/);
+// looks for `apiVersion: argoproj.io/` with optional quoting of the value
+export const fileTestRegex = regEx(/\s*apiVersion:\s*'?"?argoproj.io\//);
-- 
GitLab