Files
shields/services/luarocks/luarocks.service.js
jNullj cc90c190f2 Refactor - use renderVersionBadge - part 3 [luarocks gitlab nuget feedz] (#10630)
* Refactor luarocks to use renderVersionBadge

Loarocks does not appear to have version conventions and there are no issues in history that require usage of existing color usage.
For better consistency use color scheme as the rest of the badges.

Also add scm and cvs as preview in renderVersionBadge

* add missing test for version color formatter

* refactor nuget to use renderVersionBadge

* Refactor GitlabTag to use renderVersionBadge

* add comment about non-standard render of coljarsVersion

* Refactor FeedzVersionService to use renderVersionBadge from version.js

* Refactor nuget.tester.js to remove unnecessary version tests

* add missing label in gitlab-tag.spec
2024-10-27 13:35:03 +00:00

78 lines
1.9 KiB
JavaScript

import Joi from 'joi'
import { BaseJsonService, NotFound, pathParams } from '../index.js'
import { renderVersionBadge } from '../version.js'
import { latestVersion } from './luarocks-version-helpers.js'
const schema = Joi.object({
repository: Joi.object()
.pattern(
Joi.string(),
Joi.object().pattern(Joi.string(), Joi.array().strip()),
)
.required(),
}).required()
export default class Luarocks extends BaseJsonService {
static category = 'version'
static route = {
base: 'luarocks/v',
pattern: ':user/:moduleName/:version?',
}
static openApi = {
'/luarocks/v/{user}/{moduleName}': {
get: {
summary: 'LuaRocks',
parameters: pathParams(
{
name: 'user',
example: 'mpeterv',
},
{
name: 'moduleName',
example: 'luacheck',
},
),
},
},
}
static defaultBadgeData = {
label: 'luarocks',
}
async fetch({ user, moduleName }) {
const { repository } = await this._requestJson({
url: `https://luarocks.org/manifests/${encodeURIComponent(
user,
)}/manifest.json`,
schema,
httpErrors: {
404: 'user not found',
},
})
const moduleData = repository[moduleName]
if (!moduleData) {
throw new NotFound({ prettyMessage: 'module not found' })
}
return moduleData
}
async handle({ user, moduleName, version: requestedVersion }) {
const moduleInfo = await this.fetch({ user, moduleName })
let version
if (requestedVersion) {
if (!(requestedVersion in moduleInfo)) {
throw new NotFound({ prettyMessage: 'version not found' })
}
version = requestedVersion
} else {
const versions = Object.keys(moduleInfo)
version = latestVersion(versions)
}
return renderVersionBadge({ version })
}
}