1
0
mirror of https://github.com/badges/shields.git synced 2025-04-18 19:44:04 +03:00

deprecate [redmine] plugin rating badges (#9568)

* deprecate [redmine] badges

* Update services/redmine/redmine.service.js

* Update services/redmine/redmine.service.js

---------

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
This commit is contained in:
chris48s 2023-09-17 08:16:09 +01:00 committed by GitHub
parent 48458206f9
commit c2bbe97fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 87 deletions

View File

@ -1,79 +1,21 @@
import Joi from 'joi'
import { starRating } from '../text-formatters.js'
import { floorCount as floorCountColor } from '../color-formatters.js'
import { BaseXmlService } from '../index.js'
import { deprecatedService } from '../index.js'
const schema = Joi.object({
'redmine-plugin': Joi.object({
'ratings-average': Joi.number().min(0).required(),
}).required(),
export const RedminePluginRating = deprecatedService({
category: 'rating',
route: {
base: 'redmine/plugin/rating',
pattern: ':various*',
},
label: 'redmine',
dateAdded: new Date('2023-09-14'),
})
class BaseRedminePluginRating extends BaseXmlService {
static category = 'rating'
static render({ rating }) {
throw new Error(`render() function not implemented for ${this.name}`)
}
async fetch({ plugin }) {
const url = `https://www.redmine.org/plugins/${plugin}.xml`
return this._requestXml({ schema, url })
}
async handle({ plugin }) {
const data = await this.fetch({ plugin })
const rating = data['redmine-plugin']['ratings-average']
return this.constructor.render({ rating })
}
}
class RedminePluginRating extends BaseRedminePluginRating {
static route = {
base: 'redmine/plugin/rating',
pattern: ':plugin',
}
static examples = [
{
title: 'Plugin on redmine.org',
namedParams: { plugin: 'redmine_xlsx_format_issue_exporter' },
staticPreview: this.render({ rating: 5 }),
},
]
static defaultBadgeData = { label: 'redmine' }
static render({ rating }) {
return {
label: 'rating',
message: `${rating.toFixed(1)}/5.0`,
color: floorCountColor(rating, 2, 3, 4),
}
}
}
class RedminePluginStars extends BaseRedminePluginRating {
static route = {
export const RedminePluginStars = deprecatedService({
category: 'rating',
route: {
base: 'redmine/plugin/stars',
pattern: ':plugin',
}
static examples = [
{
title: 'Plugin on redmine.org',
namedParams: { plugin: 'redmine_xlsx_format_issue_exporter' },
staticPreview: this.render({ rating: 5 }),
},
]
static render({ rating }) {
return {
label: 'stars',
message: starRating(Math.round(rating)),
color: floorCountColor(rating, 2, 3, 4),
}
}
}
export { RedminePluginRating, RedminePluginStars }
pattern: ':various*',
},
label: 'redmine',
dateAdded: new Date('2023-09-14'),
})

View File

@ -1,6 +1,4 @@
import Joi from 'joi'
import { ServiceTester } from '../tester.js'
import { isStarRating } from '../test-validators.js'
export const t = new ServiceTester({
id: 'redmine',
@ -10,20 +8,13 @@ export const t = new ServiceTester({
t.create('plugin rating')
.get('/plugin/rating/redmine_xlsx_format_issue_exporter.json')
.expectBadge({
label: 'rating',
message: Joi.string().regex(/^[0-9]+\.[0-9]+\/5\.0$/),
label: 'redmine',
message: 'no longer available',
})
t.create('plugin stars')
.get('/plugin/stars/redmine_xlsx_format_issue_exporter.json')
.expectBadge({
label: 'stars',
message: isStarRating,
})
t.create('plugin not found')
.get('/plugin/rating/plugin_not_found.json')
.expectBadge({
label: 'redmine',
message: 'not found',
message: 'no longer available',
})