feat: add git@ support to message github url method (#12899)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Ankit Soneji 2021-11-30 23:47:16 -08:00 committed by GitHub
parent c42faf0fec
commit aba9a43543
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 3 deletions

View file

@ -1,5 +1,5 @@
import * as datasourceMaven from './maven'; import * as datasourceMaven from './maven';
import { addMetaData } from './metadata'; import { addMetaData, massageGithubUrl } from './metadata';
import * as datasourceNpm from './npm'; import * as datasourceNpm from './npm';
import { PypiDatasource } from './pypi'; import { PypiDatasource } from './pypi';
import type { ReleaseResult } from './types'; import type { ReleaseResult } from './types';
@ -227,4 +227,30 @@ describe('datasource/metadata', () => {
{ releaseTimestamp: '2000-01-03T12:34:56.000Z' }, { 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'
);
});
}); });

View file

@ -110,11 +110,18 @@ const manualSourceUrls = {
const githubPages = regEx('^https://([^.]+).github.com/([^/]+)$'); const githubPages = regEx('^https://([^.]+).github.com/([^/]+)$');
const gitPrefix = regEx('^git:/?/?'); const gitPrefix = regEx('^git:/?/?');
function massageGithubUrl(url: string): string { export function massageGithubUrl(url: string): string {
return url let massagedUrl = url;
if (url.startsWith('git@')) {
massagedUrl = url.replace(':', '/').replace('git@', 'https://');
}
return massagedUrl
.replace('http:', 'https:') .replace('http:', 'https:')
.replace('http+git:', 'https:') .replace('http+git:', 'https:')
.replace('https+git:', 'https:') .replace('https+git:', 'https:')
.replace('ssh://git@', 'https://')
.replace(gitPrefix, 'https://') .replace(gitPrefix, 'https://')
.replace(githubPages, 'https://github.com/$1/$2') .replace(githubPages, 'https://github.com/$1/$2')
.replace('www.github.com', 'github.com') .replace('www.github.com', 'github.com')