[Ansible] Add collection badge (#8578)
* Add ansible collection badge * Ansible Collection: Remove unneccesary base class * Ansible Collection: Fix test (label "collection" rather than "role")
This commit is contained in:
46
services/ansible/ansible-collection.service.js
Normal file
46
services/ansible/ansible-collection.service.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import Joi from 'joi'
|
||||
import { BaseJsonService } from '../index.js'
|
||||
|
||||
const ansibleCollectionSchema = Joi.object({
|
||||
name: Joi.string().required(),
|
||||
namespace: Joi.object({
|
||||
name: Joi.string().required(),
|
||||
}),
|
||||
}).required()
|
||||
|
||||
class AnsibleGalaxyCollectionName extends BaseJsonService {
|
||||
static category = 'other'
|
||||
static route = { base: 'ansible/collection', pattern: ':collectionId' }
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'Ansible Collection',
|
||||
namedParams: { collectionId: '278' },
|
||||
staticPreview: this.render({
|
||||
name: 'community.general',
|
||||
}),
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'collection' }
|
||||
|
||||
static render({ name }) {
|
||||
return { message: name, color: 'blue' }
|
||||
}
|
||||
|
||||
async fetch({ collectionId }) {
|
||||
const url = `https://galaxy.ansible.com/api/v2/collections/${collectionId}/`
|
||||
return this._requestJson({
|
||||
url,
|
||||
schema: ansibleCollectionSchema,
|
||||
})
|
||||
}
|
||||
|
||||
async handle({ collectionId }) {
|
||||
const json = await this.fetch({ collectionId })
|
||||
const name = `${json.namespace.name}.${json.name}`
|
||||
return this.constructor.render({ name })
|
||||
}
|
||||
}
|
||||
|
||||
export { AnsibleGalaxyCollectionName }
|
||||
14
services/ansible/ansible-collection.tester.js
Normal file
14
services/ansible/ansible-collection.tester.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import { ServiceTester } from '../tester.js'
|
||||
export const t = new ServiceTester({
|
||||
id: 'AnsibleCollection',
|
||||
title: 'AnsibleCollection',
|
||||
pathPrefix: '/ansible/collection',
|
||||
})
|
||||
|
||||
t.create('collection name (valid)')
|
||||
.get('/278.json')
|
||||
.expectBadge({ label: 'collection', message: 'community.general' })
|
||||
|
||||
t.create('collection name (not found)')
|
||||
.get('/000.json')
|
||||
.expectBadge({ label: 'collection', message: 'not found' })
|
||||
Reference in New Issue
Block a user