Skip to content

Commit 9aa9b81

Browse files
Merge branch 'master' into gh-actions-api
2 parents 30c566e + 5c33c81 commit 9aa9b81

File tree

238 files changed

+11679
-4802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+11679
-4802
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ services_steps: &services_steps
104104
environment:
105105
mocha_reporter: mocha-junit-reporter
106106
MOCHA_FILE: junit/services/results.xml
107-
command: npm run test:services:pr:run
107+
command: RETRY_COUNT=3 npm run test:services:pr:run
108108

109109
- store_test_results:
110110
path: junit

.eslintrc.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ extends:
44
- plugin:@typescript-eslint/recommended
55
- prettier/@typescript-eslint
66
- prettier/standard
7+
- prettier/react
8+
- eslint:recommended
79

810
parserOptions:
911
# Override eslint-config-standard, which incorrectly sets this to "module",
@@ -34,6 +36,7 @@ overrides:
3436
- '!frontend/**/*.js'
3537
env:
3638
node: true
39+
es6: true
3740
rules:
3841
no-console: 'off'
3942
'@typescript-eslint/no-var-requires': off
@@ -94,6 +97,8 @@ overrides:
9497
- files:
9598
- '**/*.spec.@(js|ts|tsx)'
9699
- '**/*.integration.js'
100+
- '**/test-helpers.js'
101+
- 'core/service-test-runner/**/*.js'
97102
env:
98103
mocha: true
99104
rules:
@@ -113,7 +118,7 @@ rules:
113118
'@typescript-eslint/no-var-requires': error
114119

115120
# These should be disabled by eslint-config-prettier, but are not.
116-
spaced-comment: 'off'
121+
no-extra-semi: 'off'
117122

118123
# Shields additions.
119124
no-var: 'error'
@@ -160,7 +165,6 @@ rules:
160165
'@typescript-eslint/camelcase': off
161166

162167
react/jsx-sort-props: 'error'
163-
react/prop-types: 'off'
164168
react-hooks/rules-of-hooks: 'error'
165169
react-hooks/exhaustive-deps: 'error'
166170
jsx-quotes: ['error', 'prefer-double']

.gitpod.yml

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
ports:
22
- port: 8080
3+
onOpen: open-preview
34
tasks:
45
- init: npm ci && npm run build
56
command: node server 8080 0.0.0.0
7+
github:
8+
prebuilds:
9+
# enable for the master/default branch (defaults to true)
10+
master: true
11+
# enable for all branches in this repo (defaults to false)
12+
branches: false
13+
# enable for pull requests coming from this repo (defaults to true)
14+
pullRequests: true
15+
# enable for pull requests coming from forks (defaults to false)
16+
pullRequestsFromForks: true
17+
# add a check to pull requests (defaults to true)
18+
addCheck: true
19+
# add a "Review in Gitpod" button as a comment to pull requests (defaults to false)
20+
addComment: false
21+
# add a "Review in Gitpod" button to the pull request's description (defaults to false)
22+
addBadge: false
23+
# add a label once the prebuild is ready to pull requests (defaults to false)
24+
addLabel: false
25+
vscode:
26+
extensions:
27+
- [email protected]:EbyqFvwe32qQBptkOgfQpQ==

.nycrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
"**/test-helpers.js",
1010
"**/*-test-helpers.js",
1111
"**/*-fixtures.js",
12+
"**/mocha-*.js",
1213
"dangerfile.js",
1314
"gatsby-*.js",
1415
"core/service-test-runner",
16+
"core/got-test-client.js",
1517
"services/**/*.tester.js",
1618
"services/test-validators.js",
1719
"services/tester.js",

CONTRIBUTING.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ maybe you'd like to open a pull request to address one of them:
2424

2525
You can help by improving the project's usage and developer instructions.
2626

