Skip to content
Snippets Groups Projects
Unverified Commit efd707eb authored by Pierce Thompson's avatar Pierce Thompson Committed by GitHub
Browse files

Add [modrinth] game versions (#8673)


* Add a Modrinth game versions badge

* Require at least one game version

* Code style

Co-authored-by: default avatarrepo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
parent f67251a9
No related branches found
No related tags found
No related merge requests found
......@@ -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()
......
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 })
}
}
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' })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment