Skip to content

Commit

Permalink
Refactor version rendering in [wordpress nexus] and [f-droid] services (
Browse files Browse the repository at this point in the history
#10608)

* Refactor version rendering in f-droid, nexus, and wordpress services

* add missing label in nexus test
  • Loading branch information
jNullj authored Oct 13, 2024
1 parent 9ab1a90 commit d00c4de
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
12 changes: 2 additions & 10 deletions services/f-droid/f-droid.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 })
}
}
12 changes: 2 additions & 10 deletions services/nexus/nexus.service.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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[...]]]).
Expand Down Expand Up @@ -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 })
}
}
1 change: 1 addition & 0 deletions services/nexus/nexus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('Nexus', function () {
},
),
).to.deep.equal({
label: undefined,
message: 'v2.3.4',
color: 'blue',
})
Expand Down
12 changes: 2 additions & 10 deletions services/wordpress/wordpress-version.service.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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 })
}
}
}
Expand Down

0 comments on commit d00c4de

Please sign in to comment.