Skip to content

feat: add new badges for new [ansible] collection APIs #10938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions services/ansible/ansible-collection-downloads.service.js
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions services/ansible/ansible-collection-downloads.tester.js
Original file line number Diff line number Diff line change
@@ -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 changes: 47 additions & 0 deletions services/ansible/ansible-collection-version.service.js
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions services/ansible/ansible-collection-version.tester.js
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions services/ansible/ansible-collection.tester.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ServiceTester } from '../tester.js'

export const t = new ServiceTester({
id: 'AnsibleGalaxyCollectionName',
title: 'AnsibleGalaxyCollectionName',
Expand Down
Loading