Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove logoWidth param #10878

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions badge-maker/lib/make-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { normalizeColor, toSvgColor } = require('./color')
const badgeRenderers = require('./badge-renderers')
const { stripXmlWhitespace } = require('./xml')
const { DEFAULT_LOGO_HEIGHT } = require('./constants')
const { getIconSize } = require('./svg-helpers.js')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svg-helpers.js resides at /lib and not inside the lib of badge-maker /badge-maker/lib
😵


/*
note: makeBadge() is fairly thinly wrapped so if we are making changes here
Expand All @@ -17,21 +18,29 @@ module.exports = function makeBadge({
color,
labelColor,
logo,
namedLogo,
logoSize,
logoWidth,
links = ['', ''],
idSuffix,
}) {
// String coercion and whitespace removal.
label = `${label}`.trim()
message = `${message}`.trim()

let logoWidth = logo ? DEFAULT_LOGO_HEIGHT : 0
if (namedLogo && logoSize === 'auto') {
const iconSize = getIconSize(String(namedLogo).toLowerCase())

if (iconSize) {
logoWidth = (iconSize.width / iconSize.height) * DEFAULT_LOGO_HEIGHT
}
}

// This ought to be the responsibility of the server, not `makeBadge`.
if (format === 'json') {
return JSON.stringify({
label,
message,
logoWidth,
// Only call normalizeColor for the JSON case: this is handled
// internally by toSvgColor in the SVG case.
color: normalizeColor(color),
Expand All @@ -48,8 +57,6 @@ module.exports = function makeBadge({
throw new Error(`Unknown badge style: '${style}'`)
}

logoWidth = +logoWidth || (logo ? DEFAULT_LOGO_HEIGHT : 0)

return stripXmlWhitespace(
render({
label,
Expand Down
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
1 change: 0 additions & 1 deletion core/base-service/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ describe('BaseService', function () {
style: 'flat',
namedLogo: undefined,
logo: undefined,
logoWidth: undefined,
logoSize: undefined,
links: [],
labelColor: undefined,
Expand Down
21 changes: 3 additions & 18 deletions core/base-service/coalesce-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import {
decodeDataUrlFromQueryParam,
prepareNamedLogo,
} from '../../lib/logos.js'
import { svg2base64, getIconSize } from '../../lib/svg-helpers.js'
import { DEFAULT_LOGO_HEIGHT } from '../../badge-maker/lib/constants.js'
import { svg2base64 } from '../../lib/svg-helpers.js'
import coalesce from './coalesce.js'
import toArray from './to-array.js'

Expand All @@ -20,7 +19,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 +51,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 +68,6 @@ export default function coalesceBadge(
if (typeof overrideLabelColor === 'number') {
overrideLabelColor = `${overrideLabelColor}`
}
overrideLogoWidth = +overrideLogoWidth || undefined

const {
isError,
Expand All @@ -85,7 +79,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 +124,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,15 +135,8 @@ 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') {
logoWidth = (iconSize.width / iconSize.height) * DEFAULT_LOGO_HEIGHT
}

logoSvgBase64 = prepareNamedLogo({
name: namedLogo,
color: namedLogoColor,
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
Loading