Skip to content

Commit

Permalink
Merge branch 'master' into symfony-stars
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB authored Feb 20, 2019
2 parents 6ff47bd + 144d163 commit 3859150
Show file tree
Hide file tree
Showing 92 changed files with 3,054 additions and 1,675 deletions.
18 changes: 9 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- save_cache:
paths:
Expand All @@ -37,7 +37,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- save_cache:
paths:
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Linter
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Integration tests
Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Integration tests
Expand All @@ -191,7 +191,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Danger
Expand All @@ -215,7 +215,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Prepare frontend tests
Expand Down Expand Up @@ -250,7 +250,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Identify services tagged in the PR title
Expand Down Expand Up @@ -280,7 +280,7 @@ jobs:

- run:
name: Install dependencies
command: npm install
command: npm ci

- run:
name: Identify services tagged in the PR title
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ports:
- port: 8080
tasks:
- init: npm install && npm run build
- init: npm ci && npm run build
command: node server 8080 0.0.0.0
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package.json
package-lock.json
/__snapshots__
/.next
/.cache
/build
/public
/coverage
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8.9.4-alpine
FROM node:8-alpine

RUN apk add --no-cache gettext imagemagick librsvg git

Expand All @@ -10,9 +10,9 @@ ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

COPY package.json package-lock.json /usr/src/app/
# Without the gh-badges package.json and CLI script in place, `npm install` will fail.
# Without the gh-badges package.json and CLI script in place, `npm ci` will fail.
COPY gh-badges /usr/src/app/gh-badges/
RUN npm install
RUN npm ci

COPY . /usr/src/app
RUN npm run build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ You can read a [tutorial on how to add a badge][tutorial].
1. Install Node 8 or later. You can use the [package manager][] of your choice.
Tests need to pass in Node 8 and 9.
2. Clone this repository.
3. Run `npm install` to install the dependencies.
3. Run `npm ci` to install the dependencies.
4. Run `npm start` to start the server.
5. Open `http://localhost:3000/` to view the frontend.

Expand Down
2 changes: 1 addition & 1 deletion core/base-service/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = class BaseService {
* this service.
*
* The preferred way to specify an example is with `namedParams` which are
* substitued into the service's compiled route pattern. The rendered badge
* substituted into the service's compiled route pattern. The rendered badge
* is specified with `staticPreview`.
*
* For services which use a route `format`, the `pattern` can be specified as
Expand Down
67 changes: 2 additions & 65 deletions core/base-service/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ class DummyService extends BaseService {
staticPreview: this.render({ namedParamA: 'foo', queryParamA: 'bar' }),
keywords: ['hello'],
},
{
namedParams: { namedParamA: 'World' },
staticPreview: this.render({ namedParamA: 'foo', queryParamA: 'bar' }),
keywords: ['hello'],
},
{
pattern: ':world',
namedParams: { world: 'World' },
queryParams: { queryParamA: '!!!' },
staticPreview: this.render({ namedParamA: 'foo', queryParamA: 'bar' }),
keywords: ['hello'],
},
]
}

Expand Down Expand Up @@ -343,59 +331,8 @@ describe('BaseService', function() {
queryParams: [],
},
})

const [first, second, third] = examples
expect(first).to.deep.equal({
title: 'DummyService',
example: {
pattern: '/foo/:world',
namedParams: { world: 'World' },
queryParams: {},
},
preview: {
label: 'cat',
message: 'Hello namedParamA: foo with queryParamA: bar',
color: 'lightgrey',
namedLogo: undefined,
style: undefined,
},
keywords: ['hello'],
documentation: undefined,
})
expect(second).to.deep.equal({
title: 'DummyService',
example: {
pattern: '/foo/:namedParamA',
namedParams: { namedParamA: 'World' },
queryParams: {},
},
preview: {
label: 'cat',
message: 'Hello namedParamA: foo with queryParamA: bar',
color: 'lightgrey',
namedLogo: undefined,
style: undefined,
},
keywords: ['hello'],
documentation: undefined,
})
expect(third).to.deep.equal({
title: 'DummyService',
example: {
pattern: '/foo/:world',
namedParams: { world: 'World' },
queryParams: { queryParamA: '!!!' },
},
preview: {
color: 'lightgrey',
label: 'cat',
message: 'Hello namedParamA: foo with queryParamA: bar',
namedLogo: undefined,
style: undefined,
},
keywords: ['hello'],
documentation: undefined,
})
// The in-depth tests for examples reside in transform-example.spec.js
expect(examples).to.have.lengthOf(1)
})
})

