-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathdocsrs.service.js
58 lines (52 loc) · 1.32 KB
/
docsrs.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
const schema = Joi.array()
.items(
Joi.object({
build_status: Joi.boolean().required(),
})
)
.min(1)
.required()
export default class DocsRs extends BaseJsonService {
static category = 'build'
static route = { base: 'docsrs', pattern: ':crate/:version?' }
static examples = [
{
title: 'docs.rs',
namedParams: { crate: 'regex', version: 'latest' },
staticPreview: this.render({ version: 'latest', buildStatus: true }),
keywords: ['rust'],
},
]
static defaultBadgeData = { label: 'docs' }
static render({ buildStatus, version }) {
let label = `docs@${version}`
if (version === 'latest') {
label = 'docs'
}
if (buildStatus) {
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}/builds.json`,
})
}
async handle({ crate, version = 'latest' }) {
const [{ build_status: buildStatus }] = await this.fetch({ crate, version })
return this.constructor.render({ version, buildStatus })
}
}