Skip to content

Commit

Permalink
deprecate ansible galaxy quality score
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Oct 10, 2023
1 parent 11842f0 commit 4031366
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 65 deletions.
63 changes: 11 additions & 52 deletions services/ansible/ansible-quality.service.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,11 @@
import Joi from 'joi'
import { floorCount } from '../color-formatters.js'
import { BaseJsonService, InvalidResponse, pathParams } from '../index.js'

const ansibleContentSchema = Joi.object({
quality_score: Joi.number().allow(null).required(),
}).required()

class AnsibleGalaxyContent extends BaseJsonService {
async fetch({ projectId }) {
const url = `https://galaxy.ansible.com/api/v1/content/${projectId}/`
return this._requestJson({
url,
schema: ansibleContentSchema,
})
}
}

export default class AnsibleGalaxyContentQualityScore extends AnsibleGalaxyContent {
static category = 'analysis'
static route = { base: 'ansible/quality', pattern: ':projectId' }

static openApi = {
'/ansible/quality/{projectId}': {
get: {
summary: 'Ansible Quality Score',
parameters: pathParams({ name: 'projectId', example: '432' }),
},
},
}

static defaultBadgeData = { label: 'quality' }

static render({ qualityScore }) {
return {
message: qualityScore,
color: floorCount(qualityScore, 2, 3, 4),
}
}

async handle({ projectId }) {
const { quality_score: qualityScore } = await this.fetch({ projectId })

if (qualityScore === null) {
throw new InvalidResponse({
prettyMessage: 'no score available',
})
}

return this.constructor.render({ qualityScore })
}
}
import { deprecatedService } from '../index.js'

export const AnsibleGalaxyContentQualityScore = deprecatedService({
category: 'analysis',
route: {
base: 'ansible/quality',
pattern: ':projectId',
},
label: 'quality',
dateAdded: new Date('2023-10-10'),
})
21 changes: 8 additions & 13 deletions services/ansible/ansible-quality.tester.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { nonNegativeInteger } from '../validators.js'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
import { ServiceTester } from '../tester.js'
export const t = new ServiceTester({
id: 'AnsibleGalaxyContentQualityScore',
title: 'AnsibleGalaxyContentQualityScore',
pathPrefix: '/ansible/quality',
})

t.create('quality score (valid)')
t.create('quality score')
.get('/432.json')
.expectBadge({ label: 'quality', message: nonNegativeInteger })

t.create('quality score (project not found)')
.get('/0101.json')
.expectBadge({ label: 'quality', message: 'not found' })

t.create('quality score (no score available)')
.get('/2504.json')
.expectBadge({ label: 'quality', message: 'no score available' })
.expectBadge({ label: 'quality', message: 'no longer available' })

0 comments on commit 4031366

Please sign in to comment.