Skip to content

Commit

Permalink
fix(datasource): better massage github sourceUrl (#12737)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Nov 18, 2021
1 parent e7b841a commit 01acebd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/datasource/__snapshots__/metadata.spec.ts.snap
Expand Up @@ -135,3 +135,27 @@ Object {
"sourceUrl": "https://gitlab.com/meno/dropzone",
}
`;

exports[`datasource/metadata Should massage github sourceUrls 1`] = `
Object {
"releases": Array [
Object {
"releaseTimestamp": "2018-07-13T10:14:17.000Z",
"version": "2.0.0",
},
Object {
"releaseTimestamp": "2017-10-24T10:09:16.000Z",
"version": "2.0.0.dev1",
},
Object {
"releaseTimestamp": "2019-01-20T19:59:28.000Z",
"version": "2.1.0",
},
Object {
"releaseTimestamp": "2019-07-16T18:29:00.000Z",
"version": "2.2.0",
},
],
"sourceUrl": "https://github.com/some/repo",
}
`;
22 changes: 22 additions & 0 deletions lib/datasource/metadata.spec.ts
Expand Up @@ -76,6 +76,28 @@ describe('datasource/metadata', () => {
});
});

it('Should massage github sourceUrls', () => {
const dep: ReleaseResult = {
sourceUrl: 'https://some.github.com/repo',
releases: [
{ version: '2.0.0', releaseTimestamp: '2018-07-13T10:14:17.000Z' },
{
version: '2.0.0.dev1',
releaseTimestamp: '2017-10-24T10:09:16.000Z',
},
{ version: '2.1.0', releaseTimestamp: '2019-01-20T19:59:28.000Z' },
{ version: '2.2.0', releaseTimestamp: '2019-07-16T18:29:00.000Z' },
],
};
const datasource = PypiDatasource.id;
const lookupName = 'django-filter';

addMetaData(dep, datasource, lookupName);
expect(dep).toMatchSnapshot({
sourceUrl: 'https://github.com/some/repo',
});
});

it('Should handle parsing of sourceUrls correctly for GitLab also', () => {
const dep: ReleaseResult = {
sourceUrl: 'https://gitlab.com/meno/dropzone/tree/master',
Expand Down
8 changes: 7 additions & 1 deletion lib/datasource/metadata.ts
Expand Up @@ -107,10 +107,16 @@ const manualSourceUrls = {
},
};

const githubPages = regEx('^https://([^.]+).github.com/([^/]+)$');
const gitPrefix = regEx('^git:/?/?');

function massageGithubUrl(url: string): string {
return url
.replace('http:', 'https:')
.replace(regEx(/^git:\/?\/?/), 'https://')
.replace('http+git:', 'https:')
.replace('https+git:', 'https:')
.replace(gitPrefix, 'https://')
.replace(githubPages, 'https://github.com/$1/$2')
.replace('www.github.com', 'github.com')
.split('/')
.slice(0, 5)
Expand Down

0 comments on commit 01acebd

Please sign in to comment.