Files
shields/services/pub/pub.service.js
chris48s 65dba94fa8 Stop calling variables "which"; affects [chocolatey codeclimate conda crates debug gem github mozillaobservatory nuget powershellgallery pub resharper vaadindirectory] (#3495)
* which --> variant

* which --> alias

* which --> format

* improve param names in codeclimate

* improve param names in github-issue-detail

* update github-issue-detail unit tests
2019-05-28 23:00:12 +01:00

63 lines
1.5 KiB
JavaScript

'use strict'
const Joi = require('joi')
const { BaseJsonService } = require('..')
const { latest, renderVersionBadge } = require('../version')
const schema = Joi.object({
versions: Joi.array()
.items(Joi.string())
.required(),
}).required()
module.exports = class PubVersion extends BaseJsonService {
static get category() {
return 'version'
}
static get route() {
return {
base: 'pub',
pattern: ':variant(v|vpre)/:packageName',
}
}
static get examples() {
return [
{
title: 'Pub',
pattern: 'v/:packageName',
namedParams: { packageName: 'box2d' },
staticPreview: renderVersionBadge({ version: 'v0.4.0' }),
keywords: ['dart', 'dartlang'],
},
{
title: 'Pub',
pattern: 'vpre/:packageName',
namedParams: { packageName: 'box2d' },
staticPreview: renderVersionBadge({ version: 'v0.4.0' }),
keywords: ['dart', 'dartlang'],
},
]
}
static get defaultBadgeData() {
return { label: 'pub' }
}
async fetch({ packageName }) {
return this._requestJson({
schema,
url: `https://pub.dartlang.org/packages/${packageName}.json`,
})
}
async handle({ variant, packageName }) {
const data = await this.fetch({ packageName })
const includePre = variant === 'vpre'
const versions = data.versions
const version = latest(versions, { pre: includePre })
return renderVersionBadge({ version })
}
}