27+
Tutorials are in [/doc](https://github.com/badges/shields/tree/master/doc):
28+
2729
- When you read the documentation, you can fix mistakes and add your own thoughts.
2830
- When your pull request follows the documentation but the practice changed,
2931
consider pointing this out and change the documentation for the next person.
3032

33+
API documentation is at [contributing.shields.io](https://contributing.shields.io/):
34+
35+
- This documentation is generated by annotating the code with
36+
[JSDoc](https://jsdoc.app/about-getting-started.html) comments.
37+
[Example](https://github.com/badges/shields/blob/b3be4d94d5ef570b8daccfd088c343a958988843/core/base-service/base-json.js#L26-L41)
38+
- Adding a JSDoc comment to some existing code is a great first contribution
39+
and a good way to familiarize yourself with the codebase
40+
3141
### Helping others
3242

3343
You can help with code review, which reduces bugs, and over time has a
@@ -95,12 +105,11 @@ There are three places to get help:
95105
## Badge URLs
96106

97107
- The format of new badges should be of the form
98-
`/SERVICE/NOUN/PARAMETERS/QUALIFIERS.format`. For instance,
99-
`/gitter/room/nwjs/nw.js.svg`. The vendor is gitter, the
100-
badge is for rooms, the parameter is nwjs/nw.js, and the format is svg.
101-
- For services which require a hostname, the badge should be of the form
102-
`/SERVICE/SCHEME/HOST/NOUN/PARAMETERS/QUALIFIERS.format`. For instance,
103-
`/discourse/https/discourse.example.com/topics.svg`.
108+
`/SERVICE/NOUN/PARAMETERS/QUALIFIERS`. For instance,
109+
`/gitter/room/nwjs/nw.js`. The vendor is gitter, the
110+
badge is for rooms, and the parameter is nwjs/nw.js.
111+
- Services which require a url/hostname parameter should use a query parameter to accept that value. For instance,
112+
`/discourse/topics?server=https://meta.discourse.org`.
104113

105114
## Coding guidelines
106115

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ It also works with full URLs like
114114
Use `npm run debug:server` to start server in debug mode.
115115
[This recipe][nodemon debug] shows how to debug Node.js application in [VS Code][].
116116

117-
Shields has experimental support for [Gitpod Beta][gitpod], a pre-configured development
117+
Shields has experimental support for [Gitpod][gitpod], a pre-configured development
118118
environment that runs in your browser. To use Gitpod, click the button below and
119119
sign in with GitHub. Gitpod also offers a browser add-on, though it is not required.
120120
Please report any Gitpod bugs, questions, or suggestions in issue

app.json

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
"GH_TOKEN": {
2424
"description": "Configure the token to be used for the GitHub services.",
2525
"required": false
26+
},
27+
"TWITCH_CLIENT_ID": {
28+
"description": "Configure the client id to be used for the Twitch service.",
29+
"required": false
30+
},
31+
"TWITCH_CLIENT_SECRET": {
32+
"description": "Configure the client secret to be used for the Twitch service.",
33+
"required": false
2634
}
2735
},
2836
"formation": {

config/custom-environment-variables.yml

+2
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@ private:
6363
sl_insight_userUuid: 'SL_INSIGHT_USER_UUID'
6464
sl_insight_apiToken: 'SL_INSIGHT_API_TOKEN'
6565
sonarqube_token: 'SONARQUBE_TOKEN'
66+
twitch_client_id: 'TWITCH_CLIENT_ID'
67+
twitch_client_secret: 'TWITCH_CLIENT_SECRET'
6668
wheelmap_token: 'WHEELMAP_TOKEN'

config/local-shields-io-production.template.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ private:
77
shields_secret: ...
88
sl_insight_userUuid: ...
99
sl_insight_apiToken: ...
10+
twitch_client_id: ...
11+
twitch_client_secret: ...
1012
wheelmap_token: ...

config/local.template.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ private:
55
# you can also set these values through environment variables, which may be
66
# preferable for self hosting.
77
gh_token: '...'
8+
twitch_client_id: '...'
9+
twitch_client_secret: '...'
810
wheelmap_token: '...'

core/base-service/auth-helper.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
'use strict'
22

33
class AuthHelper {
4-
constructor({ userKey, passKey, isRequired = false }, privateConfig) {
4+
constructor(
5+
{
6+
userKey,
7+
passKey,
8+
isRequired = false,
9+
defaultToEmptyStringForUser = false,
10+
},
11+
privateConfig
12+
) {
513
if (!userKey && !passKey) {
614
throw Error('Expected userKey or passKey to be set')
715
}
816

917
this._userKey = userKey
1018
this._passKey = passKey
11-
this.user = userKey ? privateConfig[userKey] : undefined
19+
if (userKey) {
20+
this.user = privateConfig[userKey]
21+
} else {
22+
this.user = defaultToEmptyStringForUser ? '' : undefined
23+
}
1224
this.pass = passKey ? privateConfig[passKey] : undefined
1325
this.isRequired = isRequired
1426
}

core/base-service/auth-helper.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ describe('AuthHelper', function() {
9191
given({ userKey: 'myci_user', passKey: 'myci_pass' }, {}).expect(
9292
undefined
9393
)
94+
given(
95+
{ passKey: 'myci_pass', defaultToEmptyStringForUser: true },
96+
{ myci_pass: 'abc123' }
97+
).expect({
98+
user: '',
99+
pass: 'abc123',
100+
})
94101
})
95102
})
96103
})

core/base-service/base-non-memory-caching.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const makeBadge = require('../../gh-badges/lib/make-badge')
44
const BaseService = require('./base')
5+
const { MetricHelper } = require('./metric-helper')
56
const { setCacheHeaders } = require('./cache-headers')
67
const { makeSend } = require('./legacy-result-sender')
78
const coalesceBadge = require('./coalesce-badge')
@@ -24,16 +25,19 @@ const { prepareRoute, namedParamsForMatch } = require('./route')
2425
// configured by the service, the user's request, and the server's default
2526
// cache length.
2627
module.exports = class NonMemoryCachingBaseService extends BaseService {
27-
static register({ camp, requestCounter }, serviceConfig) {
28+
static register({ camp, metricInstance }, serviceConfig) {
2829
const { cacheHeaders: cacheHeaderConfig } = serviceConfig
2930
const { _cacheLength: serviceDefaultCacheLengthSeconds } = this
3031
const { regex, captureNames } = prepareRoute(this.route)
3132

32-
const serviceRequestCounter = this._createServiceRequestCounter({
33-
requestCounter,
33+
const metricHelper = MetricHelper.create({
34+
metricInstance,
35+
ServiceClass: this,
3436
})
3537

3638
camp.route(regex, async (queryParams, match, end, ask) => {
39+
const metricHandle = metricHelper.startRequest()
40+
3741
const namedParams = namedParamsForMatch(captureNames, match, this)
3842
const serviceData = await this.invoke(
3943
{},
@@ -64,7 +68,7 @@ module.exports = class NonMemoryCachingBaseService extends BaseService {
6468

6569
makeSend(format, ask.res, end)(svg)
6670

67-
serviceRequestCounter.inc()
71+
metricHandle.noteResponseSent()
6872
})
6973
}
7074
}

core/base-service/base-static.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ const {
77
setCacheHeadersForStaticResource,
88
} = require('./cache-headers')
99
const { makeSend } = require('./legacy-result-sender')
10+
const { MetricHelper } = require('./metric-helper')
1011
const coalesceBadge = require('./coalesce-badge')
1112
const { prepareRoute, namedParamsForMatch } = require('./route')
1213

1314
module.exports = class BaseStaticService extends BaseService {
14-
static register({ camp, requestCounter }, serviceConfig) {
15+
static register({ camp, metricInstance }, serviceConfig) {
1516
const {
1617
profiling: { makeBadge: shouldProfileMakeBadge },
1718
} = serviceConfig
1819
const { regex, captureNames } = prepareRoute(this.route)
1920

20-
const serviceRequestCounter = this._createServiceRequestCounter({
21-
requestCounter,
21+
const metricHelper = MetricHelper.create({
22+
metricInstance,
23+
ServiceClass: this,
2224
})
2325

2426
camp.route(regex, async (queryParams, match, end, ask) => {
@@ -29,6 +31,8 @@ module.exports = class BaseStaticService extends BaseService {
2931
return
3032
}
3133

34+
const metricHandle = metricHelper.startRequest()
35+
3236
const namedParams = namedParamsForMatch(captureNames, match, this)
3337
const serviceData = await this.invoke(
3438
{},
@@ -60,7 +64,7 @@ module.exports = class BaseStaticService extends BaseService {
6064

6165
makeSend(format, ask.res, end)(svg)
6266

63-
serviceRequestCounter.inc()
67+
metricHandle.noteResponseSent()
6468
})
6569
}
6670
}

0 commit comments

Comments
 (0)