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
This commit is contained in:
Caleb Cartwright
2020-09-14 20:42:57 -05:00
committed by GitHub
parent 0b31461af6
commit ac54dd3ced
8 changed files with 117 additions and 196 deletions

View File

@@ -16,72 +16,58 @@ const queryParamSchema = Joi.object({
}).required()
module.exports = class DroneBuild extends BaseJsonService {
static get category() {
return 'build'
static category = 'build'
static route = {
base: 'drone/build',
pattern: ':user/:repo/:branch*',
queryParamSchema,
}
static get route() {
return {
queryParamSchema,
base: 'drone/build',
pattern: ':user/:repo/:branch*',
}
}
static auth = { passKey: 'drone_token', serviceKey: 'drone' }
static examples = [
{
title: 'Drone (cloud)',
pattern: ':user/:repo',
namedParams: {
user: 'drone',
repo: 'drone',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
{
title: 'Drone (cloud) with branch',
pattern: ':user/:repo/:branch',
namedParams: {
user: 'drone',
repo: 'drone',
branch: 'master',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
{
title: 'Drone (self-hosted)',
pattern: ':user/:repo',
queryParams: { server: 'https://drone.shields.io' },
namedParams: {
user: 'badges',
repo: 'shields',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
{
title: 'Drone (self-hosted) with branch',
pattern: ':user/:repo/:branch',
queryParams: { server: 'https://drone.shields.io' },
namedParams: {
user: 'badges',
repo: 'shields',
branch: 'feat/awesome-thing',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
]
static get auth() {
return { passKey: 'drone_token', serviceKey: 'drone' }
}
static get examples() {
return [
{
title: 'Drone (cloud)',
pattern: ':user/:repo',
namedParams: {
user: 'drone',
repo: 'drone',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
{
title: 'Drone (cloud) with branch',
pattern: ':user/:repo/:branch',
namedParams: {
user: 'drone',
repo: 'drone',
branch: 'master',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
{
title: 'Drone (self-hosted)',
pattern: ':user/:repo',
queryParams: { server: 'https://drone.shields.io' },
namedParams: {
user: 'badges',
repo: 'shields',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
{
title: 'Drone (self-hosted) with branch',
pattern: ':user/:repo/:branch',
queryParams: { server: 'https://drone.shields.io' },
namedParams: {
user: 'badges',
repo: 'shields',
branch: 'feat/awesome-thing',
},
staticPreview: renderBuildStatusBadge({ status: 'success' }),
},
]
}
static get defaultBadgeData() {
return {
label: 'build',
}
}
static defaultBadgeData = { label: 'build' }
async handle({ user, repo, branch }, { server = 'https://cloud.drone.io' }) {
const json = await this._requestJson(

View File

@@ -35,56 +35,47 @@ const intervalMap = {
}
module.exports = class DubDownloads extends BaseJsonService {
static get category() {
return 'downloads'
static category = 'downloads'
static route = {
base: 'dub',
pattern: ':interval(dd|dw|dm|dt)/:packageName/:version*',
}
static get route() {
return {
base: 'dub',
pattern: ':interval(dd|dw|dm|dt)/:packageName/:version*',
}
}
static examples = [
{
title: 'DUB',
namedParams: { interval: 'dm', packageName: 'vibe-d' },
staticPreview: this.render({ interval: 'dm', downloadCount: 5000 }),
},
{
title: 'DUB (version)',
namedParams: {
interval: 'dm',
packageName: 'vibe-d',
version: '0.8.4',
},
staticPreview: this.render({
interval: 'dm',
version: '0.8.4',
downloadCount: 100,
}),
},
{
title: 'DUB (latest)',
namedParams: {
interval: 'dm',
packageName: 'vibe-d',
version: 'latest',
},
staticPreview: this.render({
interval: 'dm',
version: 'latest',
downloadCount: 100,
}),
},
]
static get examples() {
return [
{
title: 'DUB',
namedParams: { interval: 'dm', packageName: 'vibe-d' },
staticPreview: this.render({ interval: 'dm', downloadCount: 5000 }),
},
{
title: 'DUB (version)',
namedParams: {
interval: 'dm',
packageName: 'vibe-d',
version: '0.8.4',
},
staticPreview: this.render({
interval: 'dm',
version: '0.8.4',
downloadCount: 100,
}),
},
{
title: 'DUB (latest)',
namedParams: {
interval: 'dm',
packageName: 'vibe-d',
version: 'latest',
},
staticPreview: this.render({
interval: 'dm',
version: 'latest',
downloadCount: 100,
}),
},
]
}
static get defaultBadgeData() {
return { label: 'downloads' }
}
static defaultBadgeData = { label: 'downloads' }
static render({ interval, version, downloadCount }) {
const { messageSuffix } = intervalMap[interval]

View File

@@ -9,30 +9,17 @@ const schema = Joi.object({
})
module.exports = class DubLicense extends BaseJsonService {
static get category() {
return 'license'
}
static category = 'license'
static route = { base: 'dub/l', pattern: ':packageName' }
static examples = [
{
title: 'DUB',
namedParams: { packageName: 'vibe-d' },
staticPreview: renderLicenseBadge({ licenses: ['MIT'] }),
},
]
static get route() {
return {
base: 'dub/l',
pattern: ':packageName',
}
}
static get examples() {
return [
{
title: 'DUB',
namedParams: { packageName: 'vibe-d' },
staticPreview: renderLicenseBadge({ licenses: ['MIT'] }),
},
]
}
static get defaultBadgeData() {
return { label: 'license' }
}
static defaultBadgeData = { label: 'license' }
async fetch({ packageName }) {
return this._requestJson({

View File

@@ -7,30 +7,17 @@ const { BaseJsonService } = require('..')
const schema = Joi.string().required()
module.exports = class DubVersion extends BaseJsonService {
static get category() {
return 'version'
}
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 get route() {
return {
base: 'dub/v',
pattern: ':packageName',
}
}
static get examples() {
return [
{
title: 'DUB',
namedParams: { packageName: 'vibe-d' },
staticPreview: renderVersionBadge({ version: 'v0.8.4' }),
},
]
}
static get defaultBadgeData() {
return { label: 'dub' }
}
static defaultBadgeData = { label: 'dub' }
async fetch({ packageName }) {
return this._requestJson({

View File

@@ -6,13 +6,8 @@ const { createRoute } = require('./dynamic-helpers')
const jsonPath = require('./json-path')
module.exports = class DynamicJson extends jsonPath(BaseJsonService) {
static get enabledMetrics() {
return [MetricNames.SERVICE_RESPONSE_SIZE]
}
static get route() {
return createRoute('json')
}
static enabledMetrics = [MetricNames.SERVICE_RESPONSE_SIZE]
static route = createRoute('json')
async fetch({ schema, url, errorMessages }) {
return this._requestJson({

View File

@@ -14,23 +14,10 @@ const { createRoute } = require('./dynamic-helpers')
// JSON parser and write the queries in jsonpath instead. Then eventually
// deprecate the old version.
module.exports = class DynamicXml extends BaseService {
static get category() {
return 'dynamic'
}
static get enabledMetrics() {
return [MetricNames.SERVICE_RESPONSE_SIZE]
}
static get route() {
return createRoute('xml')
}
static get defaultBadgeData() {
return {
label: 'custom badge',
}
}
static category = 'dynamic'
static enabledMetrics = [MetricNames.SERVICE_RESPONSE_SIZE]
static route = createRoute('xml')
static defaultBadgeData = { label: 'custom badge' }
transform({ pathExpression, buffer }) {
// e.g. //book[2]/@id

View File

@@ -6,13 +6,8 @@ const { createRoute } = require('./dynamic-helpers')
const jsonPath = require('./json-path')
module.exports = class DynamicYaml extends jsonPath(BaseYamlService) {
static get enabledMetrics() {
return [MetricNames.SERVICE_RESPONSE_SIZE]
}
static get route() {
return createRoute('yaml')
}
static enabledMetrics = [MetricNames.SERVICE_RESPONSE_SIZE]
static route = createRoute('yaml')
async fetch({ schema, url, errorMessages }) {
return this._requestYaml({

View File

@@ -17,15 +17,8 @@ const { InvalidParameter, InvalidResponse } = require('..')
*/
module.exports = superclass =>
class extends superclass {
static get category() {
return 'dynamic'
}
static get defaultBadgeData() {
return {
label: 'custom badge',
}
}
static category = 'dynamic'
static defaultBadgeData = { label: 'custom badge' }
/**
* Request data from an upstream API, transform it to JSON and validate against a schema