Continue to implement #2698: - Add `core/base-service/index.js` (but hold off on moving the things it imports) - Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits. - Apply consistent ordering of imports and use of `module.exports` in testers. - Remove some renaming of imports. - Remove obsolete tests here and there.
57 lines
1.2 KiB
JavaScript
57 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
const { BaseJsonService } = require('..')
|
|
|
|
const depfuSchema = Joi.object({
|
|
text: Joi.string().required(),
|
|
colorscheme: Joi.string().required(),
|
|
}).required()
|
|
|
|
module.exports = class Depfu extends BaseJsonService {
|
|
async fetch({ user, repo }) {
|
|
const url = `https://depfu.com/github/shields/${user}/${repo}`
|
|
return this._requestJson({ url, schema: depfuSchema })
|
|
}
|
|
|
|
static render({ text, colorscheme }) {
|
|
return {
|
|
message: text,
|
|
color: colorscheme,
|
|
}
|
|
}
|
|
|
|
async handle({ user, repo }) {
|
|
const { text, colorscheme } = await this.fetch({ user, repo })
|
|
return this.constructor.render({ text, colorscheme })
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return { label: 'dependencies' }
|
|
}
|
|
|
|
static get category() {
|
|
return 'dependencies'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'depfu',
|
|
pattern: ':user/:repo',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Depfu',
|
|
namedParams: { user: 'depfu', repo: 'example-ruby' },
|
|
staticPreview: this.render({
|
|
text: 'recent',
|
|
colorscheme: 'brightgreen',
|
|
}),
|
|
},
|
|
]
|
|
}
|
|
}
|