-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate ansible galaxy quality score
- Loading branch information
Showing
2 changed files
with
19 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) |