mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
feat: add new badges for new [ansible] collection APIs (#10938)
* feat: add ansible collection v2 badge for latest version * feat: add ansible collection downloads count badge * set default galaxy version label and fixed ansible tests * apply PR requested changes * slim down schemas to minimal required elements
This commit is contained in:
parent
9b91a60c75
commit
abf0a2970b
46
services/ansible/ansible-collection-downloads.service.js
Normal file
46
services/ansible/ansible-collection-downloads.service.js
Normal file
@ -0,0 +1,46 @@
|
||||
import Joi from 'joi'
|
||||
import { renderDownloadsBadge } from '../downloads.js'
|
||||
import { BaseJsonService, pathParams } from '../index.js'
|
||||
|
||||
const ansibleCollectionSchema = Joi.object({
|
||||
// Ansible docs don't mention this but it appears in the API responses
|
||||
download_count: Joi.number().required(),
|
||||
}).required()
|
||||
|
||||
export default class AnsibleGalaxyCollectionDownloads extends BaseJsonService {
|
||||
static category = 'downloads'
|
||||
static route = { base: 'ansible/collection/d', pattern: ':namespace/:name' }
|
||||
|
||||
static openApi = {
|
||||
'/ansible/collection/d/{namespace}/{name}': {
|
||||
get: {
|
||||
summary: 'Ansible Collection Downloads',
|
||||
parameters: pathParams(
|
||||
{ name: 'namespace', example: 'community' },
|
||||
{ name: 'name', example: 'general' },
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
static defaultBadgeData = { label: 'collection downloads' }
|
||||
|
||||
static render({ downloads }) {
|
||||
return renderDownloadsBadge({ downloads })
|
||||
}
|
||||
|
||||
async fetch({ namespace, name }) {
|
||||
return this._requestJson({
|
||||
schema: ansibleCollectionSchema,
|
||||
url: `https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/index/${namespace}/${name}/`,
|
||||
})
|
||||
}
|
||||
|
||||
async handle({ namespace, name }) {
|
||||
const { download_count: downloads } = await this.fetch({
|
||||
namespace,
|
||||
name,
|
||||
})
|
||||
return this.constructor.render({ downloads })
|
||||
}
|
||||
}
|
16
services/ansible/ansible-collection-downloads.tester.js
Normal file
16
services/ansible/ansible-collection-downloads.tester.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { ServiceTester } from '../tester.js'
|
||||
import { isMetric } from '../test-validators.js'
|
||||
|
||||
export const t = new ServiceTester({
|
||||
id: 'AnsibleGalaxyCollectionDownloads',
|
||||
title: 'AnsibleGalaxyCollectionDownloads',
|
||||
pathPrefix: '/ansible/collection/d',
|
||||
})
|
||||
|
||||
t.create('collection downloads (valid)')
|
||||
.get('/community/general.json')
|
||||
.expectBadge({ label: 'collection downloads', message: isMetric })
|
||||
|
||||
t.create('collection downloads (not found)')
|
||||
.get('/not/real.json')
|
||||
.expectBadge({ label: 'collection downloads', message: 'not found' })
|
47
services/ansible/ansible-collection-version.service.js
Normal file
47
services/ansible/ansible-collection-version.service.js
Normal file
@ -0,0 +1,47 @@
|
||||
import Joi from 'joi'
|
||||
import { renderVersionBadge } from '../version.js'
|
||||
import { BaseJsonService, pathParams } from '../index.js'
|
||||
|
||||
const ansibleCollectionSchema = Joi.object({
|
||||
highest_version: Joi.object({
|
||||
version: Joi.string().required(),
|
||||
}).required(),
|
||||
}).required()
|
||||
|
||||
export default class AnsibleGalaxyCollectionVersion extends BaseJsonService {
|
||||
static category = 'version'
|
||||
static route = { base: 'ansible/collection/v', pattern: ':namespace/:name' }
|
||||
|
||||
static openApi = {
|
||||
'/ansible/collection/v/{namespace}/{name}': {
|
||||
get: {
|
||||
summary: 'Ansible Collection Version',
|
||||
parameters: pathParams(
|
||||
{ name: 'namespace', example: 'community' },
|
||||
{ name: 'name', example: 'general' },
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
static defaultBadgeData = { label: 'galaxy' }
|
||||
|
||||
static render({ version }) {
|
||||
return renderVersionBadge({ version })
|
||||
}
|
||||
|
||||
async fetch({ namespace, name }) {
|
||||
return this._requestJson({
|
||||
schema: ansibleCollectionSchema,
|
||||
url: `https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/index/${namespace}/${name}/`,
|
||||
})
|
||||
}
|
||||
|
||||
async handle({ namespace, name }) {
|
||||
const { highest_version: highestVersion } = await this.fetch({
|
||||
namespace,
|
||||
name,
|
||||
})
|
||||
return this.constructor.render({ version: highestVersion.version })
|
||||
}
|
||||
}
|
16
services/ansible/ansible-collection-version.tester.js
Normal file
16
services/ansible/ansible-collection-version.tester.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { ServiceTester } from '../tester.js'
|
||||
import { isSemver } from '../test-validators.js'
|
||||
|
||||
export const t = new ServiceTester({
|
||||
id: 'AnsibleGalaxyCollectionVersion',
|
||||
title: 'AnsibleGalaxyCollectionVersion',
|
||||
pathPrefix: '/ansible/collection/v',
|
||||
})
|
||||
|
||||
t.create('collection version (valid)')
|
||||
.get('/community/general.json')
|
||||
.expectBadge({ label: 'galaxy', message: isSemver })
|
||||
|
||||
t.create('collection version (not found)')
|
||||
.get('/not/real.json')
|
||||
.expectBadge({ label: 'galaxy', message: 'not found' })
|
@ -1,4 +1,5 @@
|
||||
import { ServiceTester } from '../tester.js'
|
||||
|
||||
export const t = new ServiceTester({
|
||||
id: 'AnsibleGalaxyCollectionName',
|
||||
title: 'AnsibleGalaxyCollectionName',
|
||||
|
Loading…
x
Reference in New Issue
Block a user