Add [modrinth] game versions (#8673)
* Add a Modrinth game versions badge * Require at least one game version * Code style Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@ const versionSchema = Joi.array()
|
||||
.items(
|
||||
Joi.object({
|
||||
version_number: Joi.string().required(),
|
||||
game_versions: Joi.array().items(Joi.string()).min(1).required(),
|
||||
}).required()
|
||||
)
|
||||
.required()
|
||||
|
||||
34
services/modrinth/modrinth-game-versions.service.js
Normal file
34
services/modrinth/modrinth-game-versions.service.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { BaseModrinthService, documentation } from './modrinth-base.js'
|
||||
|
||||
export default class ModrinthGameVersions extends BaseModrinthService {
|
||||
static category = 'platform-support'
|
||||
|
||||
static route = {
|
||||
base: 'modrinth/game-versions',
|
||||
pattern: ':projectId',
|
||||
}
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'Modrinth Game Versions',
|
||||
namedParams: { projectId: 'AANobbMI' },
|
||||
staticPreview: this.render({ versions: ['1.19.2', '1.19.1', '1.19'] }),
|
||||
documentation,
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'game versions' }
|
||||
|
||||
static render({ versions }) {
|
||||
return {
|
||||
message: versions.join(' | '),
|
||||
color: 'blue',
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ projectId }) {
|
||||
const { 0: latest } = await this.fetchVersions({ projectId })
|
||||
const versions = latest.game_versions
|
||||
return this.constructor.render({ versions })
|
||||
}
|
||||
}
|
||||
15
services/modrinth/modrinth-game-versions.tester.js
Normal file
15
services/modrinth/modrinth-game-versions.tester.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createServiceTester } from '../tester.js'
|
||||
import { withRegex } from '../test-validators.js'
|
||||
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('Game Versions')
|
||||
.get('/AANobbMI.json')
|
||||
.expectBadge({
|
||||
label: 'game versions',
|
||||
message: withRegex(/\d+\.\d+(\.\d+)?( \| )?/),
|
||||
})
|
||||
|
||||
t.create('Game Versions (not found)')
|
||||
.get('/not-existing.json')
|
||||
.expectBadge({ label: 'game versions', message: 'not found', color: 'red' })
|
||||
Reference in New Issue
Block a user