* allow serviceData to override cacheSeconds with a longer value * prevent [endpoint] json cacheSeconds property exceeding service default * allow ShieldsRuntimeError to specify a cacheSeconds property By default error responses use the cacheLength of the service class throwing the error. This allows error to tell the handling layer the maxAge that should be set on the error badge response. * add customExceptions param This 1. allows us to specify custom properties to pass to the exception constructor if we throw any of the standard got errors e.g: `ETIMEDOUT`, `ECONNRESET`, etc 2. uses a custom `cacheSeconds` property (if set on the exception) to set the response maxAge * customExceptions --> systemErrors * errorMessages --> httpErrors
47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
import Joi from 'joi'
|
|
import { GithubAuthV3Service } from './github-auth-service.js'
|
|
import { documentation, httpErrorsFor } from './github-helpers.js'
|
|
|
|
const schema = Joi.object({
|
|
color: Joi.string().hex().required(),
|
|
}).required()
|
|
|
|
export default class GithubLabels extends GithubAuthV3Service {
|
|
static category = 'issue-tracking'
|
|
static route = { base: 'github/labels', pattern: ':user/:repo/:name' }
|
|
static examples = [
|
|
{
|
|
title: 'GitHub labels',
|
|
namedParams: {
|
|
user: 'atom',
|
|
repo: 'atom',
|
|
name: 'help-wanted',
|
|
},
|
|
staticPreview: this.render({ name: 'help-wanted', color: '#159818' }),
|
|
documentation,
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: ' ' }
|
|
|
|
static render({ name, color }) {
|
|
return {
|
|
message: name,
|
|
color,
|
|
}
|
|
}
|
|
|
|
async fetch({ user, repo, name }) {
|
|
return this._requestJson({
|
|
url: `/repos/${user}/${repo}/labels/${name}`,
|
|
schema,
|
|
httpErrors: httpErrorsFor('repo or label not found'),
|
|
})
|
|
}
|
|
|
|
async handle({ user, repo, name }) {
|
|
const { color } = await this.fetch({ user, repo, name })
|
|
return this.constructor.render({ name, color })
|
|
}
|
|
}
|