From aba9a435432c899e19661e4f38db841dccd6239e Mon Sep 17 00:00:00 2001
From: Ankit Soneji <ankit.soneji@gmail.com>
Date: Tue, 30 Nov 2021 23:47:16 -0800
Subject: [PATCH] feat: add git@ support to message github url method (#12899)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 lib/datasource/metadata.spec.ts | 28 +++++++++++++++++++++++++++-
 lib/datasource/metadata.ts      | 11 +++++++++--
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/lib/datasource/metadata.spec.ts b/lib/datasource/metadata.spec.ts
index 81fceb357f..fff49ac554 100644
--- a/lib/datasource/metadata.spec.ts
+++ b/lib/datasource/metadata.spec.ts
@@ -1,5 +1,5 @@
 import * as datasourceMaven from './maven';
-import { addMetaData } from './metadata';
+import { addMetaData, massageGithubUrl } from './metadata';
 import * as datasourceNpm from './npm';
 import { PypiDatasource } from './pypi';
 import type { ReleaseResult } from './types';
@@ -227,4 +227,30 @@ describe('datasource/metadata', () => {
       { releaseTimestamp: '2000-01-03T12:34:56.000Z' },
     ]);
   });
+
+  it('Should massage github git@ url to valid https url', () => {
+    expect(massageGithubUrl('git@example.com:foo/bar')).toMatch(
+      'https://example.com/foo/bar'
+    );
+  });
+  it('Should massage github http url to valid https url', () => {
+    expect(massageGithubUrl('http://example.com/foo/bar')).toMatch(
+      'https://example.com/foo/bar'
+    );
+  });
+  it('Should massage github http and git url to valid https url', () => {
+    expect(massageGithubUrl('http+git://example.com/foo/bar')).toMatch(
+      'https://example.com/foo/bar'
+    );
+  });
+  it('Should massage github ssh git@ url to valid https url', () => {
+    expect(massageGithubUrl('ssh://git@example.com/foo/bar')).toMatch(
+      'https://example.com/foo/bar'
+    );
+  });
+  it('Should massage github git url to valid https url', () => {
+    expect(massageGithubUrl('git://example.com/foo/bar')).toMatch(
+      'https://example.com/foo/bar'
+    );
+  });
 });
diff --git a/lib/datasource/metadata.ts b/lib/datasource/metadata.ts
index d9685047d4..35cc8d50e2 100644
--- a/lib/datasource/metadata.ts
+++ b/lib/datasource/metadata.ts
@@ -110,11 +110,18 @@ const manualSourceUrls = {
 const githubPages = regEx('^https://([^.]+).github.com/([^/]+)$');
 const gitPrefix = regEx('^git:/?/?');
 
-function massageGithubUrl(url: string): string {
-  return url
+export function massageGithubUrl(url: string): string {
+  let massagedUrl = url;
+
+  if (url.startsWith('git@')) {
+    massagedUrl = url.replace(':', '/').replace('git@', 'https://');
+  }
+
+  return massagedUrl
     .replace('http:', 'https:')
     .replace('http+git:', 'https:')
     .replace('https+git:', 'https:')
+    .replace('ssh://git@', 'https://')
     .replace(gitPrefix, 'https://')
     .replace(githubPages, 'https://github.com/$1/$2')
     .replace('www.github.com', 'github.com')
-- 
GitLab