diff --git a/lib/datasource/index.js b/lib/datasource/index.js index 2622b46da88c402e0f6b0ab3fabec2a445d9b72e..b8d8c6dce70416477093d7ea5cd5f1e6f055d6df 100644 --- a/lib/datasource/index.js +++ b/lib/datasource/index.js @@ -20,7 +20,33 @@ const datasources = { terraform, }; -function getPkgReleases(purlStr, config) { +const manualChangelogUrls = { + npm: { + firebase: 'https://firebase.google.com/support/release-notes/js', + 'flow-bin': 'https://github.com/facebook/flow/blob/master/Changelog.md', + 'react-native': + 'https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md', + }, + pypi: { + 'pytest-django': + 'https://pytest-django.readthedocs.io/en/latest/changelog.html#changelog', + django: 'https://github.com/django/django/tree/master/docs/releases', + djangorestframework: + 'https://www.django-rest-framework.org/community/release-notes/', + flake8: 'http://flake8.pycqa.org/en/latest/release-notes/index.html', + 'django-storages': + 'https://github.com/jschneier/django-storages/blob/master/CHANGELOG.rst', + phonenumbers: + 'https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/HISTORY.md', + 'psycopg2-binary': 'http://initd.org/psycopg/articles/tag/release/', + 'django-debug-toolbar': + 'https://django-debug-toolbar.readthedocs.io/en/latest/changes.html', + 'firebase-admin': + 'https://firebase.google.com/support/release-notes/admin/python', + }, +}; + +async function getPkgReleases(purlStr, config) { const purl = parse(purlStr); if (!purl) { return null; @@ -29,7 +55,27 @@ function getPkgReleases(purlStr, config) { logger.warn('Unknown purl type: ' + purl.type); return null; } - return datasources[purl.type].getPkgReleases(purl, config); + const res = await datasources[purl.type].getPkgReleases(purl, config); + if (res) { + if ( + manualChangelogUrls[purl.type] && + manualChangelogUrls[purl.type][purl.fullname.toLowerCase()] + ) { + res.changelogUrl = + manualChangelogUrls[purl.type][purl.fullname.toLowerCase()]; + } + if ( + !res.sourceUrl && + res.changelogUrl && + res.changelogUrl.startsWith('https://github.com/') + ) { + res.sourceUrl = res.changelogUrl + .split('/') + .slice(0, 5) + .join('/'); + } + } + return res; } function supportsDigests(purlStr) { diff --git a/lib/datasource/npm.js b/lib/datasource/npm.js index 4bb14038dc76edfdff2f31c0c8a5a683797b7689..a6b61524d2db85474798466f3ecee936d90bc61b 100644 --- a/lib/datasource/npm.js +++ b/lib/datasource/npm.js @@ -37,14 +37,6 @@ function resetCache() { resetMemCache(); } -// This is a manual list of changelog URLs for dependencies that don't publish to sourceUrl -const changelogUrls = { - firebase: 'https://firebase.google.com/support/release-notes/js', - 'flow-bin': 'https://github.com/facebook/flow/blob/master/Changelog.md', - 'react-native': - 'https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md', -}; - // istanbul ignore next function maskToken(token) { // istanbul ignore if @@ -136,10 +128,6 @@ async function getPkgReleases(input, config) { res.tags = res['dist-tags']; delete res['dist-tags']; delete res['renovate-config']; - // istanbul ignore if - if (changelogUrls[purl.fullname]) { - res.changelogUrl = changelogUrls[purl.fullname] || res.changelogUrl; - } } return res; } diff --git a/lib/datasource/pypi.js b/lib/datasource/pypi.js index 6f33f7a398ea7b295f00718191c9b5aae9e2a7ec..e265b9237d2a8f89dd398aa1919f662064a89aec 100644 --- a/lib/datasource/pypi.js +++ b/lib/datasource/pypi.js @@ -11,26 +11,6 @@ function normalizeName(input) { return input.toLowerCase().replace(/(-|\.)/g, '_'); } -// This is a manual list of changelog URLs for dependencies that don't publish to sourceUrl -// Make these lower case -const changelogUrls = { - 'pytest-django': - 'https://pytest-django.readthedocs.io/en/latest/changelog.html#changelog', - django: 'https://github.com/django/django/tree/master/docs/releases', - djangorestframework: - 'https://www.django-rest-framework.org/community/release-notes/', - flake8: 'http://flake8.pycqa.org/en/latest/release-notes/index.html', - 'django-storages': - 'https://github.com/jschneier/django-storages/blob/master/CHANGELOG.rst', - phonenumbers: - 'https://github.com/daviddrysdale/python-phonenumbers/blob/dev/python/HISTORY.md', - 'psycopg2-binary': 'http://initd.org/psycopg/articles/tag/release/', - 'django-debug-toolbar': - 'https://django-debug-toolbar.readthedocs.io/en/latest/changes.html', - 'firebase-admin': - 'https://firebase.google.com/support/release-notes/admin/python', -}; - function compatibleVersions(releases, compatibility) { const versions = Object.keys(releases) .filter(isVersion) @@ -112,20 +92,6 @@ async function getDependency(depName, hostUrl, compatibility) { releaseTimestamp: (dep.releases[version][0] || {}).upload_time, })); } - // istanbul ignore if - if (changelogUrls[depName.toLowerCase()]) { - dependency.changelogUrl = - changelogUrls[depName.toLowerCase()] || dependency.changelogUrl; - if ( - !dependency.sourceUrl && - dependency.changelogUrl.startsWith('https://github.com/') - ) { - dependency.sourceUrl = dependency.changelogUrl - .split('/') - .slice(0, 5) - .join('/'); - } - } return dependency; } catch (err) { logger.info( diff --git a/test/datasource/__snapshots__/index.spec.js.snap b/test/datasource/__snapshots__/index.spec.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..e97f57546659ab21e2c2ba501b321e7ee08ba0e3 --- /dev/null +++ b/test/datasource/__snapshots__/index.spec.js.snap @@ -0,0 +1,8 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`datasource/index adds changelogUrl 1`] = ` +Object { + "changelogUrl": "https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md", + "sourceUrl": "https://github.com/react-native-community/react-native-releases", +} +`; diff --git a/test/datasource/index.spec.js b/test/datasource/index.spec.js index 31059e29a3d4f3c0390244340f007f40bfad257f..14b1e163e69b899bc97a04e87c217960fdffee92 100644 --- a/test/datasource/index.spec.js +++ b/test/datasource/index.spec.js @@ -1,6 +1,8 @@ const datasource = require('../../lib/datasource'); +const npmDatasource = require('../../lib/datasource/npm'); jest.mock('../../lib/datasource/docker'); +jest.mock('../../lib/datasource/npm'); describe('datasource/index', () => { it('returns null for invalid purl', async () => { @@ -11,4 +13,11 @@ describe('datasource/index', () => { await datasource.getDigest({ purl: 'pkg:docker/node' }) ).toBeUndefined(); }); + it('adds changelogUrl', async () => { + npmDatasource.getPkgReleases.mockReturnValue({}); + const res = await datasource.getPkgReleases('pkg:npm/react-native'); + expect(res).toMatchSnapshot(); + expect(res.changelogUrl).toBeDefined(); + expect(res.sourceUrl).toBeDefined(); + }); });