From 1d661b909b18b5a09dc4b099c72cbd5397a6bb57 Mon Sep 17 00:00:00 2001
From: Sebastian Poxhofer <secustor@users.noreply.github.com>
Date: Mon, 16 Mar 2020 09:51:12 +0100
Subject: [PATCH] fix(ansible-galaxy): allow usage of ssh:// style git urls
 (#5700)

---
 .../__fixtures__/requirements01.yml            | 14 ++++++++++++++
 .../__snapshots__/extract.spec.ts.snap         | 18 ++++++++++++++++++
 lib/manager/ansible-galaxy/extract.spec.ts     |  2 +-
 lib/manager/ansible-galaxy/extract.ts          |  2 +-
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/lib/manager/ansible-galaxy/__fixtures__/requirements01.yml b/lib/manager/ansible-galaxy/__fixtures__/requirements01.yml
index 8f89b8d529..ea0ff5a7d4 100644
--- a/lib/manager/ansible-galaxy/__fixtures__/requirements01.yml
+++ b/lib/manager/ansible-galaxy/__fixtures__/requirements01.yml
@@ -16,6 +16,20 @@
   src: git@gitlab.company.com:mygroup/ansible-base.git
   version: "0.1"
 
+# Git repo, url with protocol prefix
+## with user
+- scm: git
+  src:  ssh://git@gitlab.company.com/testGroup/testProject.git
+  version: "0.1"
+## without user
+- scm: git
+  src:  ssh://gitlab.company.com/testGroup/testProject2.git
+  version: "0.1"
+## with custom port
+- scm: git
+  src:  ssh://git@gitlab.company.com:23/testGroup/testProject3.git
+  version: "3.1"
+
 # include
 - include: <path_to_requirements>/webserver.yml
 
diff --git a/lib/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap b/lib/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap
index 9b50764127..929c35432d 100644
--- a/lib/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap
+++ b/lib/manager/ansible-galaxy/__snapshots__/extract.spec.ts.snap
@@ -43,6 +43,24 @@ Array [
     "depName": "mygroup/ansible-base",
     "lookupName": "git@gitlab.company.com:mygroup/ansible-base.git",
   },
+  Object {
+    "currentValue": "0.1",
+    "datasource": "git-tags",
+    "depName": "testGroup/testProject",
+    "lookupName": "ssh://git@gitlab.company.com/testGroup/testProject.git",
+  },
+  Object {
+    "currentValue": "0.1",
+    "datasource": "git-tags",
+    "depName": "testGroup/testProject2",
+    "lookupName": "ssh://gitlab.company.com/testGroup/testProject2.git",
+  },
+  Object {
+    "currentValue": "3.1",
+    "datasource": "git-tags",
+    "depName": "testGroup/testProject3",
+    "lookupName": "ssh://git@gitlab.company.com:23/testGroup/testProject3.git",
+  },
   Object {
     "currentValue": "0.14",
     "datasource": "git-tags",
diff --git a/lib/manager/ansible-galaxy/extract.spec.ts b/lib/manager/ansible-galaxy/extract.spec.ts
index 18264580dd..830f13184f 100644
--- a/lib/manager/ansible-galaxy/extract.spec.ts
+++ b/lib/manager/ansible-galaxy/extract.spec.ts
@@ -22,7 +22,7 @@ describe('lib/manager/ansible-galaxy/extract', () => {
     it('extracts multiple dependencies from requirements.yml', () => {
       const res = extractPackageFile(yamlFile1);
       expect(res.deps).toMatchSnapshot();
-      expect(res.deps).toHaveLength(6);
+      expect(res.deps).toHaveLength(9);
     });
     it('extracts dependencies from a not beautified requirements file', () => {
       const res = extractPackageFile(yamlFile2);
diff --git a/lib/manager/ansible-galaxy/extract.ts b/lib/manager/ansible-galaxy/extract.ts
index d299cbf4c0..3fb5ccc06d 100644
--- a/lib/manager/ansible-galaxy/extract.ts
+++ b/lib/manager/ansible-galaxy/extract.ts
@@ -47,7 +47,7 @@ function finalize(dependency: PackageDependency): boolean {
 
   const source: string = dep.managerData.src;
   const sourceMatch: RegExpMatchArray = new RegExp(
-    /^(git|http|git\+http)s?(:\/\/|@).*(\/|:)(.+\/[^.]+)\/?(\.git)?$/
+    /^(git|http|git\+http|ssh)s?(:\/\/|@).*(\/|:)(.+\/[^.]+)\/?(\.git)?$/
   ).exec(source);
   if (sourceMatch) {
     dep.datasource = datasourceGitTags.id;
-- 
GitLab