From d00c4de4a369d5d032d375e43e8b7d821cc5e2d0 Mon Sep 17 00:00:00 2001 From: jNullj <15849761+jNullj@users.noreply.github.com> Date: Sun, 13 Oct 2024 20:10:17 +0300 Subject: [PATCH] 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 --- services/f-droid/f-droid.service.js | 12 ++---------- services/nexus/nexus.service.js | 12 ++---------- services/nexus/nexus.spec.js | 1 + services/wordpress/wordpress-version.service.js | 12 ++---------- 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/services/f-droid/f-droid.service.js b/services/f-droid/f-droid.service.js index 02f5ab3ee9872..bc2d36717d1fe 100644 --- a/services/f-droid/f-droid.service.js +++ b/services/f-droid/f-droid.service.js @@ -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 }) } } diff --git a/services/nexus/nexus.service.js b/services/nexus/nexus.service.js index bcb0a2a07f79b..a6bd0cea0cc62 100644 --- a/services/nexus/nexus.service.js +++ b/services/nexus/nexus.service.js @@ -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 }) } } diff --git a/services/nexus/nexus.spec.js b/services/nexus/nexus.spec.js index 1f4114bfdc61a..f0ce13c258506 100644 --- a/services/nexus/nexus.spec.js +++ b/services/nexus/nexus.spec.js @@ -154,6 +154,7 @@ describe('Nexus', function () { }, ), ).to.deep.equal({ + label: undefined, message: 'v2.3.4', color: 'blue', }) diff --git a/services/wordpress/wordpress-version.service.js b/services/wordpress/wordpress-version.service.js index 8e7432bf16393..3fb9273bbfa58 100644 --- a/services/wordpress/wordpress-version.service.js +++ b/services/wordpress/wordpress-version.service.js @@ -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 }) } } }