diff --git a/lib/datasource/nuget/v2.ts b/lib/datasource/nuget/v2.ts index b0841d877935630bad3b03dd2ef0af0e60c4ad0e..ffed8c62580178617908bdb727d36710211b6eae 100644 --- a/lib/datasource/nuget/v2.ts +++ b/lib/datasource/nuget/v2.ts @@ -36,7 +36,15 @@ export async function getPkgReleases( try { const pkgIsLatestVersion = getPkgProp(pkgInfo, 'IsLatestVersion'); if (pkgIsLatestVersion === 'true') { - dep.sourceUrl = parse(getPkgProp(pkgInfo, 'ProjectUrl')); + const projectUrl = getPkgProp(pkgInfo, 'ProjectUrl'); + if (projectUrl) { + dep.sourceUrl = parse(projectUrl); + if (!dep.sourceUrl) { + // The project URL does not represent a known + // source URL, pass it on as homepage instead. + dep.homepage = projectUrl; + } + } } } catch (err) /* istanbul ignore next */ { logger.debug( diff --git a/lib/datasource/nuget/v3.ts b/lib/datasource/nuget/v3.ts index e8d4b323457f42094973f299847ac19d846b5297..1c4a446264acbe93faef06251c9ba138f966b99f 100644 --- a/lib/datasource/nuget/v3.ts +++ b/lib/datasource/nuget/v3.ts @@ -133,6 +133,11 @@ export async function getPkgReleases( } } else if (match.projectUrl) { dep.sourceUrl = parse(match.projectUrl); + if (!dep.sourceUrl) { + // The project URL does not represent a known + // source URL, pass it on as homepage instead. + dep.homepage = match.projectUrl; + } } } catch (err) /* istanbul ignore next */ { logger.debug( diff --git a/test/datasource/__snapshots__/nuget.spec.ts.snap b/test/datasource/__snapshots__/nuget.spec.ts.snap index d69907b1dd78f66b57fd0de0ecac612dce551217..b66cc6f39ed83362abeb2420739419219c8e636c 100644 --- a/test/datasource/__snapshots__/nuget.spec.ts.snap +++ b/test/datasource/__snapshots__/nuget.spec.ts.snap @@ -305,6 +305,26 @@ Object { } `; +exports[`datasource/nuget getPkgReleases processes real data with no github project url (v2) 1`] = ` +Object { + "homepage": "https://nunit.org", + "pkgName": "nunit", + "releases": Array [ + Object { + "version": "3.11.0", + }, + ], +} +`; + +exports[`datasource/nuget getPkgReleases processes real data with no github project url (v3) 1`] = ` +Object { + "homepage": "https://nunit.org", + "pkgName": "nunit", + "releases": Array [], +} +`; + exports[`datasource/nuget getPkgReleases processes real data without project url (v2) 1`] = ` Object { "pkgName": "nunit", diff --git a/test/datasource/nuget.spec.ts b/test/datasource/nuget.spec.ts index b9a57cac5875953409865ca8a6615235463b6725..bdc268e2f96cec492dc31ecea01d1b49fbb06858 100644 --- a/test/datasource/nuget.spec.ts +++ b/test/datasource/nuget.spec.ts @@ -15,6 +15,10 @@ const pkgListV3WithoutProkjectUrl = fs.readFileSync( 'test/datasource/nuget/_fixtures/nunitV3_withoutProjectUrl.json', 'utf8' ); +const pkgListV3NoGitHubProjectUrl = fs.readFileSync( + 'test/datasource/nuget/_fixtures/nunitV3_noGitHubProjectUrl.json', + 'utf8' +); const pkgInfoV3FromNuget = fs.readFileSync( 'test/datasource/nuget/_fixtures/nunitv3_nuget-org.xml', 'utf8' @@ -24,6 +28,10 @@ const pkgListV2 = fs.readFileSync( 'test/datasource/nuget/_fixtures/nunitV2.xml', 'utf8' ); +const pkgListV2NoGitHubProjectUrl = fs.readFileSync( + 'test/datasource/nuget/_fixtures/nunitV2_noGitHubProjectUrl.xml', + 'utf8' +); const pkgListV2NoRelease = fs.readFileSync( 'test/datasource/nuget/_fixtures/nunitV2_no_release.xml', 'utf8' @@ -246,7 +254,6 @@ describe('datasource/nuget', () => { }) ).toBeNull(); }); - it('processes real data (v3) feed is a nuget.org', async () => { got.mockReturnValueOnce({ body: JSON.parse(nugetIndexV3), @@ -314,6 +321,21 @@ describe('datasource/nuget', () => { expect(res).toMatchSnapshot(); expect(res.sourceUrl).not.toBeDefined(); }); + it('processes real data with no github project url (v3)', async () => { + got.mockReturnValueOnce({ + body: JSON.parse(nugetIndexV3), + statusCode: 200, + }); + got.mockReturnValueOnce({ + body: JSON.parse(pkgListV3NoGitHubProjectUrl), + statusCode: 200, + }); + const res = await datasource.getPkgReleases({ + ...configV3NotNugetOrg, + }); + expect(res).not.toBeNull(); + expect(res).toMatchSnapshot(); + }); it('processes real data (v2)', async () => { got.mockReturnValueOnce({ body: pkgListV2, @@ -348,6 +370,17 @@ describe('datasource/nuget', () => { expect(res).toMatchSnapshot(); expect(res.sourceUrl).not.toBeDefined(); }); + it('processes real data with no github project url (v2)', async () => { + got.mockReturnValueOnce({ + body: pkgListV2NoGitHubProjectUrl, + statusCode: 200, + }); + const res = await datasource.getPkgReleases({ + ...configV2, + }); + expect(res).not.toBeNull(); + expect(res).toMatchSnapshot(); + }); it('handles paginated results (v2)', async () => { got.mockReturnValueOnce({ body: pkgListV2Page1of2, diff --git a/test/datasource/nuget/.gitignore b/test/datasource/nuget/.gitignore deleted file mode 100644 index 4c7473dedd6db3b21dde2ff23fb2a4082b583f2c..0000000000000000000000000000000000000000 --- a/test/datasource/nuget/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/bin -/obj diff --git a/test/datasource/nuget/_fixtures/.gitignore b/test/datasource/nuget/_fixtures/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..cd42ee34e873b4ddf17cdeeed2e6c0d4e094c62b --- /dev/null +++ b/test/datasource/nuget/_fixtures/.gitignore @@ -0,0 +1,2 @@ +bin/ +obj/ diff --git a/test/datasource/nuget/_fixtures/nunitV2_noGitHubProjectUrl.xml b/test/datasource/nuget/_fixtures/nunitV2_noGitHubProjectUrl.xml new file mode 100644 index 0000000000000000000000000000000000000000..ae18b8a4ead2114918f548d4c97e9a626ad2cd00 --- /dev/null +++ b/test/datasource/nuget/_fixtures/nunitV2_noGitHubProjectUrl.xml @@ -0,0 +1,28 @@ +<feed xml:base="https://www.nuget.org/api/v2" + xmlns="http://www.w3.org/2005/Atom" + xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" + xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" + xmlns:georss="http://www.georss.org/georss" + xmlns:gml="http://www.opengis.net/gml"> + <id>http://schemas.datacontract.org/2004/07/</id> + <title/> + <updated>2019-02-04T12:51:36Z</updated> + <link rel="self" href="https://www.nuget.org/api/v2/Packages"/> + <entry> + <id>https://www.nuget.org/api/v2/Packages(Id='NUnit',Version='3.11.0')</id> + <category term="NuGetGallery.OData.V2FeedPackage" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/> + <link rel="edit" href="https://www.nuget.org/api/v2/Packages(Id='NUnit',Version='3.11.0')"/> + <link rel="self" href="https://www.nuget.org/api/v2/Packages(Id='NUnit',Version='3.11.0')"/> + <title type="text">NUnit</title> + <updated>2019-02-04T12:51:36Z</updated> + <author> + <name/> + </author> + <content type="application/zip" src="https://www.nuget.org/api/v2/package/NUnit/3.11.0"/> + <m:properties> + <d:Version>3.11.0</d:Version> + <d:IsLatestVersion>true</d:IsLatestVersion> + <d:ProjectUrl>https://nunit.org</d:ProjectUrl> + </m:properties> + </entry> +</feed> diff --git a/test/datasource/nuget/_fixtures/nunitV3_noGitHubProjectUrl.json b/test/datasource/nuget/_fixtures/nunitV3_noGitHubProjectUrl.json new file mode 100644 index 0000000000000000000000000000000000000000..de5f080078f430fbfb99fe6175dd850bb3aef794 --- /dev/null +++ b/test/datasource/nuget/_fixtures/nunitV3_noGitHubProjectUrl.json @@ -0,0 +1,46 @@ +{ + "@context": { + "@vocab": "http://schema.nuget.org/schema#", + "@base": "https://api.nuget.org/v3/registration3/" + }, + "totalHits": 1, + "lastReopen": "2019-02-04T10:47:54.6449537Z", + "index": "v3-lucene2-v2v3-20171018", + "data": [ + { + "@id": "https://api.nuget.org/v3/registration3/nunit/index.json", + "@type": "Package", + "registration": "https://api.nuget.org/v3/registration3/nunit/index.json", + "id": "NUnit", + "version": "3.11.0", + "description": "NUnit features a fluent assert syntax, parameterized, generic and theory tests and is user-extensible.\n\nThis package includes the NUnit 3 framework assembly, which is referenced by your tests. You will need to install version 3 of the nunit3-console program or a third-party runner that supports NUnit 3 in order to execute tests. Runners intended for use with NUnit 2.x will not run NUnit 3 tests correctly.\n\nSupported platforms:\n- .NET Framework 2.0+\n- .NET Standard 1.4+\n- .NET Core", + "summary": "NUnit is a unit-testing framework for all .NET languages with a strong TDD focus.", + "title": "NUnit", + "iconUrl": "https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png", + "licenseUrl": "https://raw.githubusercontent.com/nunit/nunit/master/LICENSE.txt", + "projectUrl": "https://nunit.org", + "tags": [ + "nunit", + "test", + "testing", + "tdd", + "framework", + "fluent", + "assert", + "theory", + "plugin", + "addin" + ], + "authors": ["Charlie Poole, Rob Prouse"], + "totalDownloads": 34513003, + "verified": true, + "versions": [ + { + "version": "2.5.7.10213", + "downloads": 120456, + "@id": "https://api.nuget.org/v3/registration3/nunit/2.5.7.10213.json" + } + ] + } + ] +}