diff --git a/lib/datasource/index.js b/lib/datasource/index.js index b8d8c6dce70416477093d7ea5cd5f1e6f055d6df..73bf6d18be79ad0249fa815781baf1b3146ba9ae 100644 --- a/lib/datasource/index.js +++ b/lib/datasource/index.js @@ -20,6 +20,8 @@ const datasources = { terraform, }; +// Use this object to define changelog URLs for packages +// Only necessary when the changelog data cannot be found in the package's source repository const manualChangelogUrls = { npm: { firebase: 'https://firebase.google.com/support/release-notes/js', @@ -46,6 +48,23 @@ const manualChangelogUrls = { }, }; +// Use this object to define manual source URLs for packages +// Only necessary if the datasource is unable to locate the source URL itself +const manualSourceUrls = { + docker: { + node: 'https://github.com/nodejs/node', + }, + kubernetes: { + node: 'https://github.com/nodejs/node', + }, + npm: { + node: 'https://github.com/nodejs/node', + }, + nvm: { + node: 'https://github.com/nodejs/node', + }, +}; + async function getPkgReleases(purlStr, config) { const purl = parse(purlStr); if (!purl) { @@ -64,6 +83,12 @@ async function getPkgReleases(purlStr, config) { res.changelogUrl = manualChangelogUrls[purl.type][purl.fullname.toLowerCase()]; } + if ( + manualSourceUrls[purl.type] && + manualSourceUrls[purl.type][purl.fullname.toLowerCase()] + ) { + res.sourceUrl = manualSourceUrls[purl.type][purl.fullname.toLowerCase()]; + } if ( !res.sourceUrl && res.changelogUrl && diff --git a/test/datasource/__snapshots__/index.spec.js.snap b/test/datasource/__snapshots__/index.spec.js.snap index e97f57546659ab21e2c2ba501b321e7ee08ba0e3..1d664daa3b54de012bbdd25e99047ffec29cece7 100644 --- a/test/datasource/__snapshots__/index.spec.js.snap +++ b/test/datasource/__snapshots__/index.spec.js.snap @@ -6,3 +6,9 @@ Object { "sourceUrl": "https://github.com/react-native-community/react-native-releases", } `; + +exports[`datasource/index adds sourceUrl 1`] = ` +Object { + "sourceUrl": "https://github.com/nodejs/node", +} +`; diff --git a/test/datasource/index.spec.js b/test/datasource/index.spec.js index 14b1e163e69b899bc97a04e87c217960fdffee92..ef91beeeede964f358fe02dd6a41bc234f1614cb 100644 --- a/test/datasource/index.spec.js +++ b/test/datasource/index.spec.js @@ -20,4 +20,10 @@ describe('datasource/index', () => { expect(res.changelogUrl).toBeDefined(); expect(res.sourceUrl).toBeDefined(); }); + it('adds sourceUrl', async () => { + npmDatasource.getPkgReleases.mockReturnValue({}); + const res = await datasource.getPkgReleases('pkg:npm/node'); + expect(res).toMatchSnapshot(); + expect(res.sourceUrl).toBeDefined(); + }); }); diff --git a/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap b/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap index 9227602e958f395ef0e829a61780e389ab156306..d8eb066b2dd80a6663df4ba84945c6c1e1e91fae 100644 --- a/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap +++ b/test/workers/repository/process/lookup/__snapshots__/index.spec.js.snap @@ -88,7 +88,7 @@ Object { "version": "8.1.0", }, ], - "sourceUrl": null, + "sourceUrl": "https://github.com/nodejs/node", "updates": Array [ Object { "blockedByPin": true, @@ -134,7 +134,7 @@ Object { "changelogUrl": undefined, "homepage": undefined, "releases": Array [], - "sourceUrl": null, + "sourceUrl": "https://github.com/nodejs/node", "updates": Array [ Object { "newDigest": "sha256:abcdef1234567890", @@ -159,7 +159,7 @@ Object { "version": "8.1.0", }, ], - "sourceUrl": null, + "sourceUrl": "https://github.com/nodejs/node", "updates": Array [ Object { "canBeUnpublished": undefined, @@ -859,7 +859,7 @@ Object { "version": "9", }, ], - "sourceUrl": null, + "sourceUrl": "https://github.com/nodejs/node", "updates": Array [ Object { "canBeUnpublished": undefined, @@ -893,7 +893,7 @@ Object { "version": "9.0", }, ], - "sourceUrl": null, + "sourceUrl": "https://github.com/nodejs/node", "updates": Array [ Object { "canBeUnpublished": undefined, @@ -942,7 +942,7 @@ Object { "version": "8.2.5", }, ], - "sourceUrl": null, + "sourceUrl": "https://github.com/nodejs/node", "updates": Array [ Object { "canBeUnpublished": undefined,