Skip to content

Commit

Permalink
remove logoWidth param (#10878)
Browse files Browse the repository at this point in the history
* remove `logoWidth` param
Fixes #10285

* remove `logoWidth` param
Fixes #10285

* fix: add `logoWidth` parameter to BaseService test
  • Loading branch information
jNullj authored Mar 2, 2025
1 parent 779f8ae commit 42e7808
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 43 deletions.
5 changes: 0 additions & 5 deletions core/base-service/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ const optionalStringWhenNamedLogoPresent = Joi.alternatives().conditional(
},
)

const optionalNumberWhenAnyLogoPresent = Joi.alternatives()
.conditional('namedLogo', { is: Joi.string().required(), then: Joi.number() })
.conditional('logoSvg', { is: Joi.string().required(), then: Joi.number() })

const serviceDataSchema = Joi.object({
isError: Joi.boolean(),
label: Joi.string().allow(''),
Expand All @@ -66,7 +62,6 @@ const serviceDataSchema = Joi.object({
logoSvg: Joi.string(),
logoColor: optionalStringWhenNamedLogoPresent,
logoSize: optionalStringWhenNamedLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
cacheSeconds: Joi.number().integer().min(0),
style: Joi.string(),
})
Expand Down
14 changes: 3 additions & 11 deletions core/base-service/coalesce-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import toArray from './to-array.js'
// 1. When `?logo=` contains a simple-icons logo or contains a base64-encoded
// SVG, that logo is used. When a `&logoColor=` is specified, that color is
// used (except for the base64-encoded logos). Otherwise the default color
// is used. The appearance of the logo can be customized using `logoWidth`,
// is used.
// When `?logo=` is specified, any logo-related parameters specified
// dynamically by the service, or by default in the service, are ignored.
// 2. The second precedence is the dynamic logo returned by a service. This is
Expand Down Expand Up @@ -52,11 +52,7 @@ export default function coalesceBadge(
colorB: legacyOverrideColor,
colorA: legacyOverrideLabelColor,
} = overrides
let {
logoWidth: overrideLogoWidth,
color: overrideColor,
labelColor: overrideLabelColor,
} = overrides
let { color: overrideColor, labelColor: overrideLabelColor } = overrides

// Only use the legacy properties if the new ones are not provided
if (typeof overrideColor === 'undefined') {
Expand All @@ -73,7 +69,6 @@ export default function coalesceBadge(
if (typeof overrideLabelColor === 'number') {
overrideLabelColor = `${overrideLabelColor}`
}
overrideLogoWidth = +overrideLogoWidth || undefined

const {
isError,
Expand All @@ -85,7 +80,6 @@ export default function coalesceBadge(
namedLogo: serviceNamedLogo,
logoColor: serviceLogoColor,
logoSize: serviceLogoSize,
logoWidth: serviceLogoWidth,
link: serviceLink,
cacheSeconds: serviceCacheSeconds,
style: serviceStyle,
Expand Down Expand Up @@ -131,7 +125,6 @@ export default function coalesceBadge(
// If the logo has been overridden it does not make sense to inherit the
// original width or position.
logoSize = overrideLogoSize
logoWidth = overrideLogoWidth
} else {
if (serviceLogoSvg) {
logoSvgBase64 = svg2base64(serviceLogoSvg)
Expand All @@ -143,12 +136,11 @@ export default function coalesceBadge(
namedLogoColor = coalesce(overrideLogoColor, serviceLogoColor)
}
logoSize = coalesce(overrideLogoSize, serviceLogoSize)
logoWidth = coalesce(overrideLogoWidth, serviceLogoWidth)
}
if (namedLogo) {
const iconSize = getIconSize(String(namedLogo).toLowerCase())

if (!logoWidth && iconSize && logoSize === 'auto') {
if (iconSize && logoSize === 'auto') {
logoWidth = (iconSize.width / iconSize.height) * DEFAULT_LOGO_HEIGHT
}

Expand Down
15 changes: 0 additions & 15 deletions core/base-service/coalesce-badge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ describe('coalesceBadge', function () {
{
namedLogo: 'appveyor',
logoColor: 'red',
logoWidth: 100,
},
{},
).logo,
Expand Down Expand Up @@ -246,20 +245,6 @@ describe('coalesceBadge', function () {
})
})

describe('Logo width', function () {
it('overrides the logoWidth', function () {
expect(coalesceBadge({ logoWidth: 20 }, {}, {})).to.include({
logoWidth: 20,
})
})

it('applies the logo width', function () {
expect(
coalesceBadge({}, { namedLogo: 'npm', logoWidth: 275 }, {}),
).to.include({ logoWidth: 275 })
})
})

describe('Links', function () {
it('overrides the links', function () {
expect(
Expand Down
1 change: 0 additions & 1 deletion core/base-service/legacy-request-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const globalQueryParams = new Set([
'logo',
'logoColor',
'logoSize',
'logoWidth',
'link',
'colorA',
'colorB',
Expand Down
2 changes: 1 addition & 1 deletion services/endpoint-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const endpointSchema = Joi.object({
logoSvg: Joi.string(),
logoColor: optionalStringWhenNamedLogoPresent,
logoSize: optionalStringWhenNamedLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
style: Joi.string(),
cacheSeconds: Joi.number().integer().min(0),
/*
Expand All @@ -45,6 +44,7 @@ const endpointSchema = Joi.object({
passing it should not throw an error
*/
logoPosition: optionalNumberWhenAnyLogoPresent,
logoWidth: optionalNumberWhenAnyLogoPresent,
})
// `namedLogo` or `logoSvg`; not both.
.oxor('namedLogo', 'logoSvg')
Expand Down
9 changes: 0 additions & 9 deletions services/endpoint/endpoint.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ The endpoint badge takes a single required query param: <code>url</code>, which
Supported for simple-icons logos only.
</td>
</tr>
<tr>
<td><code>logoWidth</code></td>
<td>
Default: none. Same meaning as the query string. Can be overridden by
the query string.
</td>
</tr>
<tr>
<td><code>style</code></td>
<td>
Expand Down Expand Up @@ -156,7 +149,6 @@ export default class Endpoint extends BaseJsonService {
logoSvg,
logoColor,
logoSize,
logoWidth,
style,
cacheSeconds,
}) {
Expand All @@ -170,7 +162,6 @@ export default class Endpoint extends BaseJsonService {
logoSvg,
logoColor,
logoSize,
logoWidth,
style,
// don't allow the user to set cacheSeconds any shorter than this._cacheLength
cacheSeconds: Math.max(
Expand Down
3 changes: 2 additions & 1 deletion services/endpoint/endpoint.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ t.create('custom svg logo')
expect(body).to.include(getSimpleIcon({ name: 'npm' }))
})

// The logoWidth param was removed, but passing it should not
// throw a validation error. It should just do nothing.
t.create('logoWidth')
.get('.json?url=https://example.com/badge')
.intercept(nock =>
Expand All @@ -132,7 +134,6 @@ t.create('logoWidth')
.expectBadge({
label: 'hey',
message: 'yo',
logoWidth: 30,
})

// The logoPosition param was removed, but passing it should not
Expand Down

0 comments on commit 42e7808

Please sign in to comment.