Files
shields/services/jitpack/jitpack-version.service.js
Davide Bassi 9daae0ce94 Custom domains for [JitPack] artifacts (#8333)
* Custom domains for JitPack artifacts

* FIx jitpack-version test

* style: missing comma

* fix: name for both jitpack-version redirectors

* chore: comment explaining endpoint change

* use more conventional names for redirectors

Co-authored-by: chris48s <chris.shaw480@gmail.com>
2022-08-22 17:35:21 +00:00

49 lines
1.3 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,
errorMessages: { 401: 'project not found or private' },
})
}
async handle({ groupId, artifactId }) {
const { version } = await this.fetch({ groupId, artifactId })
return renderVersionBadge({ version })
}
}