fix [nuget] version build metadata handling (#4222)
* fix: nuget version build metadata handling * chore: manual formatting update
This commit is contained in:
@@ -34,9 +34,26 @@ const nuGetV3VersionJsonFirstCharNotZero = JSON.stringify({
|
||||
],
|
||||
})
|
||||
|
||||
const nuGetV3VersionJsonBuildMetadataWithDash = JSON.stringify({
|
||||
data: [
|
||||
{
|
||||
totalDownloads: 0,
|
||||
versions: [
|
||||
{
|
||||
version: '1.16.0+388',
|
||||
},
|
||||
{
|
||||
version: '1.17.0+1b81349-429',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
queryIndex,
|
||||
nuGetV3VersionJsonWithDash,
|
||||
nuGetV3VersionJsonFirstCharZero,
|
||||
nuGetV3VersionJsonFirstCharNotZero,
|
||||
nuGetV3VersionJsonBuildMetadataWithDash,
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
const { promisify } = require('util')
|
||||
const Joi = require('@hapi/joi')
|
||||
const semver = require('semver')
|
||||
const { regularUpdate } = require('../../core/legacy/regular-update')
|
||||
const RouteBuilder = require('../route-builder')
|
||||
const { renderVersionBadge, renderDownloadBadge } = require('./nuget-helpers')
|
||||
@@ -184,16 +185,19 @@ function createServiceFamily({
|
||||
feed,
|
||||
})
|
||||
const { versions } = await fetch(this, { baseUrl, packageName })
|
||||
|
||||
let latest = versions.slice(-1).pop()
|
||||
const includePrereleases = which === 'vpre'
|
||||
if (!includePrereleases) {
|
||||
const filtered = versions.filter(item => !item.version.includes('-'))
|
||||
const filtered = versions.filter(item => {
|
||||
if (semver.valid(item.version)) {
|
||||
return !semver.prerelease(item.version)
|
||||
}
|
||||
return !item.version.includes('-')
|
||||
})
|
||||
if (filtered.length) {
|
||||
latest = filtered.slice(-1).pop()
|
||||
}
|
||||
}
|
||||
|
||||
const { version } = latest
|
||||
return this.constructor.render({ version, feed })
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ const {
|
||||
nuGetV3VersionJsonWithDash,
|
||||
nuGetV3VersionJsonFirstCharZero,
|
||||
nuGetV3VersionJsonFirstCharNotZero,
|
||||
nuGetV3VersionJsonBuildMetadataWithDash,
|
||||
} = require('../nuget-fixtures')
|
||||
const { invalidJSON } = require('../response-fixtures')
|
||||
|
||||
@@ -114,6 +115,25 @@ t.create('version (blue badge)')
|
||||
color: 'blue',
|
||||
})
|
||||
|
||||
// https://github.com/badges/shields/issues/4219
|
||||
t.create('version (build metadata with -)')
|
||||
.get('/v/MongoFramework.json')
|
||||
.intercept(nock =>
|
||||
nock('https://api.nuget.org')
|
||||
.get('/v3/index.json')
|
||||
.reply(200, queryIndex)
|
||||
)
|
||||
.intercept(nock =>
|
||||
nock('https://api-v2v3search-0.nuget.org')
|
||||
.get('/query?q=packageid%3Amongoframework&prerelease=true&semVerLevel=2')
|
||||
.reply(200, nuGetV3VersionJsonBuildMetadataWithDash)
|
||||
)
|
||||
.expectBadge({
|
||||
label: 'nuget',
|
||||
message: 'v1.17.0+1b81349-429',
|
||||
color: 'yellow',
|
||||
})
|
||||
|
||||
t.create('version (not found)')
|
||||
.get('/v/not-a-real-package.json')
|
||||
.expectBadge({ label: 'nuget', message: 'package not found' })
|
||||
|
||||
Reference in New Issue
Block a user