mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
Refactor version rendering in [wordpress nexus] and [f-droid] services (#10608)
* Refactor version rendering in f-droid, nexus, and wordpress services * add missing label in nexus test
This commit is contained in:
parent
9ab1a906b2
commit
d00c4de4a3
@ -3,8 +3,7 @@ import {
|
||||
optionalNonNegativeInteger,
|
||||
nonNegativeInteger,
|
||||
} from '../validators.js'
|
||||
import { addv } from '../text-formatters.js'
|
||||
import { version as versionColor } from '../color-formatters.js'
|
||||
import { renderVersionBadge } from '../version.js'
|
||||
import { BaseJsonService, NotFound, pathParam, queryParam } from '../index.js'
|
||||
|
||||
const schema = Joi.object({
|
||||
@ -46,13 +45,6 @@ export default class FDroid extends BaseJsonService {
|
||||
|
||||
static defaultBadgeData = { label: 'f-droid' }
|
||||
|
||||
static render({ version }) {
|
||||
return {
|
||||
message: addv(version),
|
||||
color: versionColor(version),
|
||||
}
|
||||
}
|
||||
|
||||
async fetch({ appId }) {
|
||||
const url = `https://f-droid.org/api/v1/packages/${appId}`
|
||||
return this._requestJson({
|
||||
@ -83,6 +75,6 @@ export default class FDroid extends BaseJsonService {
|
||||
const json = await this.fetch({ appId })
|
||||
const suggested = includePre === undefined
|
||||
const { version } = this.transform({ json, suggested })
|
||||
return this.constructor.render({ version })
|
||||
return renderVersionBadge({ version })
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import Joi from 'joi'
|
||||
import { version as versionColor } from '../color-formatters.js'
|
||||
import { addv } from '../text-formatters.js'
|
||||
import { renderVersionBadge } from '../version.js'
|
||||
import {
|
||||
optionalUrl,
|
||||
optionalDottedVersionNClausesWithOptionalSuffix,
|
||||
@ -143,13 +142,6 @@ export default class Nexus extends BaseJsonService {
|
||||
label: 'nexus',
|
||||
}
|
||||
|
||||
static render({ version }) {
|
||||
return {
|
||||
message: addv(version),
|
||||
color: versionColor(version),
|
||||
}
|
||||
}
|
||||
|
||||
addQueryParamsToQueryString({ searchParams, queryOpt }) {
|
||||
// Users specify query options with 'key=value' pairs, using a
|
||||
// colon delimiter between pairs ([:k1=v1[:k2=v2[...]]]).
|
||||
@ -321,6 +313,6 @@ export default class Nexus extends BaseJsonService {
|
||||
})
|
||||
|
||||
const { version } = this.transform({ repo, json, actualNexusVersion })
|
||||
return this.constructor.render({ version })
|
||||
return renderVersionBadge({ version })
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,7 @@ describe('Nexus', function () {
|
||||
},
|
||||
),
|
||||
).to.deep.equal({
|
||||
label: undefined,
|
||||
message: 'v2.3.4',
|
||||
color: 'blue',
|
||||
})
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { pathParams } from '../index.js'
|
||||
import { addv } from '../text-formatters.js'
|
||||
import { version as versionColor } from '../color-formatters.js'
|
||||
import { renderVersionBadge } from '../version.js'
|
||||
import { description, BaseWordpress } from './wordpress-base.js'
|
||||
|
||||
function VersionForExtensionType(extensionType) {
|
||||
@ -43,19 +42,12 @@ function VersionForExtensionType(extensionType) {
|
||||
|
||||
static defaultBadgeData = { label: extensionType }
|
||||
|
||||
static render({ version }) {
|
||||
return {
|
||||
message: addv(version),
|
||||
color: versionColor(version),
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ slug }) {
|
||||
const { version } = await this.fetch({
|
||||
extensionType,
|
||||
slug,
|
||||
})
|
||||
return this.constructor.render({ version })
|
||||
return renderVersionBadge({ version })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user