* 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
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import Joi from 'joi'
|
|
import { renderVersionBadge } from '../version.js'
|
|
import { BaseJsonService } from '../index.js'
|
|
|
|
const schema = Joi.object({
|
|
version: Joi.string().required(),
|
|
status: Joi.string().valid('ok').required(),
|
|
}).required()
|
|
|
|
export default class JitPackVersion extends BaseJsonService {
|
|
static category = 'version'
|
|
|
|
// Changed endpoint to allow any groupId, custom domains included
|
|
// See: https://github.com/badges/shields/issues/8312
|
|
static route = {
|
|
base: 'jitpack/version',
|
|
pattern: ':groupId/:artifactId',
|
|
}
|
|
|
|
static examples = [
|
|
{
|
|
title: 'JitPack',
|
|
namedParams: {
|
|
groupId: 'com.github.jitpack',
|
|
artifactId: 'maven-simple',
|
|
},
|
|
staticPreview: renderVersionBadge({ version: 'v1.1' }),
|
|
keywords: ['java', 'maven'],
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'jitpack' }
|
|
|
|
async fetch({ groupId, artifactId }) {
|
|
const url = `https://jitpack.io/api/builds/${groupId}/${artifactId}/latestOk`
|
|
|
|
return this._requestJson({
|
|
schema,
|
|
url,
|
|
httpErrors: { 401: 'project not found or private' },
|
|
})
|
|
}
|
|
|
|
async handle({ groupId, artifactId }) {
|
|
const { version } = await this.fetch({ groupId, artifactId })
|
|
return renderVersionBadge({ version })
|
|
}
|
|
}
|