86 Commits

Author SHA1 Message Date
Paul Melnikow
e528c85ed4 Refactor [GithubContributors] and [NpmCollaborators] and change color (#2715)
See examples in https://github.com/badges/shields/pull/2705#issue-243107694
2019-01-09 16:29:57 -05:00
Paul Melnikow
d1c5378bf0 Integrate new path-to-regexp with trailing optionals (#2644)
Fix #2497

Ref pillarjs/path-to-regexp#176
2019-01-08 18:50:47 -05:00
Paul Melnikow
89113eee17 Migrate deprecated staticExample -> staticPreview (#2650) 2019-01-06 17:30:25 -05:00
Paul Melnikow
83044ce325 Update more exampleUrls; style tweaks (#2639) 2019-01-06 08:18:19 -05:00
Paul Melnikow
5e50b7bcc4 Fix [npm] badges when a dependency points to a URL (#2525)
Fix #2523
2018-12-13 14:07:33 -05:00
Paul Melnikow
a3a52524fc Add [npm] badges for collaborator count and dependency version (#2461)
This adds a badge for collaborator count. When evaluating a library, it can be useful to know that there's not a single-contributor bottleneck for publishing. Having more than one collaborator is a sign of library maturity.

It adds another badge for dependency version of published dependencies, which solves a similar problem as the node-version badge. I will find this useful for making sure dependencies are up to date in a library.
2018-12-12 15:02:37 -05:00
Paul Melnikow
88c8b0ee3e More example urls and static examples [apm waffle] (#2478) 2018-12-11 16:31:01 -05:00
Paul Melnikow
8a8311d931 Unify and minimize tester boilerplate (#2472)
I started using this one-line boilerplate a while back and it seems to tidy things up a bit.
2018-12-08 13:15:24 -05:00
Paul Melnikow
477d357286 Sort some badges; add an Activity category (#2448) 2018-12-05 14:17:37 -05:00
Paul Melnikow
809ecf73b9 Examples: Drop deprecated aliases query, urlPattern (#2443) 2018-12-03 16:30:12 -05:00
Paul Melnikow
43d99f96e6 Fix failing service tests for [bintray npmlicense github crates] (#2401)
Closes #2343 #2348 #2402

Ref: #2345 #1359
2018-11-28 18:54:04 -05:00
Paul Melnikow
3ad742e79a Example: Canonicalize urlPattern to pattern (#2341)
Close #2334 

To avoid merge conflicts, I've deferred removing the aliasing logic in `prepareExamples`. That whole function will be refactored momentarily, and there's also #2339 open.
2018-11-18 09:03:33 -05:00
Paul Melnikow
02ec19fd22 BaseService terminology: Rename url to route (#2278)
The term “url” is overloaded in services, to refer to the Shields route and also the API URL. Calling the Shields URL a “route” is on the whole more descriptive, and makes it clearer and more obvious which one of these we’re talking about. It’s a small thing, though seems like an improvement.

We have a few functions called `buildUrl`. I’ve renamed them to `buildRoute` when they refer to routes, and left them as `buildUrl` when they refer to API URLs.

I included a minor style tweak and some formatting cleanup in `TUTORIAL.md`.
2018-11-09 15:11:03 -05:00
dependabot[bot]
e240409033 Bump prettier from 1.14.3 to 1.15.1 (#2289)
* Bump prettier from 1.14.3 to 1.15.1

Bumps [prettier](https://github.com/prettier/prettier) from 1.14.3 to 1.15.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.14.3...1.15.1)

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

* Run prettier
2018-11-08 14:39:00 -05:00
Ted Janeczko
a6fe16c5d1 Add support for private [npm] packages (#2187) 2018-10-20 08:06:36 +01:00
chris48s
362db466bb update service tests tutorial (#2075)
* update service tests tutorial
* re-order and re-name tests for clarity
* update documentation examples
* extract boilerplate for testing colours
2018-10-01 20:53:04 +01:00
Paul Melnikow
454575c4cb Enforce no extensions in require (#1999)
This removes remaining `.js` extensions from `require()` expressions and automatically enforces this rule.
2018-09-01 11:14:01 -07:00
Paul Melnikow
302c8606ff Rewrite [pypi]; affects [npm] (#1922) 2018-08-27 07:46:06 -04: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
a0c43ed219 Reduce boilerplate for creating new testers [npm appveyor gem uptimerobot clojars] (#1934)
This is a bit of sugar that reduces the boilerplate for creating testers in what I expect will become the standard case: a service in `foo/foo-thing.service.js` with its tests in `foo/foo-thing.tester.js`.

This makes a small stylistic change, which is to name the service by its CamelCase class name rather than an invented snake-case ID. Whereas before the name was specified in `class FooThing extends Base[Json]Service` and a second time in the tester, it now only needs to be specified once.
2018-08-22 18:07:51 -04: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
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
edb7d82500 Change format of [npm] type definitions badge (#1897)
Based on feedback at chalk/chalk#286.
2018-08-19 09:27:23 -04:00
Paul Melnikow
9119c235a9 Prevent merging exclusive service tests (#1926)
* Remove an .only() left behind previously
2018-08-16 11:06:08 -07:00
Pyves
b0070ff861 [GitHub] Error message customisation for all status codes (#1888) 2018-08-14 18:57:24 +01:00
Paul Melnikow
0a7c833452 Fix an edge case in NpmBase (#1904)
I noticed this when I copied this code while I was working on #1895.
2018-08-12 19:13:31 -04:00
Paul Melnikow
1a71acfa2e Add badge for dependents and dependent repos using Libraries.io (#1895)
See #1845
2018-08-12 11:05:43 -04:00
Paul Melnikow
db4bffb300 Split BaseService and BaseJsonService into separate modules (#1889)
There’s a lot of behavior here, and going to be even more, so I think it makes sense to split these up as I’ve done with the tests.
2018-08-11 10:43:05 -04:00
Paul Melnikow
ed81dcbb36 npm downloads: Better experience for new projects (#1892)
When a new project is created, the download badge shows “project not found” as reported in #1882. This gives a more informative message in that case.
2018-08-11 10:18:41 -04:00
chris48s
f05a3496ee Validate response json in [apm appveyor cdnjs clojars gem] (#1883)
* split gem service into multiple files
* add validation to apm, appveyor, cdnjs, clojars & gem services
* fix the apm examples
2018-08-10 20:52:09 +01: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
Paul Melnikow
7e04f25fc5 Tweak layout of services to conveniently handle large service families 2018-08-01 16:49:07 -04:00
Paul Melnikow
fa61247dba Rewrite [npm] typedefs badge using new-style service (#1735)
For #1358
2018-06-16 16:38:52 -04:00
chris48s
e6559a0889 fix typescript regex in [npm] tests (#1712)
- Expect `TypeScript vX.Y | Flow vX.Y`
  instead of `TypeScript vX.Y Flow vX.Y`
- Allow version numbers to have more than >1 digit
  after the point
2018-06-02 19:03:55 +01:00
Paul Melnikow
ea4b758612 Move service tests alongside code (#1563)
Per discussion in #1543
2018-03-20 18:32:48 -07:00