Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nuget): Sort api response before picking projectUrl #23090

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>NUnit</id>
<version>3.13.2</version>
<title>NUnit</title>
<authors>Charlie Poole, Rob Prouse</authors>
<owners>Charlie Poole, Rob Prouse</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="file">LICENSE.txt</license>
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl>
<icon>icon.png</icon>
<projectUrl>https://nunit.org/</projectUrl>
<iconUrl>https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png</iconUrl>
<description>NUnit features a fluent assert syntax, parameterized, generic and theory tests and is user-extensible.
rarkins marked this conversation as resolved.
Show resolved Hide resolved

This 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.

Supported platforms:
- .NET Framework 3.5+
- .NET Standard 2.0+</description>
<summary>NUnit is a unit-testing framework for all .NET languages with a strong TDD focus.</summary>
<releaseNotes>This 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.</releaseNotes>
<copyright>Copyright (c) 2021 Charlie Poole, Rob Prouse</copyright>
<language>en-US</language>
<tags>nunit test testing tdd framework fluent assert theory plugin addin</tags>
<repository type="git" url="https://github.com/nunit/nunit" />
<dependencies>
<group targetFramework=".NETFramework3.5" />
<group targetFramework=".NETFramework4.0" />
<group targetFramework=".NETFramework4.5" />
<group targetFramework=".NETStandard2.0">
<dependency id="NETStandard.Library" version="2.0.0" />
</group>
</dependencies>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"count": 1,
"items": [
{
"count": 4,
"items": [
{
"@id": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/registrations2/nunit/3.13.2.json",
"@type": "Package",
"catalogEntry": {
"listed": true,
"projectUrl": "https://nunit.org/",
"published": "2021-12-03T03:20:52Z",
"version": "3.13.2"
},
"packageContent": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/flat2/nunit/3.13.2/nunit.3.13.2.nupkg"
},
{
"@id": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/registrations2/nunit/2.7.1.json",
"@type": "Package",
"catalogEntry": {
"listed": true,
"projectUrl": "http://nunitsoftware.com/nunitv2",
"published": "2021-12-03T03:20:52Z",
"version": "2.7.1"
},
"packageContent": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/flat2/nunit/2.7.1/nunit.2.7.1.nupkg"
},
{
"@id": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/registrations2/nunit/2.6.5.json",
"@type": "Package",
"catalogEntry": {
"listed": true,
"projectUrl": "http://nunit.org/",
"published": "2021-12-03T03:20:52Z",
"version": "2.6.5"
},
"packageContent": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/flat2/nunit/2.6.5/nunit.2.6.5.nupkg"
},
{
"@id": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/registrations2/nunit/2.5.7.10213.json",
"@type": "Package",
"catalogEntry": {
"listed": true,
"projectUrl": "",
"published": "2021-12-03T03:20:52Z",
"version": "2.5.7.10213"
},
"packageContent": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/flat2/nunit/2.5.7.10213/nunit.2.5.7.10213.nupkg"
}
],
"lower": "2.5.7.10213",
"upper": "3.13.2"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"resources": [
{
"@id": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/registrations2-semver2/",
"@type": "RegistrationsBaseUrl/3.6.0",
"comment": "This base URL includes SemVer 2.0.0 packages."
},
{
"@id": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/flat2/",
"@type": "PackageBaseAddress/3.0.0"
}
],
"version": "3.0.0-beta"
}
26 changes: 26 additions & 0 deletions lib/modules/datasource/nuget/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,32 @@ exports[`modules/datasource/nuget/index getReleases processes real data (v3) fee
}
`;

exports[`modules/datasource/nuget/index getReleases processes real data (v3) feed is azure devops 1`] = `
{
"homepage": "https://nunit.org/",
"registryUrl": "https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/index.json",
"releases": [
{
"releaseTimestamp": "2021-12-03T03:20:52.000Z",
"version": "2.5.7.10213",
},
{
"releaseTimestamp": "2021-12-03T03:20:52.000Z",
"version": "2.6.5",
},
{
"releaseTimestamp": "2021-12-03T03:20:52.000Z",
"version": "2.7.1",
},
{
"releaseTimestamp": "2021-12-03T03:20:52.000Z",
"version": "3.13.2",
},
],
"sourceUrl": "https://github.com/nunit/nunit",
}
`;

exports[`modules/datasource/nuget/index getReleases processes real data (v3) feed is not a nuget.org 1`] = `
{
"registryUrl": "https://myprivatefeed/index.json",
Expand Down
39 changes: 39 additions & 0 deletions lib/modules/datasource/nuget/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const nlogMocks = [
},
];

const nugetIndexV3AzureDevOps = Fixtures.get('azure_devops/v3_index.json');
const pkgListV3RegistrationAzureDevOps = Fixtures.get(
'azure_devops/nunit/v3_registration.json'
);
const pkgInfoV3FromAzureDevOps = Fixtures.get('azure_devops/nunit/nuspec.xml');
rarkins marked this conversation as resolved.
Show resolved Hide resolved

const configV3V2 = {
datasource,
versioning,
Expand Down Expand Up @@ -93,6 +99,15 @@ const configV3Multiple = {
],
};

const configV3AzureDevOps = {
datasource,
versioning,
packageName: 'nunit',
registryUrls: [
'https://pkgs.dev.azure.com/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/index.json',
],
};

describe('modules/datasource/nuget/index', () => {
describe('parseRegistryUrl', () => {
beforeEach(() => {
Expand Down Expand Up @@ -378,6 +393,30 @@ describe('modules/datasource/nuget/index', () => {
expect(res?.sourceUrl).toBeDefined();
});

it('processes real data (v3) feed is azure devops', async () => {
httpMock
.scope('https://pkgs.dev.azure.com')
.get(
'/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/index.json'
)
.twice()
.reply(200, nugetIndexV3AzureDevOps)
.get(
'/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/registrations2-semver2/nunit/index.json'
)
.reply(200, pkgListV3RegistrationAzureDevOps)
.get(
'/organisationName/_packaging/2745c5e9-610a-4537-9032-978c66527b51/nuget/v3/flat2/nunit/3.13.2/nunit.nuspec'
)
.reply(200, pkgInfoV3FromAzureDevOps);
const res = await getPkgReleases({
...configV3AzureDevOps,
});
expect(res).not.toBeNull();
rarkins marked this conversation as resolved.
Show resolved Hide resolved
expect(res).toMatchSnapshot();
rarkins marked this conversation as resolved.
Show resolved Hide resolved
expect(res?.sourceUrl).toBeDefined();
rarkins marked this conversation as resolved.
Show resolved Hide resolved
});

it('processes real data (v3) for several catalog pages', async () => {
const scope = httpMock
.scope('https://api.nuget.org')
Expand Down
7 changes: 5 additions & 2 deletions lib/modules/datasource/nuget/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Http, HttpError } from '../../../util/http';
import * as p from '../../../util/promises';
import { regEx } from '../../../util/regex';
import { ensureTrailingSlash } from '../../../util/url';
import { api as versioning } from '../../versioning/nuget';
import type { Release, ReleaseResult } from '../types';
import { massageUrl, removeBuildMeta } from './common';
import type {
Expand Down Expand Up @@ -121,7 +122,9 @@ export async function getReleases(
const catalogPagesQueue = catalogPages.map(
(page) => (): Promise<CatalogEntry[]> => getCatalogEntry(http, page)
);
const catalogEntries = (await p.all(catalogPagesQueue)).flat();
const catalogEntries = (await p.all(catalogPagesQueue))
.flat()
.sort((a, b) => versioning.sortVersions(a.version, b.version));
rarkins marked this conversation as resolved.
Show resolved Hide resolved

let homepage: string | null = null;
let latestStable: string | null = null;
Expand All @@ -131,7 +134,7 @@ export async function getReleases(
if (releaseTimestamp) {
release.releaseTimestamp = releaseTimestamp;
}
if (semver.valid(version) && !semver.prerelease(version)) {
if (versioning.isValid(version) && versioning.isStable(version)) {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
latestStable = removeBuildMeta(version);
homepage = projectUrl ? massageUrl(projectUrl) : homepage;
}
Expand Down