diff --git a/lib/datasource/metadata.spec.ts b/lib/datasource/metadata.spec.ts index 81fceb357fe9514c64ac435c239d2903a89d3947..fff49ac554366dcbee50f3ad879aa00329d1f2cb 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 d9685047d49807982c7a2b0cc9a04c44b45f99bc..35cc8d50e2ff81583d61d492e90b5fafb5e51a90 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')