From d1c86675ff0e11155f096145c7eb6e496e431bd8 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Thu, 2 May 2024 20:59:15 +0800 Subject: [PATCH] feat(endpoint-badge): add logoSize support --- core/base-service/base.js | 1 + services/endpoint-common.js | 1 + services/endpoint/endpoint.service.js | 10 ++++++++++ services/endpoint/endpoint.tester.js | 16 ++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/core/base-service/base.js b/core/base-service/base.js index 4b7e460955143..86bd19f628259 100644 --- a/core/base-service/base.js +++ b/core/base-service/base.js @@ -65,6 +65,7 @@ const serviceDataSchema = Joi.object({ namedLogo: Joi.string(), logoSvg: Joi.string(), logoColor: optionalStringWhenNamedLogoPresent, + logoSize: optionalStringWhenNamedLogoPresent, logoWidth: optionalNumberWhenAnyLogoPresent, logoPosition: optionalNumberWhenAnyLogoPresent, cacheSeconds: Joi.number().integer().min(0), diff --git a/services/endpoint-common.js b/services/endpoint-common.js index fabf483d057fb..868fbd7d87477 100644 --- a/services/endpoint-common.js +++ b/services/endpoint-common.js @@ -35,6 +35,7 @@ const endpointSchema = Joi.object({ namedLogo: Joi.string(), logoSvg: Joi.string(), logoColor: optionalStringWhenNamedLogoPresent, + logoSize: optionalStringWhenNamedLogoPresent, logoWidth: optionalNumberWhenAnyLogoPresent, logoPosition: optionalNumberWhenAnyLogoPresent, style: Joi.string(), diff --git a/services/endpoint/endpoint.service.js b/services/endpoint/endpoint.service.js index 80a0664f89c19..484a36ecad144 100644 --- a/services/endpoint/endpoint.service.js +++ b/services/endpoint/endpoint.service.js @@ -95,6 +95,14 @@ The endpoint badge takes a single required query param: url, which named logo will be used and colored. + + logoSize + + Default: none. Make icons adaptively resize by setting auto. + Useful for some wider logos like amd and amg. + Supported for simple-icons logos only. + + logoWidth @@ -156,6 +164,7 @@ export default class Endpoint extends BaseJsonService { namedLogo, logoSvg, logoColor, + logoSize, logoWidth, logoPosition, style, @@ -170,6 +179,7 @@ export default class Endpoint extends BaseJsonService { namedLogo, logoSvg, logoColor, + logoSize, logoWidth, logoPosition, style, diff --git a/services/endpoint/endpoint.tester.js b/services/endpoint/endpoint.tester.js index 2fb43865b1a7a..7a57c9a6348b9 100644 --- a/services/endpoint/endpoint.tester.js +++ b/services/endpoint/endpoint.tester.js @@ -82,6 +82,22 @@ t.create('named logo with color') expect(body).to.include(getSimpleIcon({ name: 'github', color: 'blue' })) }) +t.create('named logo with size') + .get('.svg?url=https://example.com/badge') + .intercept(nock => + nock('https://example.com/').get('/badge').reply(200, { + schemaVersion: 1, + label: 'hey', + message: 'yo', + namedLogo: 'github', + logoSize: 'auto', + }), + ) + .after((err, res, body) => { + expect(err).not.to.be.ok + expect(body).to.include(getSimpleIcon({ name: 'github', logoSize: 'auto' })) + }) + const logoSvg = Buffer.from( getShieldsIcon({ name: 'npm' }).replace('data:image/svg+xml;base64,', ''), 'base64',