Files
shields/services/dub/dub-version.service.js
Caleb Cartwright ac54dd3ced convert some service classes to static props, run [drone dub dynamic] (#5543)
* refactor(drone): convert to static props

* refactor(dub): convert to static props

* refactor(dynamic): convert to static props
2020-09-15 01:42:57 +00:00

34 lines
848 B
JavaScript

'use strict'
const Joi = require('@hapi/joi')
const { renderVersionBadge } = require('../version')
const { BaseJsonService } = require('..')
const schema = Joi.string().required()
module.exports = class DubVersion extends BaseJsonService {
static category = 'version'
static route = { base: 'dub/v', pattern: ':packageName' }
static examples = [
{
title: 'DUB',
namedParams: { packageName: 'vibe-d' },
staticPreview: renderVersionBadge({ version: 'v0.8.4' }),
},
]
static defaultBadgeData = { label: 'dub' }
async fetch({ packageName }) {
return this._requestJson({
schema,
url: `https://code.dlang.org/api/packages/${packageName}/latest`,
})
}
async handle({ packageName }) {
const version = await this.fetch({ packageName })
return renderVersionBadge({ version })
}
}