diff --git a/lib/badge-data.js b/lib/badge-data.js index e095fe42f7..2df638f54d 100644 --- a/lib/badge-data.js +++ b/lib/badge-data.js @@ -96,4 +96,5 @@ module.exports = { makeLabel, makeLogo, makeBadgeData, + makeColor }; diff --git a/server.js b/server.js index 276e41c13f..8ae2779dda 100644 --- a/server.js +++ b/server.js @@ -65,6 +65,7 @@ const { getAnalytics } = require('./lib/analytics'); const { + makeColor, isValidStyle, isSixHex: sixHex, makeLabel: getLabel, @@ -6129,7 +6130,7 @@ cache(function(data, match, sendBadge, request) { badgeData.text[0] = data.label || ghLabel; badgeData.text[1] = '' + count; badgeData.colorscheme = null; - badgeData.colorB = '#' + (color || '78bdf2'); + badgeData.colorB = makeColor(data.colorB || color || '78bdf2'); sendBadge(format, badgeData); } catch(e) { badgeData.text[1] = 'invalid'; diff --git a/service-tests/waffle.js b/service-tests/waffle.js new file mode 100644 index 0000000000..f7727fc8cc --- /dev/null +++ b/service-tests/waffle.js @@ -0,0 +1,52 @@ +const Joi = require('joi'); +const ServiceTester = require('./runner/service-tester'); + +const t = new ServiceTester({ id: 'waffle', title: 'Waffle.io' }); +module.exports = t; + + +const fakeData = [ + { + githubMetadata: { + labels: [ + { color: "c5def5", name: "feature" }, + { color: "fbca04", name: "bug" }, + { color: "e11d21", name: "bug" } + ] + } + }, + { + githubMetadata: { + labels: [ + { color: "c5def5", name: "feature" }, + { color: "fbca04", name: "bug" }, + { color: "e11d21", name: "feature" } + ] + } + }, + { + githubMetadata: { + labels: [ + { color: "c5def5", name: "bug" }, + { color: "fbca04", name: "bug" } + ] + } + }, +]; + +t.create('label should be `bug` & value should be exactly 5 as supplied in `fakeData`. e.g: bug|5') + .get('/label/userName/repoName/bug.json') + .intercept(nock => nock('https://api.waffle.io/') + .get('/userName/repoName/cards') + .reply(200, fakeData)) + .expectJSONTypes(Joi.object().keys({ + name: Joi.equal('bug'), + value: Joi.equal('5') + })); + +t.create('label should be `Mybug` & value should be formated. e.g: Mybug|25') + .get('/label/ritwickdey/vscode-live-server/bug.json?label=Mybug') + .expectJSONTypes(Joi.object().keys({ + name: Joi.equal('Mybug'), + value: Joi.string().regex(/^\d+$/) + }));