From 31988947b4359798fe532ccd57e30cf801e686d0 Mon Sep 17 00:00:00 2001
From: Sebastian Poxhofer <secustor@users.noreply.github.com>
Date: Fri, 3 Nov 2023 10:02:26 +0100
Subject: [PATCH] fix(manager/ansible-galaxy): handle collections with http git
 references (#25568)

---
 .../manager/ansible-galaxy/__fixtures__/collections1.yml   | 6 ++++++
 .../ansible-galaxy/__snapshots__/extract.spec.ts.snap      | 7 +++++++
 lib/modules/manager/ansible-galaxy/collections.ts          | 2 +-
 lib/modules/manager/ansible-galaxy/extract.spec.ts         | 4 ++--
 4 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/modules/manager/ansible-galaxy/__fixtures__/collections1.yml b/lib/modules/manager/ansible-galaxy/__fixtures__/collections1.yml
index f6a857277b..7f40d32010 100644
--- a/lib/modules/manager/ansible-galaxy/__fixtures__/collections1.yml
+++ b/lib/modules/manager/ansible-galaxy/__fixtures__/collections1.yml
@@ -25,6 +25,12 @@ collections:
     version: 1.2.2
     type: git
 
+  # explicit git repo
+  - name: namespace.mycollection
+    version: 3.0.0
+    type: git
+    source: https://example.com/organization/repo_name.git
+
 # appendix style version definition
   - name: https://example.com/organization/repo_name.git,1.2.2
 
diff --git a/lib/modules/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap
index feb715ef9c..e7d85ef032 100644
--- a/lib/modules/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap
+++ b/lib/modules/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap
@@ -32,6 +32,13 @@ exports[`modules/manager/ansible-galaxy/extract extractPackageFile() check colle
     "depType": "galaxy-collection",
     "packageName": "https://example.com/organization/repo_name.git",
   },
+  {
+    "currentValue": "3.0.0",
+    "datasource": "git-tags",
+    "depName": "namespace.mycollection",
+    "depType": "galaxy-collection",
+    "packageName": "https://example.com/organization/repo_name.git",
+  },
   {
     "currentValue": "1.2.2",
     "datasource": "git-tags",
diff --git a/lib/modules/manager/ansible-galaxy/collections.ts b/lib/modules/manager/ansible-galaxy/collections.ts
index f84bf3bd3a..0846b3da53 100644
--- a/lib/modules/manager/ansible-galaxy/collections.ts
+++ b/lib/modules/manager/ansible-galaxy/collections.ts
@@ -30,7 +30,7 @@ function interpretLine(
     }
     case 'source': {
       localDependency.managerData.source = value;
-      if (value?.startsWith('git@')) {
+      if (value?.startsWith('git@') || value?.endsWith('.git')) {
         localDependency.packageName = value;
       } else {
         localDependency.registryUrls = value
diff --git a/lib/modules/manager/ansible-galaxy/extract.spec.ts b/lib/modules/manager/ansible-galaxy/extract.spec.ts
index dd1e0f95b8..13c6f630fb 100644
--- a/lib/modules/manager/ansible-galaxy/extract.spec.ts
+++ b/lib/modules/manager/ansible-galaxy/extract.spec.ts
@@ -31,7 +31,7 @@ describe('modules/manager/ansible-galaxy/extract', () => {
     it('extracts dependencies from requirements.yml with a space at the end of line', () => {
       const yamlFile = codeBlock`collections:
       - name: https://github.com/lowlydba/lowlydba.sqlserver.git
-      type: git 
+      type: git
       version: 1.1.3`;
       const res = extractPackageFile(yamlFile, 'requirements.yml');
       expect(res?.deps).toHaveLength(1);
@@ -66,7 +66,7 @@ describe('modules/manager/ansible-galaxy/extract', () => {
     it('check collection style requirements file', () => {
       const res = extractPackageFile(collections1, 'requirements.yml');
       expect(res?.deps).toMatchSnapshot();
-      expect(res?.deps).toHaveLength(13);
+      expect(res?.deps).toHaveLength(14);
       expect(res?.deps.filter((value) => value.skipReason)).toHaveLength(6);
     });
 
-- 
GitLab