Skip to content

Commit

Permalink
Align label and message props of coalesceBadge() with internal …
Browse files Browse the repository at this point in the history
…`makeBadge()` (#5719)

There is an internal `makeBadge()` function which is called from a few places in the server and from the public `makeBadge()` function which is a light wrapper. (Eventually we want to dogfood the public API: that's the work of #4950, and this helps with it by aligning the interfaces.)

Related to that is #3370, which is about aligning the `serviceData` schema (i.e. the result of `handle()`) with the public `makeBadge()` function.

A legacy quirk of the _private_ `makeBadge()` function is accepting a `text: ['label', 'message']` array instead of separate `{ label, message }` props like the rest of the codebase. `coalesceBadge()` has to translate from `{ label, message }` to `text: ['label', message']`. This removes that bit of indirection.

It also rewrites most of the tests of `coalesceBadge()` to use `.includes()`, providing IMO a slight improvement in readability.
  • Loading branch information
paulmelnikow committed Oct 16, 2020
1 parent e1bd160 commit 1184938
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 148 deletions.
6 changes: 3 additions & 3 deletions badge-maker/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ function _clean(format) {
}
})

// Legacy.
cleaned.label = cleaned.label || ''

// convert "public" format to "internal" format
cleaned.text = [cleaned.label || '', cleaned.message]
delete cleaned.label
delete cleaned.message
if ('style' in cleaned) {
cleaned.template = cleaned.style
delete cleaned.style
Expand Down
8 changes: 4 additions & 4 deletions badge-maker/lib/make-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ it is likely this will impact on the package's public interface in index.js
module.exports = function makeBadge({
format,
template = 'flat',
text,
label,
message,
color,
labelColor,
logo,
Expand All @@ -19,9 +20,8 @@ module.exports = function makeBadge({
links = ['', ''],
}) {
// String coercion and whitespace removal.
text = text.map(value => `${value}`.trim())

const [label, message] = text
label = `${label}`.trim()
message = `${message}`.trim()

// This ought to be the responsibility of the server, not `makeBadge`.
if (format === 'json') {
Expand Down
Loading

0 comments on commit 1184938

Please sign in to comment.