Expand Down
23 changes: 20 additions & 3 deletions core/base-service/coalesce-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,36 @@ module.exports = function coalesceBadge(
defaultBadgeData,
{ category, _cacheLength: defaultCacheSeconds } = {}
) {
// The "overrideX" naming is based on services that provide badge
// parameters themselves, which can be overridden by a query string
// parameter. (For a couple services, the dynamic badge and the
// query-string-based static badge, the service never sets a value
// so the query string overrides are the _only_ way to configure
// these badge parameters.
const {
style: overrideStyle,
label: overrideLabel,
logoColor: overrideLogoColor,
link: overrideLink,
colorB: legacyOverrideColor,
colorA: legacyOverrideLabelColor,
} = overrides
// Scoutcamp converts numeric query params to numbers. Convert them back.
let {
colorB: overrideColor,
colorA: overrideLabelColor,
logoWidth: overrideLogoWidth,
logoPosition: overrideLogoPosition,
color: overrideColor,
labelColor: overrideLabelColor,
} = overrides

// Only use the legacy properties of the new ones are not provided
if (typeof overrideColor === 'undefined') {
overrideColor = legacyOverrideColor
}
if (typeof overrideLabelColor === 'undefined') {
overrideLabelColor = legacyOverrideLabelColor
}

// Scoutcamp converts numeric query params to numbers. Convert them back.
if (typeof overrideColor === 'number') {
overrideColor = `${overrideColor}`
}
Expand Down
32 changes: 29 additions & 3 deletions core/base-service/coalesce-badge.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ describe('coalesceBadge', function() {

it('overrides the color', function() {
expect(
coalesceBadge({ colorB: '10ADED' }, { color: 'red' }, {}).color
coalesceBadge({ color: '10ADED' }, { color: 'red' }, {}).color
).to.equal('10ADED')
// also expected for legacy name
expect(
coalesceBadge({ colorB: 'B0ADED' }, { color: 'red' }, {}).color
).to.equal('B0ADED')
})

context('In case of an error', function() {
it('does not override the color', function() {
expect(
coalesceBadge(
{ colorB: '10ADED' },
{ color: '10ADED' },
{ isError: true, color: 'lightgray' },
{}
).color
).to.equal('lightgray')
// also expected for legacy name
expect(
coalesceBadge(
{ colorB: 'B0ADED' },
{ isError: true, color: 'lightgray' },
{}
).color
Expand All @@ -92,11 +104,25 @@ describe('coalesceBadge', function() {

it('overrides the label color', function() {
expect(
coalesceBadge({ colorA: '42f483' }, { color: 'green' }, {}).labelColor
coalesceBadge({ labelColor: '42f483' }, { color: 'green' }, {})
.labelColor
).to.equal('42f483')
// also expected for legacy name
expect(
coalesceBadge({ colorA: 'B2f483' }, { color: 'green' }, {}).labelColor
).to.equal('B2f483')
})

it('converts a query-string numeric color to a string', function() {
expect(
coalesceBadge(
// Scoutcamp converts numeric query params to numbers.
{ color: 123 },
{ color: 'green' },
{}
).color
).to.equal('123')
// also expected for legacy name
expect(
coalesceBadge(
// Scoutcamp converts numeric query params to numbers.
Expand Down
21 changes: 20 additions & 1 deletion core/base-service/deprecated-service.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
'use strict'

const Joi = require('joi')
const BaseService = require('./base')
const { Deprecated } = require('./errors')

// Only `url` is required.
function deprecatedService({ route, label, category, examples = [], message }) {
function deprecatedService({
route,
label,
category,
examples = [],
message,
dateAdded,
}) {
return class DeprecatedService extends BaseService {
static get category() {
return category
Expand All @@ -18,6 +26,17 @@ function deprecatedService({ route, label, category, examples = [], message }) {
return true
}

static validateDefinition() {
super.validateDefinition()
Joi.assert(
{ dateAdded },
Joi.object({
dateAdded: Joi.date().required(),
}),
`Deprecated service for ${route.base}`
)
}

static get defaultBadgeData() {
return { label }
}
Expand Down
2 changes: 2 additions & 0 deletions core/base-service/legacy-request-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const globalQueryParams = new Set([
'link',
'colorA',
'colorB',
'color',
'labelColor',
])

function flattenQueryParams(queryParams) {
Expand Down
6 changes: 3 additions & 3 deletions core/base-service/legacy-request-handler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,17 @@ describe('The request handler', function() {
beforeEach(function() {
register({ cacheHeaderConfig: standardCacheHeaders })
})
const expectedCacheKey = '/testing/123.json?colorB=123&label=foo'
const expectedCacheKey = '/testing/123.json?color=123&label=foo'
it('should match expected and use canonical order - 1', async function() {
const res = await fetch(
`${baseUrl}/testing/123.json?colorB=123&label=foo`
`${baseUrl}/testing/123.json?color=123&label=foo`
)
expect(res.ok).to.be.true
expect(_requestCache.cache).to.have.keys(expectedCacheKey)
})
it('should match expected and use canonical order - 2', async function() {
const res = await fetch(
`${baseUrl}/testing/123.json?label=foo&colorB=123`
`${baseUrl}/testing/123.json?label=foo&color=123`
)
expect(res.ok).to.be.true
expect(_requestCache.cache).to.have.keys(expectedCacheKey)
Expand Down
Loading

0 comments on commit 3859150

Please sign in to comment.