Skip to content

Commit

Permalink
Use XML for Chocolatey, affects [Chocolatey Resharper PowershellGallery]
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Jul 9, 2024
1 parent 79b0141 commit b093aa2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 56 deletions.
1 change: 0 additions & 1 deletion services/chocolatey/chocolatey.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default createServiceFamily({
defaultLabel: 'chocolatey',
serviceBaseUrl: 'chocolatey',
apiBaseUrl: 'https://community.chocolatey.org/api/v2',
odataFormat: 'json',
title: 'Chocolatey',
examplePackageName: 'git',
exampleVersion: '2.19.2',
Expand Down
64 changes: 12 additions & 52 deletions services/nuget/nuget-v2-service-family.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Joi from 'joi'
import queryString from 'query-string'
import { nonNegativeInteger } from '../validators.js'
import {
BaseJsonService,
BaseXmlService,
NotFound,
redirector,
Expand All @@ -20,26 +19,11 @@ function createFilter({ packageName, includePrereleases }) {
const releaseTypeFilter = includePrereleases
? 'IsAbsoluteLatestVersion eq true'
: 'IsLatestVersion eq true'
return `Id eq '${packageName}' and ${releaseTypeFilter}`
return `tolower(Id) eq '${packageName.toLowerCase()}' and ${releaseTypeFilter}`
}

const versionSchema = Joi.alternatives(Joi.string(), Joi.number())

const jsonSchema = Joi.object({
d: Joi.object({
results: Joi.array()
.items(
Joi.object({
Version: versionSchema,
NormalizedVersion: Joi.string(),
DownloadCount: nonNegativeInteger,
}),
)
.max(1)
.default([]),
}).required(),
}).required()

const xmlSchema = Joi.object({
feed: Joi.object({
entry: Joi.object({
Expand All @@ -59,7 +43,7 @@ const queryParamSchema = Joi.object({

async function fetch(
serviceInstance,
{ odataFormat, baseUrl, packageName, includePrereleases = false },
{ baseUrl, packageName, includePrereleases = false },
) {
const url = `${baseUrl}/Packages()`
const searchParams = queryString.stringify(
Expand All @@ -69,31 +53,19 @@ async function fetch(
{ encode: false },
)

let packageData
if (odataFormat === 'xml') {
const data = await serviceInstance._requestXml({
schema: xmlSchema,
url: `${url}?${searchParams}`,
})
packageData = odataToObject(data.feed.entry)
} else if (odataFormat === 'json') {
const data = await serviceInstance._requestJson({
schema: jsonSchema,
url: `${url}?${searchParams}`,
options: {
headers: { Accept: 'application/atom+json,application/json' },
},
})
packageData = data.d.results[0]
} else {
throw Error(`Unsupported Atom OData format: ${odataFormat}`)
}
const data = await serviceInstance._requestXml({
schema: xmlSchema,
url: `${url}?${searchParams}`,
options: {
headers: { Accept: 'application/atom+xml,application/xml' },
},
})
const packageData = odataToObject(data.feed.entry)

if (packageData) {
return packageData
} else if (!includePrereleases) {
return fetch(serviceInstance, {
odataFormat,
baseUrl,
packageName,
includePrereleases: true,
Expand All @@ -117,22 +89,12 @@ function createServiceFamily({
defaultLabel,
serviceBaseUrl,
apiBaseUrl,
odataFormat,
examplePackageName,
exampleVersion,
examplePrereleaseVersion,
exampleDownloadCount,
}) {
let Base
if (odataFormat === 'xml') {
Base = BaseXmlService
} else if (odataFormat === 'json') {
Base = BaseJsonService
} else {
throw Error(`Unsupported Atom OData format: ${odataFormat}`)
}

class NugetVersionService extends Base {
class NugetVersionService extends BaseXmlService {
static name = `${name}Version`

static category = 'version'
Expand Down Expand Up @@ -174,7 +136,6 @@ function createServiceFamily({

async handle({ packageName }, queryParams) {
const packageData = await fetch(this, {
odataFormat,
baseUrl: apiBaseUrl,
packageName,
includePrereleases: queryParams.include_prereleases !== undefined,
Expand All @@ -197,7 +158,7 @@ function createServiceFamily({
dateAdded: new Date('2019-12-15'),
})

class NugetDownloadService extends Base {
class NugetDownloadService extends BaseXmlService {
static name = `${name}Downloads`

static category = 'downloads'
Expand Down Expand Up @@ -230,7 +191,6 @@ function createServiceFamily({

async handle({ packageName }) {
const packageData = await fetch(this, {
odataFormat,
baseUrl: apiBaseUrl,
packageName,
})
Expand Down
2 changes: 0 additions & 2 deletions services/powershellgallery/powershellgallery.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
defaultLabel: 'powershell gallery',
serviceBaseUrl: 'powershellgallery',
apiBaseUrl,
odataFormat: 'xml',
title: 'PowerShell Gallery',
examplePackageName: 'Azure.Storage',
exampleVersion: '4.4.0',
Expand Down Expand Up @@ -57,7 +56,6 @@ class PowershellGalleryPlatformSupport extends BaseXmlService {
async handle({ packageName }) {
const { Tags: tagStr } = await fetch(this, {
baseUrl: apiBaseUrl,
odataFormat: 'xml',
packageName,
})

Expand Down
1 change: 0 additions & 1 deletion services/resharper/resharper.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export default createServiceFamily({
defaultLabel: 'resharper',
serviceBaseUrl: 'resharper',
apiBaseUrl: 'https://resharper-plugins.jetbrains.com/api/v2',
odataFormat: 'xml',
title: 'JetBrains ReSharper plugins',
examplePackageName: 'StyleCop.StyleCop',
exampleVersion: '2017.2.0',
Expand Down

0 comments on commit b093aa2

Please sign in to comment.