This closes #2921 by switching ReSharper to the XML API used by Powershell, and refactors the powershell code back into the common nuget v2 service class. It also removes mocked tests of the color logic, replacing them with smaller-bracket tests that accomplish the same thing more concisely.
50 lines
936 B
JavaScript
50 lines
936 B
JavaScript
'use strict'
|
|
|
|
const { metric, addv } = require('../../lib/text-formatters')
|
|
const {
|
|
downloadCount: downloadCountColor,
|
|
} = require('../../lib/color-formatters')
|
|
|
|
function renderVersionBadge({ version, feed }) {
|
|
let color
|
|
if (version.includes('-')) {
|
|
color = 'yellow'
|
|
} else if (version.startsWith('0')) {
|
|
color = 'orange'
|
|
} else {
|
|
color = 'blue'
|
|
}
|
|
|
|
return {
|
|
message: addv(version),
|
|
color,
|
|
label: feed,
|
|
}
|
|
}
|
|
|
|
function renderDownloadBadge({ downloads }) {
|
|
return {
|
|
message: metric(downloads),
|
|
color: downloadCountColor(downloads),
|
|
}
|
|
}
|
|
|
|
function odataToObject(odata) {
|
|
if (odata === undefined) {
|
|
return undefined
|
|
}
|
|
|
|
const result = {}
|
|
Object.entries(odata['m:properties']).forEach(([key, value]) => {
|
|
const newKey = key.replace(/^d:/, '')
|
|
result[newKey] = value
|
|
})
|
|
return result
|
|
}
|
|
|
|
module.exports = {
|
|
renderVersionBadge,
|
|
renderDownloadBadge,
|
|
odataToObject,
|
|
}
|