Add [ArchLinux] package version support (#3374)

This commit is contained in:
Ville Skyttä
2019-04-28 23:19:42 +03:00
committed by chris48s
parent 2806eb8a00
commit 75def85eca
2 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
'use strict'
const Joi = require('joi')
const { renderVersionBadge } = require('../version')
const { BaseJsonService } = require('..')
const schema = Joi.object({
pkgver: Joi.string().required(),
}).required()
module.exports = class ArchLinux extends BaseJsonService {
static get category() {
return 'version'
}
static get route() {
return {
base: 'archlinux/v',
pattern: ':repository/:architecture/:packageName',
}
}
static get examples() {
return [
{
title: 'Arch Linux package',
namedParams: {
architecture: 'x86_64',
repository: 'core',
packageName: 'pacman',
},
staticPreview: renderVersionBadge({ version: '5.1.3' }),
},
]
}
static get defaultBadgeData() {
return { label: 'arch linux' }
}
async handle({ repository, architecture, packageName }) {
const data = await this._requestJson({
schema,
url: `https://www.archlinux.org/packages/${repository}/${architecture}/${packageName}/json/`,
})
return renderVersionBadge({ version: data.pkgver })
}
}

View File

@@ -0,0 +1,38 @@
'use strict'
const {
isVPlusDottedVersionNClausesWithOptionalSuffix,
} = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
t.create('Arch Linux package (valid)')
.get('/core/x86_64/pacman.json')
.expectBadge({
label: 'arch linux',
message: isVPlusDottedVersionNClausesWithOptionalSuffix,
})
t.create('Arch Linux package (valid, mocked response)')
.get('/core/x86_64/pacman.json')
.intercept(nock =>
nock('https://www.archlinux.org')
.get('/packages/core/x86_64/pacman/json/')
.reply(200, {
pkgname: 'pacman',
pkgver: '5.1.3',
pkgrel: '1',
})
)
.expectBadge({ label: 'arch linux', message: 'v5.1.3' })
t.create('Arch Linux package (repository not found)')
.get('/not-a-repository/x86_64/pacman.json')
.expectBadge({ label: 'arch linux', message: 'not found' })
t.create('Arch Linux package (architecture not found)')
.get('/core/not-an-architecture/pacman.json')
.expectBadge({ label: 'arch linux', message: 'not found' })
t.create('Arch Linux package (not found)')
.get('/core/x86_64/not-a-package.json')
.expectBadge({ label: 'arch linux', message: 'not found' })