* 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
55 lines
1.1 KiB
JavaScript
55 lines
1.1 KiB
JavaScript
import Joi from 'joi'
|
|
import { BaseJsonService } from '../index.js'
|
|
import { metric } from '../text-formatters.js'
|
|
|
|
const schema = Joi.object({
|
|
commit_count: Joi.number().required(),
|
|
}).required()
|
|
|
|
export default class SourceforgeCommitCount extends BaseJsonService {
|
|
static category = 'activity'
|
|
|
|
static route = {
|
|
base: 'sourceforge/commit-count',
|
|
pattern: ':project',
|
|
}
|
|
|
|
static examples = [
|
|
{
|
|
title: 'SourceForge commit count',
|
|
namedParams: {
|
|
project: 'guitarix',
|
|
},
|
|
staticPreview: this.render({
|
|
commitCount: 1365,
|
|
}),
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'commit count' }
|
|
|
|
static render({ commitCount }) {
|
|
return {
|
|
message: metric(commitCount),
|
|
color: 'blue',
|
|
}
|
|
}
|
|
|
|
async fetch({ project }) {
|
|
return this._requestJson({
|
|
url: `https://sourceforge.net/rest/p/${project}/git`,
|
|
schema,
|
|
httpErrors: {
|
|
404: 'project not found',
|
|
},
|
|
})
|
|
}
|
|
|
|
async handle({ project }) {
|
|
const body = await this.fetch({ project })
|
|
return this.constructor.render({
|
|
commitCount: body.commit_count,
|
|
})
|
|
}
|
|
}
|