From 474b126be674a30d3b76e71273f461d41bd182d6 Mon Sep 17 00:00:00 2001
From: Paul Melnikow <github@paulmelnikow.com>
Date: Wed, 16 Jan 2019 13:37:48 -0500
Subject: [PATCH] Fix color again, for legacy badges (#2782)

Ref: https://github.com/badges/shields/pull/2780#issuecomment-454873296
---
 gh-badges/lib/make-badge.spec.js                |  2 +-
 gh-badges/templates/_shields_test-template.json |  6 ++----
 lib/badge-data.js                               | 10 ++++++++--
 services/github/github-commits-since.tester.js  |  5 ++++-
 4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/gh-badges/lib/make-badge.spec.js b/gh-badges/lib/make-badge.spec.js
index f4bfd189dc..1466f50d47 100644
--- a/gh-badges/lib/make-badge.spec.js
+++ b/gh-badges/lib/make-badge.spec.js
@@ -64,7 +64,7 @@ describe('The badge generator', function() {
         given('almostred'),
         given('brightmaroon'),
         given('cactus')
-      ).expect(undefined)
+      ).expect(null)
     })
   })
 
diff --git a/gh-badges/templates/_shields_test-template.json b/gh-badges/templates/_shields_test-template.json
index 3821a8cb05..e39706a956 100644
--- a/gh-badges/templates/_shields_test-template.json
+++ b/gh-badges/templates/_shields_test-template.json
@@ -1,9 +1,7 @@
 {
-{{?it.color}}
-  "color": {{=JSON.stringify(it.color)}},
-{{?}}
+  "color": {{=JSON.stringify(it.color || null)}},
 {{?it.labelColor}}
-  "labelColor": {{=JSON.stringify(it.labelColor)}}
+  "labelColor": {{=JSON.stringify(it.labelColor)}},
 {{?}}
   "name": {{=JSON.stringify(it.text[0])}},
   "value": {{=JSON.stringify(it.text[1])}}
diff --git a/lib/badge-data.js b/lib/badge-data.js
index dc75f84eea..f2931dc8e6 100644
--- a/lib/badge-data.js
+++ b/lib/badge-data.js
@@ -107,8 +107,14 @@ function makeBadgeData(defaultLabel, overrides) {
     logoWidth: +overrides.logoWidth,
     links: toArray(overrides.link),
     // Scoutcamp sometimes turns these into numbers.
-    colorA: `${overrides.colorA}`,
-    colorB: `${overrides.colorB}`,
+    colorA:
+      typeof overrides.colorA === 'number'
+        ? `${overrides.colorA}`
+        : overrides.colorA,
+    colorB:
+      typeof overrides.colorB === 'number'
+        ? `${overrides.colorB}`
+        : overrides.colorB,
   }
 }
 
diff --git a/services/github/github-commits-since.tester.js b/services/github/github-commits-since.tester.js
index 39d4a65ac2..2673222373 100644
--- a/services/github/github-commits-since.tester.js
+++ b/services/github/github-commits-since.tester.js
@@ -5,11 +5,14 @@ const Joi = require('joi')
 const t = (module.exports = require('../create-service-tester')())
 
 t.create('Commits since')
-  .get('/badges/shields/a0663d8da53fb712472c02665e6ff7547ba945b7.json')
+  .get(
+    '/badges/shields/a0663d8da53fb712472c02665e6ff7547ba945b7.json?style=_shields_test'
+  )
   .expectJSONTypes(
     Joi.object().keys({
       name: Joi.string().regex(/^(commits since){1}[\s\S]+$/),
       value: Joi.string().regex(/^\w+$/),
+      color: 'blue',
     })
   )
 
-- 
GitLab