Files
shields/services/docsrs/docsrs.service.js
chris48s 478b1083f2 migrate examples to openApi part 3; affects [conan cookbook coverity cpan debian docker docsrs dub eclipse] (#9429)
* migrate some services from examples to openApi

* improve and de-dupe service titles

* revert changes to depfu
2023-08-17 20:32:01 +00:00

72 lines
1.6 KiB
JavaScript

import Joi from 'joi'
import { BaseJsonService, pathParams } from '../index.js'
const schema = Joi.object({
doc_status: Joi.boolean().required(),
}).required()
export default class DocsRs extends BaseJsonService {
static category = 'build'
static route = { base: 'docsrs', pattern: ':crate/:version?' }
static openApi = {
'/docsrs/{crate}/{version}': {
get: {
summary: 'docs.rs (with version)',
parameters: pathParams(
{
name: 'crate',
example: 'regex',
},
{
name: 'version',
example: 'latest',
},
),
},
},
'/docsrs/{crate}': {
get: {
summary: 'docs.rs',
parameters: pathParams({
name: 'crate',
example: 'regex',
}),
},
},
}
static defaultBadgeData = { label: 'docs' }
static render({ docStatus, version }) {
let label = `docs@${version}`
if (version === 'latest') {
label = 'docs'
}
if (docStatus) {
return {
label,
message: 'passing',
color: 'success',
}
} else {
return {
label,
message: 'failing',
color: 'critical',
}
}
}
async fetch({ crate, version }) {
return await this._requestJson({
schema,
url: `https://docs.rs/crate/${crate}/${version}/status.json`,
})
}
async handle({ crate, version = 'latest' }) {
const { doc_status: docStatus } = await this.fetch({ crate, version })
return this.constructor.render({ version, docStatus })
}
}