Refactor badge color functions (#2742)

- Replace the idea of color schemes with the idea of named colors (since none of our colorschemes have used `colorA`)
- Pass through the normalized color to `_shields_test` to harmonize with BaseService and simplify testing
    - Update service tests
- Move responsibility for color generation into the npm package
- Remove several color helper functions and their tests
- Update gh-badge public API to accept `color` and `labelColor`

This is a precursor to refactoring some of the logo code for #2473.
This commit is contained in:
Paul Melnikow
2019-01-15 16:43:33 -05:00
committed by GitHub
parent cab689706f
commit 4597d77015
81 changed files with 492 additions and 669 deletions

View File

@@ -2,7 +2,6 @@
const LegacyService = require('../legacy-service')
const {
makeColorB,
makeLabel: getLabel,
makeBadgeData: getBadgeData,
makeLogo: getLogo,
@@ -116,11 +115,8 @@ module.exports = class GithubIssueDetail extends LegacyService {
switch (which) {
case 's': {
const state = (badgeData.text[1] = parsedData.state)
badgeData.colorscheme = null
badgeData.colorB = makeColorB(
githubStateColor(state),
queryParams
)
badgeData.colorscheme = undefined
badgeData.colorB = queryParams.colorB || githubStateColor(state)
break
}
case 'title':
@@ -136,21 +132,17 @@ module.exports = class GithubIssueDetail extends LegacyService {
.map(i => i.name)
.join(' | ')
if (parsedData.labels.length === 1) {
badgeData.colorscheme = null
badgeData.colorB = makeColorB(
parsedData.labels[0].color,
queryParams
)
badgeData.colorscheme = undefined
badgeData.colorB =
queryParams.colorB || parsedData.labels[0].color
}
break
case 'comments': {
badgeData.text[0] = getLabel('comments', queryParams)
const comments = (badgeData.text[1] = parsedData.comments)
badgeData.colorscheme = null
badgeData.colorB = makeColorB(
githubCommentsColor(comments),
queryParams
)
badgeData.colorscheme = undefined
badgeData.colorB =
queryParams.coloB || githubCommentsColor(comments)
break
}
case 'age':