Skip to content
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

[Ansible] Add collection badge #8578

Merged
merged 3 commits into from
Nov 1, 2022
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.service.js
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions services/ansible/ansible-collection.tester.js
Original file line number Diff line number Diff line change
@@ -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' })