Skip to content
Snippets Groups Projects
Commit 44228f9b authored by Florian Greinacher's avatar Florian Greinacher Committed by Rhys Arkins
Browse files

fix(datasource/nuget): ensure projectUrl is exposed (#4795)

Fixes #4794
parent 5c018204
No related branches found
Tags 19.66.10
No related merge requests found
...@@ -36,7 +36,15 @@ export async function getPkgReleases( ...@@ -36,7 +36,15 @@ export async function getPkgReleases(
try { try {
const pkgIsLatestVersion = getPkgProp(pkgInfo, 'IsLatestVersion'); const pkgIsLatestVersion = getPkgProp(pkgInfo, 'IsLatestVersion');
if (pkgIsLatestVersion === 'true') { 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 */ { } catch (err) /* istanbul ignore next */ {
logger.debug( logger.debug(
......
...@@ -133,6 +133,11 @@ export async function getPkgReleases( ...@@ -133,6 +133,11 @@ export async function getPkgReleases(
} }
} else if (match.projectUrl) { } else if (match.projectUrl) {
dep.sourceUrl = parse(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 */ { } catch (err) /* istanbul ignore next */ {
logger.debug( logger.debug(
......
...@@ -305,6 +305,26 @@ Object { ...@@ -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`] = ` exports[`datasource/nuget getPkgReleases processes real data without project url (v2) 1`] = `
Object { Object {
"pkgName": "nunit", "pkgName": "nunit",
......
...@@ -15,6 +15,10 @@ const pkgListV3WithoutProkjectUrl = fs.readFileSync( ...@@ -15,6 +15,10 @@ const pkgListV3WithoutProkjectUrl = fs.readFileSync(
'test/datasource/nuget/_fixtures/nunitV3_withoutProjectUrl.json', 'test/datasource/nuget/_fixtures/nunitV3_withoutProjectUrl.json',
'utf8' 'utf8'
); );
const pkgListV3NoGitHubProjectUrl = fs.readFileSync(
'test/datasource/nuget/_fixtures/nunitV3_noGitHubProjectUrl.json',
'utf8'
);
const pkgInfoV3FromNuget = fs.readFileSync( const pkgInfoV3FromNuget = fs.readFileSync(
'test/datasource/nuget/_fixtures/nunitv3_nuget-org.xml', 'test/datasource/nuget/_fixtures/nunitv3_nuget-org.xml',
'utf8' 'utf8'
...@@ -24,6 +28,10 @@ const pkgListV2 = fs.readFileSync( ...@@ -24,6 +28,10 @@ const pkgListV2 = fs.readFileSync(
'test/datasource/nuget/_fixtures/nunitV2.xml', 'test/datasource/nuget/_fixtures/nunitV2.xml',
'utf8' 'utf8'
); );
const pkgListV2NoGitHubProjectUrl = fs.readFileSync(
'test/datasource/nuget/_fixtures/nunitV2_noGitHubProjectUrl.xml',
'utf8'
);
const pkgListV2NoRelease = fs.readFileSync( const pkgListV2NoRelease = fs.readFileSync(
'test/datasource/nuget/_fixtures/nunitV2_no_release.xml', 'test/datasource/nuget/_fixtures/nunitV2_no_release.xml',
'utf8' 'utf8'
...@@ -246,7 +254,6 @@ describe('datasource/nuget', () => { ...@@ -246,7 +254,6 @@ describe('datasource/nuget', () => {
}) })
).toBeNull(); ).toBeNull();
}); });
it('processes real data (v3) feed is a nuget.org', async () => { it('processes real data (v3) feed is a nuget.org', async () => {
got.mockReturnValueOnce({ got.mockReturnValueOnce({
body: JSON.parse(nugetIndexV3), body: JSON.parse(nugetIndexV3),
...@@ -314,6 +321,21 @@ describe('datasource/nuget', () => { ...@@ -314,6 +321,21 @@ describe('datasource/nuget', () => {
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
expect(res.sourceUrl).not.toBeDefined(); 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 () => { it('processes real data (v2)', async () => {
got.mockReturnValueOnce({ got.mockReturnValueOnce({
body: pkgListV2, body: pkgListV2,
...@@ -348,6 +370,17 @@ describe('datasource/nuget', () => { ...@@ -348,6 +370,17 @@ describe('datasource/nuget', () => {
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
expect(res.sourceUrl).not.toBeDefined(); 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 () => { it('handles paginated results (v2)', async () => {
got.mockReturnValueOnce({ got.mockReturnValueOnce({
body: pkgListV2Page1of2, body: pkgListV2Page1of2,
......
/bin
/obj
bin/
obj/
<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>
{
"@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"
}
]
}
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment