1
0
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:
Ari Kalfus 2025-03-13 14:00:29 -04:00 committed by GitHub
parent 9b91a60c75
commit abf0a2970b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 126 additions and 0 deletions

View 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 })
}
}

View 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' })

View 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 })
}
}

View 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' })

View File

@ -1,4 +1,5 @@
import { ServiceTester } from '../tester.js'
export const t = new ServiceTester({
id: 'AnsibleGalaxyCollectionName',
title: 'AnsibleGalaxyCollectionName',