Commit Graph

246 Commits

Author SHA1 Message Date
chris48s
e294dc4edc refactor [circleci] integration (#1927)
* refactor [circleci] integration
2018-08-28 15:49:43 +01:00
Paul Melnikow
bedba47d77 Move legacy services from server.js into services/ (#1958)
This builds on the work of #1931 by moving the legacy services into `services/`.
2018-08-27 13:29:54 -04:00
Paul Melnikow
302c8606ff Rewrite [pypi]; affects [npm] (#1922) 2018-08-27 07:46:06 -04:00
Pyves
f377443585 Fixed Chrome Web Store examples (#1976) 2018-08-26 09:21:17 +01:00
tooomm
53cf4c1fe9 Remove gratipay from frontend (#1967) 2018-08-23 22:21:53 +01:00
chris48s
ae190c5f07 generate static examples without api call [apm appveyor cdnjs clojars gem npm uptimerobot] (#1740)
* allow service classes to define a static example
* define static example for some services
  (apm, appveyor, cdnjs, clojars, gem, librariesio, npm, uptimerobot)
* add/update tests


This allows us to show an example without making an API call to a live service for better performance.

We can now specify 3 fields in the example definition:

* urlPattern for the version with placeholders e.g: /npm/dw/:package.svg
* ExampleUrl/Uri for the concrete example e.g: /npm/dw/localeval.svg
* PreviewUrl/Uri for the static (or live) image we will actually show
2018-08-23 20:22:24 +01:00
Paul Melnikow
452affba15 Sort some more badges (#1948)
- Move the Docker Pulls badge from **Other** to **Downloads**.
- Create **Platform & Version Support** for the following:
    - django version support
    - python version support
    - node version support
    - pypi - wheel (waiting to avoid conflict with #1922)
    - pipi - format (waiting to avoid conflict with #1922)
    - pipi - implementation (waiting to avoid conflict with #1922)
    - hhvm
    - cocoapods platform
    - conda
    - php version badges
2018-08-22 15:05:11 -04:00
Paul Melnikow
942466aa92 Allow migrating legacy services to services/ (#1931) 2018-08-21 23:38:12 -04:00
Pyves
82bc90cec1 Deprecated VersionEye (#1953) 2018-08-20 20:04:11 +01:00
Paul Melnikow
656326d693 Rewrite [appveyor] tests badge (#1940) 2018-08-20 14:49:59 -04:00
Paul Melnikow
77b54c8c9a Sort some badges (#1945)
This implements proposals 1, 2, and 4 from #1905:

* Move gem rank from ratings to downloads; tweak title

* Move docker build from other to build

* Move bundlephobia, github file, github repo, imagelayers, and microbadger size + layers badges into new category

* Fill in a couple missing titles
2018-08-19 17:55:20 -04:00
Paul Melnikow
a16d436602 Optionally persist [Github] tokens in Redis (#1939)
This is a fairly simple addition of a Redis-backed TokenPersistence. When GithubConstellation is initialized, it will create a FsTokenPersistence or a RedisTokenPersistence based on configuration. Have added tests of the Redis backend as an integration test, and ensured the server starts up correctly when a `REDIS_URL` is configured.

Ref: #1848
2018-08-19 10:27:23 -04:00
Paul Melnikow
365f2cff5f Run tests by prefix e.g. [librariesio] (#1933)
Close #1923
2018-08-19 00:40:02 -04:00
Paul Melnikow
b10a6a4aa7 Refactor [github] token persistence, again (#1906)
Instead of saving tokens on a timer, save them when they change. Use EventEmitter to keep the components loosely coupled.

This is easier to reason about, much easier to test, and better supports adapting to backends which support atomic operations.

This replaces json-autosave, which was a bit difficult to read and also hard to test, with fsos, the lower-level utility it’s built on.

Ref: #1848
2018-08-18 23:54:53 -04:00
Pyves
886cde72d5 Rewrite [Wercker] service (#1920) 2018-08-16 22:03:15 +01:00
Pyves
b0070ff861 [GitHub] Error message customisation for all status codes (#1888) 2018-08-14 18:57:24 +01:00
Paul Melnikow
0c703c11b5 Rewrite [uptimerobot] (#1891) 2018-08-12 21:47:30 -07:00
Paul Melnikow
66d444aa40 Clean up our callback style and enforce no exclusive tests and remove an exclusive test (#1900)
We use arrow functions in most places; this enforces it.

Passing arrow functions to Mocha is discouraged: https://mochajs.org/#arrow-functions

This was a mix of autofixes and hand adjustments.
2018-08-12 20:45:43 -04:00
Paul Melnikow
2c646ae6ca Create Monitoring category (#1903) 2018-08-12 09:12:47 -04:00
Paul Melnikow
9007658fd0 Refactor and test [github] token persistence (#1863)
Ref #1848 #1205
2018-08-11 20:13:40 -04:00
Paul Melnikow
39d393028d Fix and test the github admin route (#1886)
Fix regressions in the github admin and token acceptor endpoints, introduced in #1813.
2018-08-11 19:48:43 -04:00
Paul Melnikow
cd6c38a616 Add InvalidParameter runtime error and return inaccessible for 5xx errors (#1890)
* InvalidParameter: New error type
* Return inaccessible for 5xx errors from services
* Add test for Inaccessible on 5xx
* Add tests for named error types
2018-08-11 21:05:56 +01:00
Paul Melnikow
0db88d33e0 Add debug logging to BaseService and BaseJsonService (#1867)
Invoke this using `npm run test:services:trace`.
2018-08-10 15:22:13 -04:00
Paul Melnikow
8af48c0a21 Minor tweaks in [github] auth code (#1862)
* Move / rework is-valid-token

* TokenPool: Add allValidTokenIds method

* Minor cleanup in server.js
2018-08-09 07:22:54 -04:00
Paul Melnikow
c11d97a192 Refactor [github] initialization (#1861)
This creates a new convenience class which consolidates all the Github initialization. It supports dependency injection and facilitates refactoring the persistence along the lines of #1205.

Also ref #1848
2018-08-09 07:20:57 -04:00
Paul Melnikow
7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00
Paul Melnikow
e3b100504d Add Joi-based request validation to BaseJsonService and rewrite [NPM] and [node] badges (#1743)
When JSON responses come back, they are sometimes not in the format expected by the API. As a result we have a lot of defensive coding (expressions like `(data || {}).someProperty`) to avoid exceptions being thrown in badge processing. Often we rely on the `try` blocks that wrap so much of the badge-processing code, which catch all JavaScript exceptions and return some error result, usually **invalid**. The problem with this is that these `try` blocks catch all sorts of programmer errors too, so when we see **invalid** we don't know whether the API returned something unexpected, or we've made a mistake. We also spend a lot of time writing defensive tests around malformed responses, and creating and maintaining the defensive coding.

A better solution is to validate the API responses using declarative contracts. Here the programmer says exactly what they expect from the API. That way, if the response isn't what we expect we can just say it's an **invalid json response**. And if our code then throws an exception, well that's our mistake; when we catch that we can call it a **shields internal error**. It's also less code and less error-prone. Over time we may be confident enough in the contracts that we won't need so many tests of malformed responses. The contract doesn't need to describe the entire response, only the part that's needed. Unknown keys can simply be dropped, preventing unvalidated parts of the response from creeping into the code. Checking what's in our response before calling values on it also makes our code more secure.

I used Joi here, since we're already using it for testing. There may be another contracts library that's a better fit, though I think we could look at that later.

Those changes are in base.js.

The rest is a rewrite of the remaining NPM badges, including the extraction of an NpmBase class. Inspired by @chris48s's work in #1740, this class splits the service concerns into fetching, validation, transformation, and rendering. This is treated as a design pattern. See the PR discussion for more. There are two URL patterns, one which allows specifying a tag (used by e.g. the version badge `https://img.shields.io/npm/v/npm/next.svg`), and the other which does not accept a tag (e.g. the license badge `https://img.shields.io/npm/l/express.svg`). Subclasses like NpmLicense and NpmTypeDefinitions can specify the URL fragment, examples, the validation schema for the chunk of the package data they use, and a render function. The NpmVersion subclass uses a different endpoint, so it overrides the `handle` implementation from NpmBase.

The remaining services using BaseJsonService are shimmed, so they will keep working after the changes.
2018-08-08 17:08:16 -04:00
Pyves
e1affea266 [GitHub] Fix undefined badges (#1816) 2018-08-08 20:57:57 +01:00
Paul Melnikow
56fcb2e5ba GithubApiProvider: injectible interface for code that calls github (#1812) 2018-08-07 16:46:12 -04:00
Pyves
da403b7e3a Increased default BADGE_MAX_AGE_SECONDS (#1846)
* Added note about default on website
2018-08-06 22:36:10 -04:00
Paul Melnikow
2ff71dab6a Start cleaning up github auth routes (#1813)
- Move github token debug route to separate module
- Use crypto.timingSafeEqual
- Rename getTokenDebugInfo -> serializeDebugInfo
2018-08-01 21:58:11 -04:00
Danial
317e19ea2a Add support for simple-icons, colored icons with ?logoColor (#1810)
* add simple-icons

* handle undefined

* support logoColor param

* our icon > simple-icon

* dont crash 

* return false → undefined

* update test

* add test

* support logoColor on our logos

* cache as base64, pre-load-simple-icons, logo-helper

* add ?logoColor information

* and simple-icons reference, link to github master branch for our logos

* update simple-icons

update to 1.7.1

* Revert "and simple-icons reference, link to github master branch for our logos"

This reverts commit 5e99d5f8db.

* add link to simple-icons

* Add snapshot test

* support dash in place of space for logo name
2018-08-02 09:07:23 +12:00
Danial
c974b1b931 throw if given invalid version, refactor [apm] (#1785)
* throw if given invalid version

* refactor service

* add test

* fixup

* move service

* split up module

* update test

* add keywords

* remove from all-badge-examples

* update category [license → miscellaneous]

* Error → InvalidResponse

* minor style fix

* InvalidResponse

* reduce some code duplication

* fixup

* update category

* invalid → unparseable json response
2018-07-30 14:46:47 +12:00
Danial
409bcd1870 Add logo style badges - popout, popout-square (#1478)
* add logo style badges

add new styles:
- flat-logo
- flat-square-logo

* rename flat-logo -> popout

flat-logo -> popout
flat-square-logo -> popout-square

* default centered, add logoAlign param

* fix test

* logoAlign -> logoPosition

* reverse logoPosition direction

* fixup
2018-07-28 16:35:24 +12:00
Danial
329db7ddab loosely detect semver versions (#1628)
* loosely detect semver versions

* semver loose validity

* add test

* semver compare versions when null

* add comments for loose

* remove console.log, only match semver scheme

* looser version restrictions

* re-sort version tests

comments refered to incorrect test

* add support for pre-release tags

#1682

* support uppercase, lowercase mixed

* make pre-release opt in

* change pre param to object

* add notes
2018-07-27 08:27:48 +12:00
Danial
b216bcc17e Hide left hand of badge if no label (#1585)
* hide left side if no text

* fix whitespace at start of template

* for-the-badge done

* center text

* add logo support

* update snapshot test

* make first - in static badge optional

* add no label support to non static badges

* Add test for label

* update to not allow use of false/0/null

* fixup
2018-07-27 08:27:32 +12:00
chris48s
d572abff4f re-organise badge examples (#1800)
Re-organise badge examples into categories:

- Build
- Chat
- Dependencies
- Downloads
- Funding
- Issue Tracking
- License
- Rating
- Social
- Version
- Other
2018-07-23 19:36:24 -05:00
Paul Melnikow
6e09a93cf0 Provide a descriptive message when json can’t be parsed (#1796)
* Test handling of invalid JSON on BaseJsonService
* Remove invalidJSON tests from new-style services
2018-07-23 19:35:42 -05:00
Paul Melnikow
5a62ed59fe List the named logos in the frontend (#1794)
Fix #1787
2018-07-23 15:19:55 -05:00
Paul Melnikow
f9545af81d Fix edge case for service detection in PR titles [cran] [crates] (#1790)
Service detection didn’t work correctly for PR titles with multiple bracketed entries.

https://circleci.com/gh/badges/shields/6797
2018-07-21 09:53:55 -07:00
chris48s
b9db222c8a send longer cache headers by default (#1725)
* tell browsers and downstream caches to cache for
  `env.BADGE_MAX_AGE_SECONDS`, default 0 for dev

* set Cache-Control: no-cache, no-store, must-revalidate if maxAge=0

* add servertime badge to help with cache header debugging

* if service category is 'debug', exclude from examples

* ignore maxAge GET param if less than `env.BADGE_MAX_AGE_SECONDS`
2018-07-20 20:24:02 +01:00
greenkeeper[bot]
6462cc49d5 Update eslint-plugin-node to the latest version 🚀 (#1786)
* chore(package): update eslint-plugin-node to version 7.0.0

* Update lockfile

* Update call to deprecated API
2018-07-18 18:36:54 -07:00
chris48s
7de10783fa Deprecate [magnumci bithound] (#1770)
* deprecate Magnum CI badge

* deprecate BitHound badges
2018-07-11 23:30:52 -04:00
chris48s
0ec35ec9f8 add tests for composer version compare function (#1771) 2018-07-11 23:14:26 -04:00
Paul Melnikow
b3ec3e7a96 Generalized rotating token pool (#1736)
This was designed as part of a rewrite of the Github auth code in #1205 which is stalled because I don't want to deploy it without access to server logs. The need for token rotation came up recently in #541, so I picked up this code, removed the github-specific bits, and pulled it in. Ordinarily I wouldn't merge helper code without a use, though sadly it seems like the best way to move forward this rewrite.
2018-07-11 23:08:56 -04:00
Danial
d8cf836264 Add support for rgb, rgba, hsl, hsla, css named colors (#1635)
* add support for rgb, rgb, css named colors

* add support for hsl, hsla & add color-validate

* update makeBadge test, better coverage

* re-add comment

* add comment for supported colors

* dynamic badge gen, remove 'hex'

* add support for 1.0 opacity & fix 101-109

* fix colorscheme tests

* remove extra tests

* add test for negative values

* add test for uppercase & mixed case colors

* fix mixed case/uppercase test

* allow whitespace around color

* update test error messages

* add comments

* add more uppercase test

* update error message

* default to grey/red if invalid color chosen

default colorscheme:
colorA: grey
colorB: red

* Revert "default to grey/red if invalid color chosen"

This reverts commit 10db0c6d74.
Reverted as this affects the CLI version/when no color specified.

* validColor -> isCSSColor

* assignColor function

* update tests to use sazerac
2018-07-12 10:26:17 +12:00
Stanley Ng
85dd5f0809 Add [Jenkins] Jacoco coverage badge ☘ (#1593)
* Add Jenkins Jacoco coverage badge

* [Jenkins] add service test for jacoco coverage

* Added Jenkins Coverage (Jacoco) in all-badge-examples page

* Defined variables using let/const instead of var

* Used template string for the uri

* Used checkErrorResponse helper function for the error check

* Used NaN method for not a number test

* Prefixed the original Jenkin coverage test with "cobertura:"

* Moved the happy test case at front

* Merge the business logic between jacoco and cobertura

* Fixed lint issue

* Trigger notification
2018-07-10 18:12:26 +12:00
Pyves
8ad3bc7e90 [scrutinizer] Fix #1739, add tests and refactor (#1759)
* Added tests for Scrutinizer service

* Refactored service and fixed NaN bug

* Updated example

* Improved badge regex
2018-07-08 10:32:13 +01:00
chris48s
b05d93c9c1 fix [waffle] labels badge (#1745)
fix [waffle] labels badge

- update URL and parsing code to use /columns endpoint
- add error handling for 'not found' case
- add missing test cases
- update home page example

Closes #1731
2018-07-05 19:06:06 +01:00
Grey Baker
ca58d84447 Add [dependabot] SemVer compatibility badge (#1734)
* Add [dependabot] SemVer compatibility badge

* Add dependabot logo

* Clean up and additional tests
2018-06-17 21:32:57 +02:00