Commit Graph

84 Commits

Author SHA1 Message Date
chris48s
d8831729cb Check request origin before sending credentials (#4729)
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
Co-authored-by: chris48s <chris48s@users.noreply.github.com>

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
Co-authored-by: chris48s <chris48s@users.noreply.github.com>
2020-03-04 20:42:27 +00:00
François Hodierne
0d8a2d5ca0 Update to eslint 6.8.0 [appveyor githubissuedetail packagist] (#4489)
* update to eslint 6.8.0 and related packages

* Fixes for no-prototype-builtins

* Updates for explicit-function-return-type

* Add ignores for no-explicit-any

* update to eslint 6.8.0 and related packages

* Fixes for no-prototype-builtins

* Updates for explicit-function-return-type

* Add ignores for no-explicit-any

* package: activate eslint-config-standard

* apply updated eslint configuration

* lint: apply eslint feedback after rebase

* Update lockfile

* Update lockfile

* Restore missing deps

* Update lockfile

* Re-add eslint-plugin-node

* Add eslint-plugin-standard and eslint-plugin-react-hooks

* Clean lint

Co-authored-by: Paul Melnikow <github@paulmelnikow.com>
2020-02-29 11:06:36 -06:00
Marcin Mielnicki
22a85bfbcd A response size metric of an upstream service for dynamic badges like [dynamicyaml], (but not [jetbrains]) (#4434)
* Response size metric for all services

* Unused code removed

* Test for service response size metric

* All buckes of the service_response_bytes in a comment

* Register parameter in PrometheusMetrics is optional

* service response size metric enabled for dynamic badges

* Better test name

* JSDoc removed

* One import from one file

* Gather metrics in the background

* Revert saving response time metrics in the background
2020-01-04 17:48:24 +01:00
Marcin Mielnicki
dfcb6defc8 Refactor JSONPath based services, run [DynamicJson DynamicYaml] (#4272)
* Subclass factory for JSON path services

* Common methods moved to JSON path class

* should throw error if _getData is not overridden

* Test JSON path factory using chai-as-promised

* Using chai-as-promised in more tests

* JSDoc for json-path

* Error message adopted to JSON and YAML

* Dynamic YAML badge handles YAML with a string

* 'fetch' naming covention

* Strict string validation in error message
2019-12-05 01:03:05 +01:00
dependabot-preview[bot]
6d5a23b889 Build(deps): bump path-to-regexp from 3.1.0 to 5.0.0 (#4330)
* Build(deps): bump path-to-regexp from 3.1.0 to 5.0.0

Bumps [path-to-regexp](https://github.com/pillarjs/path-to-regexp) from 3.1.0 to 5.0.0.
- [Release notes](https://github.com/pillarjs/path-to-regexp/releases)
- [Changelog](https://github.com/pillarjs/path-to-regexp/blob/master/History.md)
- [Commits](https://github.com/pillarjs/path-to-regexp/compare/v3.1.0...v5.0.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* chore: apply path-to-regexp v5.x changes
2019-11-16 16:27:58 -06:00
dependabot-preview[bot]
0f332413df Build(deps-dev): bump prettier from 1.18.2 to 1.19.1 (#4328)
* Build(deps-dev): bump prettier from 1.18.2 to 1.19.1

Bumps [prettier](https://github.com/prettier/prettier) from 1.18.2 to 1.19.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/1.18.2...1.19.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Build(deps-dev): bump prettier from 1.18.2 to 1.19.1

Bumps [prettier](https://github.com/prettier/prettier) from 1.18.2 to 1.19.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/1.18.2...1.19.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* chore: apply new prettier formatting

* chore: try prettier, again
2019-11-15 19:33:40 -06:00
Paul Melnikow
7e0976cd8c When serviceData fails validation, include the service class in the stack trace (#4266)
This should make it easier to debug #3784.
2019-10-28 10:33:47 -04:00
Paul Melnikow
dde66ca383 Fix tests in Node 12 (#4146)
c.f. https://github.com/badges/shields/pull/4145#issuecomment-538768061

This is super-strange. I am curious what this is about! (Though not quite curious enough to go digging.)

The test failure is reproducible in Node 12.11.0 though not e.g. 10.6.3.

Example failure on master: https://circleci.com/gh/badges/shields/74325
2019-10-06 16:12:22 -04:00
Pierre-Yves B
157a6180b2 Make search work with category names (#4103) 2019-10-02 20:03:59 +01:00
chris48s
c762d971b4 upgrade Joi and related packages (#4060)
* update dependencies

* (core) children --> keys

* (core) fix/update BaseService validate

* (core) update error messages in tests

* (core) only Joi.attempt if we've got a Joi schema

* (core) allow 'expected' to be a regex

* (services) pass 2 schema to .alternatives()

* (services) functions --> Joi schema

* (services) update expected error message

* (services) explicit check for color: undefined

* re-bump joi

* (services) wrap another regex

* (core/services) remove use of array arguments

* (core/services) when --> conditional

* (services) remove more array arguments

* fix spelling in var name

* DRY up sonar helper
2019-09-23 17:36:56 +01:00
Caleb Cartwright
d18d4218fc support basic auth with just pass token (#4063)
* feat: support basic auth with token

* refactor: change param name
2019-09-22 11:14:01 -05:00
Paul Melnikow
6560706d01 Finish Typescripterizing the frontend (#4026)
* Typescripterize RequestMarkupButton

* Typescripterize Customizer

* Typescripterize MarkupModalContent (+ tweaks)

* More TypeScript

* More TS

* Fix build

* Remove prop-types dependency

* More types

* Update frontend/components/badge-examples.tsx

* Update frontend/components/badge-examples.tsx

* RequestMarkupButton: Fix weird formatting on click
2019-09-16 14:53:07 +00:00
chris48s
a75b9b3c8c document exceptions (#3961) 2019-09-08 20:58:45 +00:00
Paul Melnikow
b7a29f20ef Add a response-time metric (#3948)
* Refactor existing metrics support into MetricHelper

This completes the refactor done at https://github.com/badges/shields/pull/3662#issuecomment-509011229 in anticipation of adding more metrics support, such as response size of an upstream service, or response time.

* Clean up

* Renames

* Add response time metrics

This adds around 30 new metrics to cover response times at a fairly granular level. We may be able to shrink the number of buckets with time, though I think using 30 metrics is probably okay given that I think may become our most important metric.

* Fix
2019-09-03 22:19:24 +00:00
chris48s
02e1baf690 improve docs for base service classes (#3850)
improve docs for base service classes
2019-08-14 21:54:46 +01:00
chris48s
75ee413178 Add BaseGraphqlService, support [github] V4 API (#3763)
* add base class for Graphql APIs
* add GithubAuthV4Service + updates to GH token pool
* update github forks to use GithubAuthV4Service
* rename GithubAuthService to GithubAuthV3Service
2019-07-29 21:42:03 +01:00
Paul Melnikow
3f891e4a1f Fix timeout logic (#3774)
Close #3773
2019-07-24 22:51:25 -05:00
Paul Melnikow
cfbd2c30df SVG by default (#3717)
Make cleaner badge URLs by omitting the `.svg` extension.

Closes #2674
2019-07-24 12:57:39 -05:00
Paul Melnikow
3964eb5cb0 Remove use of deprecated Domain API (#3762)
Use of this feature [has been discouraged for a long time](https://nodejs.org/api/domain.html).

Since most of our code is now bubbling through async, we aren't really getting these "vendor errors" anymore.

Errors that _do_ bubble up through the services have been reported to Sentry since #3706, though they seem to be missing a bunch of their stack traces. Sentry also seems to be combining unrelated internal errors. (https://github.com/badges/shields/issues/3709#issuecomment-514299441) Maybe this will help.
2019-07-23 16:43:09 -05:00
Paul Melnikow
28b8836595 Unify the ESLint config (#3743)
Adding TypeScript to the frontend and a `.d.ts` file to `core` (see #3742) has multiplied out the different combinations of lint rules. ESLint has support for file-pattern-based overrides, which we've used in some places, but we've also maintained a separate eslintrc for `frontend/`.

This merges the config together, with the strategy of putting all the rules at the top level except where they conflict, and applying settings to exactly the files where they should apply.

This introduces a few new errors in the server but they are true positives – hoisting and lowercase class names – things we don't really need to be doing).
2019-07-22 15:06:38 -05:00
Paul Melnikow
153732756c Log internal errors to Sentry (#3706)
Fix #3688
2019-07-12 19:40:46 -04:00
chris48s
38cdc0033f adopt JSDoc, eslint-plugin-jsdoc (#3645)
eslint-plugin-jsdoc:
- install eslint-plugin-jsdoc
- config file
- fix lint/style errors

JSDoc:
- add JSDoc as a dev dependency
- get everything rendering nicely with JSDoc
- config, build command + ignores
2019-07-11 20:14:47 +01:00
Paul Melnikow
ce0ddf93fc Inject secrets into the services (#3652)
This is a reworking of #3410 based on some feedback @calebcartwright left on that PR.

The goals of injecting the secrets are threefold:

1. Simplify testing
2. Be consistent with all of the other config (which is injected)
3. Encapsulate the sensitive auth-related code in one place so it can be studied and tested thoroughly

- Rather than add more code to BaseService to handle authorization logic, it delegates that to an AuthHelper class.
- When the server starts, it fetches the credentials from `config` and injects them into `BaseService.register()` which passes them to `invoke()`.
- In `invoke()` the service's auth configuration is checked (`static get auth()`, much like `static get route()`).
- If the auth config is present, an AuthHelper instance is created and attached to the new instance.
- Then within the service, the password, basic auth config, or bearer authentication can be accessed via e.g. `this.authHelper.basicAuth` and passed to `this._requestJson()` and friends.
- Everything is being done very explicitly, so it should be very clear where and how the configured secrets are being used.
- Testing different configurations of services can now be done by injecting the config into `invoke()` in `.spec` files instead of mocking global state in the service tests as was done before. See the new Jira spec files for a good example of this.

Ref #3393
2019-07-09 23:14:36 -04:00
Paul Melnikow
66c7f13e38 Drop gif + png, and redirect png to raster.shields.io (#3644)
1. Remove rasterization support from the server. This responsibility is delegated to a raster server which proxies the SVG badges and renders them.
2. When a raster server URL is configured, 301 redirect all .png badges to the identical URL on the raster server.
    `https://img.shields.io/npm/v/express.png?style=flat-square` ↪️`https://raster.shields.io/npm/v/express.png?style=flat-square`
3. For configured redirects, redirect to the canonical URL on the raster server.
    `https://img.shields.io/vso/build/totodem/8cf3ec0e-d0c2-4fcd-8206-ad204f254a96/2.png?style=flat-square`
    ↪️`https://img.shields.io/azure-devops/build/totodem/8cf3ec0e-d0c2-4fcd-8206-ad204f254a96/2.png?style=flat-square`
4. Redirect the "legacy badge old version" to the appropriate URL on the raster server.
5. When no raster server is configured (e.g. PRs), render an SVG containing **404 | raster badges not available** for all `.png` badges. (Note that the raster server can be self-hosted; however, this is deferred to a later PR.)
5. Drop support for jpg and gif which are very infrequently used (see #3112). Render an SVG containing **410 | jpg no longer available**.
7. ~~Remove raster dependencies.~~ Remove the raster cache (which is only used in the CLI, and therefore pointless).
8. Move the LRUCache code out of the npm package.
8. A wee bit of refactoring in `server.js`.

Ref #3112
Close #3631
2019-07-06 16:41:46 -04:00
Paul Melnikow
093d9cd368 Minor refactor: expose custom promisify function from legacy request handler (#3650)
Cherry-picked from #3410; should simplify reworking it.
2019-07-05 21:26:05 -04:00
chris48s
d78edaf5b5 add/improve some JSDoc comments on core API (#3595) 2019-06-25 22:42:01 +01:00
dependabot-preview[bot]
95b6e48bff Build(deps-dev): bump nock from 11.0.0-beta.14 to 11.0.0-beta.19 (#3552)
* Build(deps-dev): bump nock from 11.0.0-beta.14 to 11.0.0-beta.19

Bumps [nock](https://github.com/nock/nock) from 11.0.0-beta.14 to 11.0.0-beta.19.
- [Release notes](https://github.com/nock/nock/releases)
- [Changelog](https://github.com/nock/nock/blob/beta/CHANGELOG.md)
- [Commits](https://github.com/nock/nock/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Fix one test

* Update for breaking change in nock api

* Always use got without retries in tests
2019-06-21 10:45:34 -04:00
dependabot-preview[bot]
d732b937c9 Build(deps-dev): bump prettier from 1.17.1 to 1.18.2 (#3580)
* Build(deps-dev): bump prettier from 1.17.1 to 1.18.2

Bumps [prettier](https://github.com/prettier/prettier) from 1.17.1 to 1.18.2.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/1.17.1...1.18.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* chore: prettier
2019-06-17 19:15:44 -05:00
chris48s
8621fe42d7 Upgrade Joi (#3505)
* upgrade joi
* find & replace ALL THE THINGS
* update related deps
2019-06-02 21:59:55 +01:00
Paul Melnikow
786bac21ce Convert remaining uses of node-fetch to got (#3417) 2019-05-06 10:10:07 +01:00
Paul Melnikow
001ade3704 Move checkErrorResponse from lib/ to core/ [chrome] (#3408) 2019-05-02 18:07:18 -04:00
Paul Melnikow
a0da978886 Bury the loader fixtures with the code that uses them (#3407)
One less thing to have in the root of the project!
2019-05-02 12:36:00 -04:00
Paul Melnikow
ae2499bf53 Generate JSON badges without using a template [GithubSearch] (#3395)
Warm up for #2428.
2019-04-29 23:26:52 -04:00
Paul Melnikow
b2e21da34d Remove legacy helper makeBadgeData (#3392)
Close #3369
2019-04-29 19:44:25 -04:00
Paul Melnikow
a0492c5283 Remove unused callback-based error helpers (#3371) 2019-04-29 13:35:57 -04:00
Pierre-Yves B
2806eb8a00 Legacy services clean up (#3367)
* Deleted remaining legacy service bits

* Removed badge from README

* Removed no longer needed try/catch

* Deleted refactoring script

* Switched to const

* Reinstated doc

* Ran Prettier
2019-04-27 19:25:01 +01:00
Paul Melnikow
0088a9d0da Unify remaining service order and enforce (#3359)
Ref #3353
2019-04-24 16:53:33 -04:00
Paul Melnikow
1cdcaabd38 Unify order of properties and methods in services (#3353)
I find having these in a consistent order makes the services much faster to read.

This is the order I’ve generally been using:

1. Category
2. Route
3. Examples
4. Rendering
5. Other helpers (`fetch()`, `transform()`)
6. `handle()`
2019-04-23 21:36:04 -04:00
Paul Melnikow
91d6dd6643 Rewrite [codeclimate] coverage (#3316)
Attacking this in two pieces for ease of review. The legacy implementation for coverage is still there, though I disabled it via the route. That whole file will be removed in the next PR.

Ref #2863
2019-04-15 23:47:25 -04:00
Pierre-Yves B
25f8541e5b JSON format modernisation and _shields_test removal (#3272)
* Modernised JSON format and removed _shields_test style

* Added logoWidth and labelColor fields to JSON response

* Reinstated and updated comment

* Extended expectBadge to accept Joi schemas for all fields
2019-04-07 18:57:55 +01:00
Paul Melnikow
3733de6232 Rewrite GitHub commit status (#3186)
* WIP

* Parse the error response

* Clarify

* Restore one test

* Add a schema
2019-03-10 18:43:37 -05:00
Paul Melnikow
612831a2d8 Remove legacy analytics (#3179)
We're getting good results from #3093, so there's no reason to keep maintaining this code.

Ref #1848 #2068
2019-03-08 00:05:37 -05:00
Paul Melnikow
a6d02239f7 Document queryParams + rename example module (#3170)
This file does more than transform, and `examples` seems is a bit more consistent with e.g. `trace.js` and `route.js`.
2019-03-06 21:04:08 -06:00
Paul Melnikow
a12cbb76fc Prevent queryParams from reaching handle() when no schema is defined (#3171)
I believe I’ve added all the schemas to the new-style services in #3164, so this should be purely preventive.
2019-03-06 21:26:09 -05:00
Paul Melnikow
388b0eefbb Add query param validation to remaining new-style services [azuredevops appveyor npm] (#3164)
Remove now-obsolete code.

Close #2675
2019-03-06 18:13:36 -05:00
Paul Melnikow
4f411755da Add a stats category for static badges (#3168)
Right now they're showing up in "other," though I expect they make up
most of that category.

https://github.com/badges/shields/issues/966#issuecomment-469851361
2019-03-05 21:23:20 -06:00
Paul Melnikow
e159d90516 Reorganize a couple of the legacy helpers [npm node jenkinsplugin dynamic] (#3163) 2019-03-05 20:43:33 -06:00
Caleb Cartwright
726830f067 Add ability to transform query params in redirct service, run [Endpoint GitHubReleaseRedirect SensioLabs VSO] (#3125)
* feat(redirector): added transformQueryParams to redirector

* refactor: renamed to transformPath in redirector

* Rename targetUrl to targetPath

Co-Authored-By: calebcartwright <calebcartwright@users.noreply.github.com>

* feat(redirector): handle param conflicts
2019-03-04 18:11:37 -06:00
Paul Melnikow
56e71d7c76 Label all deprecated services as such (#3120)
* Label all deprecated services as such

This will change

service_requests_total{category="other",family="cocoapods",service="cocoapods_apps"} 76

to

service_requests_total{category="other",family="cocoapods",service="deprecated_cocoapods_apps"} 76

* Fix tests
2019-02-28 18:22:28 -06:00
Paul Melnikow
97358c1399 Rewrite [GitHubStars] (#3119)
* Refactor [GithubStars]

* Add test of link array
2019-02-28 18:18:32 -06:00