From 7356fedefb635af59893f2c4e2d25b8984160b1d Mon Sep 17 00:00:00 2001
From: Jonas Rutishauser <jonas.rutishauser@alumni.ethz.ch>
Date: Mon, 12 Feb 2024 14:31:44 +0100
Subject: [PATCH] feat(manager/helmfile): Support oci urls in helmfile (#27126)

---
 lib/modules/manager/helmfile/extract.spec.ts | 10 ++++++++++
 lib/modules/manager/helmfile/extract.ts      | 20 +++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lib/modules/manager/helmfile/extract.spec.ts b/lib/modules/manager/helmfile/extract.spec.ts
index abbddc6bad..315412754b 100644
--- a/lib/modules/manager/helmfile/extract.spec.ts
+++ b/lib/modules/manager/helmfile/extract.spec.ts
@@ -319,6 +319,9 @@ describe('modules/manager/helmfile/extract', () => {
         - name: jenkins
           chart: jenkins/jenkins
           version: 3.3.0
+        - name: oci-url
+          version: 0.4.2
+          chart: oci://ghcr.io/example/oci-repo/url-example
       `;
       const fileName = 'helmfile.yaml';
       const result = await extractPackageFile(content, fileName, {
@@ -338,6 +341,13 @@ describe('modules/manager/helmfile/extract', () => {
           {
             currentValue: '3.3.0',
             depName: 'jenkins',
+            registryUrls: ['https://charts.jenkins.io'],
+          },
+          {
+            currentValue: '0.4.2',
+            depName: 'url-example',
+            datasource: 'docker',
+            packageName: 'ghcr.io/example/oci-repo/url-example',
           },
         ],
       });
diff --git a/lib/modules/manager/helmfile/extract.ts b/lib/modules/manager/helmfile/extract.ts
index e570afe4f4..fa34d53900 100644
--- a/lib/modules/manager/helmfile/extract.ts
+++ b/lib/modules/manager/helmfile/extract.ts
@@ -24,6 +24,10 @@ function isLocalPath(possiblePath: string): boolean {
   );
 }
 
+function isOciUrl(possibleUrl: string): boolean {
+  return possibleUrl.startsWith('oci://');
+}
+
 export async function extractPackageFile(
   content: string,
   packageFile: string,
@@ -100,7 +104,11 @@ export async function extractPackageFile(
         dep.version = String(dep.version);
       }
 
-      if (dep.chart.includes('/')) {
+      if (isOciUrl(dep.chart)) {
+        const v = dep.chart.substring(6).split('/');
+        depName = v.pop()!;
+        repoName = v.join('/');
+      } else if (dep.chart.includes('/')) {
         const v = dep.chart.split('/');
         repoName = v.shift()!;
         depName = v.join('/');
@@ -130,7 +138,10 @@ export async function extractPackageFile(
       const repository = doc.repositories?.find(
         (repo) => repo.name === repoName,
       );
-      if (repository?.oci) {
+      if (isOciUrl(dep.chart)) {
+        res.datasource = DockerDatasource.id;
+        res.packageName = repoName + '/' + depName;
+      } else if (repository?.oci) {
         res.datasource = DockerDatasource.id;
         res.packageName = registryAliases[repoName] + '/' + depName;
       }
@@ -142,7 +153,10 @@ export async function extractPackageFile(
       }
 
       // Skip in case we cannot locate the registry
-      if (is.emptyArray(res.registryUrls)) {
+      if (
+        res.datasource !== DockerDatasource.id &&
+        is.emptyArray(res.registryUrls)
+      ) {
         res.skipReason = 'unknown-registry';
       }
 
-- 
GitLab