Add [Fedora] package version support (#3372)

This commit is contained in:
Ville Skyttä
2019-05-04 00:15:38 +03:00
committed by Paul Melnikow
parent 742f287f06
commit 3b73900b8a
2 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
'use strict'
const Joi = require('joi')
const { renderVersionBadge } = require('../version')
const { BaseJsonService } = require('..')
const schema = Joi.object({
version: Joi.string().required(),
}).required()
// No way to permalink to current "stable", https://pagure.io/mdapi/issue/69
const defaultBranch = 'rawhide'
module.exports = class Fedora extends BaseJsonService {
static get category() {
return 'version'
}
static get route() {
return {
base: 'fedora/v',
pattern: ':packageName/:branch?',
}
}
static get examples() {
return [
{
title: 'Fedora package',
namedParams: { packageName: 'rpm', branch: 'rawhide' },
staticPreview: renderVersionBadge({ version: '4.14.2.1' }),
documentation:
'See <a href="https://apps.fedoraproject.org/mdapi/">mdapi docs</a> for information on valid branches.',
},
]
}
static get defaultBadgeData() {
return { label: 'fedora' }
}
async handle({ packageName, branch = defaultBranch }) {
const data = await this._requestJson({
schema,
url: `https://apps.fedoraproject.org/mdapi/${encodeURIComponent(
branch
)}/pkg/${encodeURIComponent(packageName)}`,
errorMessages: {
400: 'branch not found',
},
})
return renderVersionBadge({ version: data.version })
}
}

View File

@@ -0,0 +1,21 @@
'use strict'
const {
isVPlusDottedVersionNClausesWithOptionalSuffixAndEpoch,
} = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
t.create('Fedora package (default branch, valid)')
.get('/rpm.json')
.expectBadge({
label: 'fedora',
message: isVPlusDottedVersionNClausesWithOptionalSuffixAndEpoch,
})
t.create('Fedora package (not found)')
.get('/not-a-package/rawhide.json')
.expectBadge({ label: 'fedora', message: 'not found' })
t.create('Fedora package (branch not found)')
.get('/not-a-package/not-a-branch.json')
.expectBadge({ label: 'fedora', message: 'branch not found' })