Commit Graph

339 Commits

Author SHA1 Message Date
Paul Melnikow
b3606724fd Wildcard to run all service tests [*] (#2739)
Close #2685.
2019-01-11 16:11:46 -05:00
Paul Melnikow
c4efdc8e66 Rewrite and test Github auth logic, separating standard and search quota (#1205)
The end of an era.
2019-01-10 21:30:23 -05:00
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
945272db22 Rm old list of critical services (#2695)
This list was useful when we had to triage service tests, though happily that day is no longer :)
2019-01-08 15:13:47 -05:00
Pierre-Yves B
a158cf858b [Travis-Build] service rewrite, run [travis-php-version] (#2660)
* Rewrote Travis-Build service and separated tests

* Fixed property shorthand

* Strenghtened schema validation

* Implemented keyword remapping
2019-01-08 19:33:14 +00:00
Jan Keromnes
3ab2862922 Fix a few typos (#2697)
* Fix typos (using 'codespell -w')

* Properly capitalize Git and GitHub in TUTORIAL.md
2019-01-08 12:08:50 -05:00
Paul Melnikow
bc0be4f619 Fixes for config update (#2655)
Ref #2626 #2654
2019-01-06 12:23:58 -05:00
Paul Melnikow
fa5309400d PaaS, CI, and production-friendly config (#2626)
This implements the configuration mechanism I described in #2621. The heavy lifting is delegated to [node-config](https://github.com/lorenwest/node-config) with a minor assist from [dotenv](https://github.com/motdotla/dotenv).

`private/secret.json` has been replaced with environment variables and/or `config/local.yml`. See `doc/server-secrets.md`.
2019-01-06 10:42:09 -05:00
Ang YC
f6357da8ee [Date] Relative date badge (#2244)
Close #749
2019-01-04 11:32:38 -05:00
Paul Melnikow
5dc25af93c redirectUrl: Update terminology and add a test (#2617) 2019-01-02 13:48:27 -05:00
Caleb Cartwright
97cdc5762f Add timeout for server test setup/teardown (#2612) 2019-01-01 21:16:35 -05:00
Caleb Cartwright
dcfd84923c fix: fix bug in server-config on allowedOrigin (#2607) 2018-12-30 21:26:41 +00:00
Paul Melnikow
ebe6da23d4 Register missing redirects [static] (#2603) 2018-12-28 14:00:07 -05:00
Paul Melnikow
16491d787c Fix [suggest] (#2604) 2018-12-28 13:51:29 -05:00
Paul Melnikow
5c665a70da Overhaul initialization pattern for server + server tests (#2519)
Because `server.js` was long a monolith, there are a bunch of shims in place to facilitate unit testing. A few of the test suites share port 1111 which means if one of them fails to set up, the port won't be freed and other unrelated tests will fail. Some of the tests which trigger server setup include timeouts which were added to give setup code time to run. In one the test suites, we actually modify `process.argv`, which seems completely gross.

This implements a few changes which improve this:

1. Separate the server from the server startup script, splitting out `lib/server.js`.
2. Inject config into the server and validate the config schema.
3. Inject config into the service test runner.
4. Use `portfinder`, a popular utility for grabbing open ports during testing.
5. Switch more of the setup code from callbacks to async-await.

Overall it leaves everything acting more reliably and looking rather cleaner, if in a few places more verbose.

It also fixes the root cause of #1455, a `setTimeout` in `rate-limit`. Off and on during development of this changeset, Mocha would decide not to exit, and that turned out to be the culprit.

Fix #1455
2018-12-23 11:24:22 -05:00
Paul Melnikow
ebe4a12acc Convert lodash.uniq to native and remove an unused dev dep (#2564) 2018-12-20 15:15:56 -05:00
Caleb Cartwright
a1150efd25 Migrate [Coverity] to new service model (#2550)
* feat: migrate coverity to new service model
* chore: add coverity ondemand to deprecated services list
2018-12-18 21:19:50 +00:00
chris48s
df22adfba7 remove logos for deprecated services (#2539)
* remove logos for deprecated services
* remove references to gratipay logo in tests
2018-12-16 19:33:27 +00:00
Caleb Cartwright
dea35025b1 Deprecate [nsp] service (#2529)
deprecated nsp service and added doc for deprecation
2018-12-16 19:21:22 +00:00
Caleb Cartwright
d74568b9c9 Minor test updates for jenkins coverage and token-pool (#2509) 2018-12-11 21:10:21 +00:00
Paul Melnikow
58b276539a Refactor frontend main page and badge-example code (#2441)
- The goal of this PR is:
    - Consume the new service-definition format. (#2397)
    - Make the frontend more readable.
- Behavior changes:
    - I changed the **Image** field in the markup modal to show only the path.
    - I added another click-to-select field below that shows the complete URL.
    - This made it easier to suppress the live badge preview while it contains placeholders like `:user` or `:gem`, a minor tweak discussed at https://github.com/badges/shields/issues/2427#issuecomment-442972100.
    - The search box now searches all categories, regardless of the current page. (This is an improvement, I would say.)
- I did not deliberately address performance, though I ripped out a bunch of anonymous functions and avoided re-filtering all the examples by category on every render, which I expect will not hurt. I haven't really tested this on a mobile connection and it'd be worth doing that.
- It would be great to have some tests of the components, though getting started with that seemed like a big project and I did not want to make this any larger than it already is.

It's a medium-sized refactor:

1. Replace `BadgeExamples`, `Category` and `Badge` component with a completely rewritten `BadgeExamples` component which renders a table of badges, and `CategoryHeading` and `CategoryHeadings` components.
2. Refactor `ExamplesPage` and `SearchResults` components into a new `Main` component.
3. Rewrite the data flow for `MarkupModal`. Rather than rely on unmounting and remounting the component to copy the badge URL into state, employ the `getDerivedStateFromProps` lifecycle method.
4. Remove `prepareExamples` and `all-badge-examples`.
5. Rewrite the `$suggest` schema to harmonize with the service definition format. It's not backward-compatible which means at deploy time there probably will be 10–20 minutes of downtime on that feature, between the first server deploy and the final gh-pages deploy.  🤷‍♂️ (We could leave the old version in place if it seems worth it.)
6. Added two new functions in `make-badge-url` with tests. I removed _most_ of the uses of the old functions, but there are some in parts of the frontend I didn't touch like the static and dynamic badge generators, and again I didn't want to make this any larger than it already is.
7. Fix a couple bugs in the service-definition export.
2018-12-08 15:26:13 -05:00
Paul Melnikow
6a737b7b38 Rewrite the DynamicJson badge (#2399)
This starts the rewrite of the dynamic badges. I've pulled into BaseService an initial version of the query param validation from #2325.

I've extended from BaseJsonService to avoid duplicating the deserialization logic, though it means there is a bit of duplicated code among the three dynamic services. The way to unravel this would be to move the logic from `_requestJson` and friends from the base classes into functions so DynamicJson can inherit from BaseDynamic. Would that be worth it?

This introduces a regression of #1446 for this badge.

Close #2345
2018-12-06 16:45:40 -05:00
M C
9e95020b18 Add [Matrix] Badge (#2417)
* Added matrix badge

* decreased the size of the matrix logo by more than 50%

* returning the size in fetch() instead of an object

* found another way to register a throwaway account (guest account). this one actually works on matrix.org, but I kept the old way as a backup method. also changed the POST from /members to /state because guest accounts didn't work with /members

* updated logo to a recolored version of the official logo

* Removed unnecessary comments.
Added documentation on how to create the badge URL.
Added a test that hits a real room to test for API compliance.
URLs are now obtained from getter functions.
Added JSON schema for the /state API request.
Improved state response filter.
Replaced example URL room ID to a dedicated testing room.
Made some error messages more helpful.

* correctly implemented requested changes

* changed color hex codes to constants
2018-12-06 19:25:59 +00:00
Paul Melnikow
477d357286 Sort some badges; add an Activity category (#2448) 2018-12-05 14:17:37 -05:00
Paul Melnikow
59fdd8a5b0 TokenPool: Add debug logging helper + return correct error (#2400)
Slice another sliver from #1205.
2018-12-02 11:28:21 -05:00
Tair Assimov
88294563cc Deprecate dockbit service - discontinued (#2410)
Ref: #2344
2018-12-02 11:26:10 -05:00
Paul Melnikow
0aee712738 Fix crash in legacy service (#2437)
Bug in #2360
2018-12-01 15:10:32 -05:00
Paul Melnikow
54a36e9474 Refactor cache-header handling and config, create NonMemoryCachingBaseService, rewrite [flip] (#2360)
There's a lot going on in this PR, though it's all interdependent, so the only way I can see to break it up into smaller pieces would be serially.

1. I completely refactored the functions for managing cache headers. These have been added to `services/cache-headers.js`, and in some ways set the stage for the rest of this PR.

    - There are ample higher-level test of the functionality via `request-handler`. Refactoring these tests was deferred. Cache headers were previously dealt with in three places:
        - `request-handler.js`, for the dynamic badges. This function now calls `setCacheHeaders`.
        - `base-static.js`, for the static badges. This method now calls the wordy `serverHasBeenUpSinceResourceCached` and `setCacheHeadersForStaticResource`.
        - The bitFlip badge in `server.js`. 👈 This is what set all this in motion. This badge has been refactored to a new-style service based on a new `NoncachingBaseService` which does not use the Shields in-memory cache that the dynamic badges user.
    - I'm open to clearer names for `NoncachingBaseService`, which is kind of terrible. Absent alternatives, I wrote a short essay of clarification in the docstring. 😝 

2. In the process of writing `NoncachingBaseService`, I discovered it takes several lines of code to instantiate and invoke a service. These would be duplicated in three or four places in production code, and in lots and lots of tests. I kept the line that goes from regex to namedParams (for reasons) and moved the rest into a static method called `invoke()`, which instantiates and invokes the service. This _replaced_ the instance method `invokeHandler`.
    - I gently reworked the unit tests to use `invoke` instead of `invokeHandler`– generally for the better.
    - I made a small change to `BaseStatic`. Now it invokes `handle()` async as the dynamic badges do. This way it could use `BaseService.invoke()`.

3. There was logic in `request-handler` for processing environment variables, validating them, and setting defaults. This could have been lifted whole-hog to `services/cache-headers.js`, though I didn't do that. Instead I moved it to `server-config.js`. Ideally `server-config` is the only module that should access `process.env`. This puts the defaults and config validation in one place, decouples the config schema from the entire rest of the application, and significantly simplifies our ability to test different configs, particularly on small units of code. (We were doing this well enough before in `request-handler.spec`, though it required mutating the environment, which was kludgy.) Some of the `request-handler` tests could be rewritten at a higher level, with lower-level data-driven tests directly against `cache-headers`.
2018-12-01 13:57:34 -05:00
Marcin Mielnicki
c72e366895 Run service tests on a given (remote) instance; test on [jetbrains] (#2195)
* Allow to run service tests for remote shields instance

* Allow to run service tests for remote shields instance - doc

* Load testedServerUrl from env variable

* Load 'skipIntercepted' flag from env variable
2018-11-25 15:51:57 +01:00
Paul Melnikow
b600bde44e The last of the badge examples (#2389)
* Move PowerShell

* Move Choco + Resharper

* Move MyGet and Nuget
2018-11-25 09:14:54 -05:00
Paul Melnikow
ccfac2eab3 Move remaining badge examples into services/ [cpan] (#2349)
Except NuGet; leaving those for the last pass.
2018-11-19 15:25:34 -05:00
Pierre-Yves B
5ed0f67640 Deprecate [ImageLayers] service (#2352) 2018-11-18 18:08:47 +00:00
Paul Melnikow
282520041d Add [GitlabPipeline] badge (#2325)
There's a lot of demand for the Gitlab badges (#541) and the PR has been lingering, so I thought I'd start off one of the simple ones as a new-style service. This one is SVG-based, so it shouldn't require the API-token logic which could use some more testing and will require us to create an app and configure it on our server.

We don't have any validation in place for `queryParams`. Probably this should be added to BaseService, though for the time being I extracted a helper function.

Thanks to @LVMBDV for getting this work started in #1838!
2018-11-18 10:06:47 -05:00
Paul Melnikow
9d77c8afe2 Rewrite [codacy] badges; rm unused svg helpers (#2275) 2018-11-17 09:51:20 -05:00
Paul Melnikow
ff9cd20821 Coverage cleanup (#2328)
- Stop running daily service tests in the main repo (since they're now handled [over here](https://github.com/badges/daily-tests)
- Add coverage and separate daily tests badges with links to coveralls
- Update our coverage ignores
    - Move scripts, which do not need coverage, into `scripts/`
- Split out coverage test for npm package
- Remove spurious env var

Ref: #1584 #2314
2018-11-17 09:37:09 -05:00
Paul Melnikow
065dd570ad Move [StaticBadge] to own service & add test; also affects [gitter] (#2284)
This picks up @RedSparr0w's work in #1802.

1. The handler for the static badge is moved into its own service with a synchronous handler. Avoiding an async call may make the static badges slightly faster, though it may be worth profiling this if it turns out we want asynchronous static badges in the future. If it doesn't make a performance difference we could make this handler `async` like the others.
2. Most of the custom static-badge logic is in a BaseStaticBadge base class.
3. Rewrite the static Gitter badge to use BaseStaticBadge.
4. A bit of minor cleanup in related functions.
2018-11-16 19:21:48 -05:00
Paul Melnikow
51897b3c7e Precompute text width using a lookup table (#2311)
This simplifies and further optimizes text-width computation by computing the entire width table in advance, and serializing it in the style of QuickTextMeasurer (#1390). This entirely removes the need for PDFKit at runtime. This has the advantage of fixing #1305 – more generally: producing the same result everywhere – without having to deploy a copy of Verdana.

The lifting is delegated to these three libraries, which are housed in a monorepo: https://github.com/metabolize/anafanafo

I'd be happy to move it into the badges org if folks want to collaborate on maintaining them.

QuickTextMeasurer took kerning pairs into account, whereas this implementation does not. I was thinking kerning would be a necessary refinement, though this seems to work well enough.

I dropped in a binary-search package to traverse the data structure, in part to conserve space. This causes a moderate performance regression, though there is ample room for improving on that: https://github.com/badges/shields/pull/2311#issuecomment-439182704
2018-11-15 17:27:21 -05:00
Paul Melnikow
fe05d00747 Move github examples into services/github (#2309) 2018-11-15 15:57:56 -05:00
Paul Melnikow
5d63effabc Fix a crasher in production (#2313)
When I deployed 5e99aad2de to s0, shortly after Sentry picked up an unhandled error. I'm not sure which of the legacy badges this is in.

The bug was introduced just now, in #2257. Oops!

A test would have caught this, but I don't think it's worth wrapping tests around this difficult-to-test code. It makes more sense I think, to refactor the remaining badges that use it, replace it with something using async/await (maybe based on [node-cache](https://www.npmjs.com/package/node-cache), and test that.
2018-11-15 14:25:46 -05:00
chris48s
b68ac16092 Move NPM package files out of /lib ; affects [resharper nuget myget dub chocolatey github] (#2300)
* move gh-badges files out of /lib

As far as possible, this is just moving files
around and updating paths however there are 2
functional changes in this commit:
- remove use of lib/register-chai-plugins.spec
  in badge-cli.spec.js
- remove use of starRating()
  in text-measurer.spec.js

* update service tests that use colorscheme.json

* split package.json in two

* clean up import

* don't hard-code path

* start a changelog

* put a license file in the package dir

* re-organise documentation 📚

* don't pack test files

* remove favicon from Makefile

* give package its own test command

* link the docs better in README
2018-11-15 18:48:01 +00:00
Paul Melnikow
5e99aad2de Rewrite [NuGet] badges including [myget chocolatey resharper powershellgallery] (#2257)
The NuGet badge examples are straggling in all-badge-examples. Rather than move them as is, I thought it made more sense to refactor the services and see if they could be generated. I didn't take that on here; this is a straight rewrite of the badges. The old implementations were fairly difficult to follow. The new implementations are complicated too, though I hope much more readable.

Though the NuGet behaviors could be consolidated into a single flag, I split `withTenant` and `withFeed` into separate flags, thinking naming the behaviors makes the implementations easier to understand. I defaulted these to true, thinking that really this is really a MyGet implementation which is generalized to NuGet. Though maybe it makes more sense to have the MyGet style as the default. Probably it doesn't matter much either way.

I added a helper class ServiceUrlBuilder to construct the Shields service URL. It's useful in this complex case where the URL must be built up conditionally. This might be useful in a couple other places.

I also wrote a new service to handle the Powershell badges. They've diverged a little bit from the Nuget v2. There's a bit of shared code which I factored out.

If the XML Nuget APIs are more reliable, we could consider switching everything else over to them, though for now I would like to get this merged and get #2078 fixed.

Fix #2078
2018-11-14 17:28:15 -05:00
Marcin Mielnicki
a039fffe79 Refactor [Jetbrains] service; affects [eclipse-marketplace] (#2232)
* Refactor Jetbrains

* Test that custom parser options are provided

* Code refactoring

* Code refactoring

* url -> route

* package-lock.json updated
2018-11-10 16:05:00 +01:00
Paul Melnikow
5dd4ee078b Start on the Github rewrite, with [GithubPullRequestCheckState] (#2253)
The GitHub service family is the largest, and as yet untouched by our service rewrite. I thought I would start the process by tackling one service.

This pull request has a few things going on:

1. Rename pull-request-status to pull-request-check-state. We have another badge called pull request status. It seems like the checks are called one thing in the UI and another thing in the API, which is unfortunate. If other folks have strong feelings about the name, I’ll defer.
2. Move its tests and tighten up the syntax.
3. Move its badge examples including the doc string.
4. Add a new helper `errorMessagesFor` to use in the new services in place of `githubCheckErrorResponse`. It seems like we didn’t really use the `errorMessages` parameter to `githubCheckErrorResponse`, so I pared this down. I’m not sure if this is the function we’ll ultimately want, but it seems like a good place to start.
5. Pull fetch code I _know_ we use in other places into `github-common-fetch`. As in the PR I just opened for azure-devops, this takes a functional approach to the shared code, which is more direct, nimble, and easy to reason about than inheritance.
6. Create `GithubAuthService` which functions identically to BaseJsonService, except for one thing, which is that it uses the token pool. I accomplished this by adding a `_requestFetcher` property to BaseService, which is initialized to `sendAndCacheRequest` in the constructor, and can be overridden in subclasses. Since we weren’t using `_sendAndCacheRequest` directly except in BaseService and tests, I removed that property. I like this approach to patching in the GitHub auth because it’s very simple and creates no new API exposure. However, the way we’re doing the dependency injection feels a bit odd. Maybe the eventual refactor of request-handler would be a godo time to revisit this.

The GitHub requests go through many, many layers of indirection at this point. Later on it would be good to shave some of these off, perhaps once the legacy GitHub services have been converted, or when all the services are done and we can take another look at the base service hierarchy. The work in #2021 and #1205 is also related.
2018-11-09 16:22:48 -05:00
Paul Melnikow
3eac8ebbfb Rework GitHub acceptor and move to its own module (#2021)
Continue to merge the work from #1205.
2018-11-09 15:14:01 -05:00
Paul Melnikow
e4e5628207 Fix suggest on staging in Firefox (#2277)
Fix #2245
2018-11-09 14:06:13 -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
Paul Melnikow
3bb392dfae Remove some duplicated URL generation code (#2240)
I went down a rabbit hole while trying to untangle the bug in the dockbit and bitrise examples https://github.com/badges/shields/pull/2234#pullrequestreview-169997546.

The URL generation code is spaghetti-like, with functions, many of which I wrote, with opaque names, doing similar but not identical things, and making slightly incompatible assumptions about the way query strings are handled.

I got a bit lost and need to take a step back.

Meanwhile, this is a small piece of work I did that’s worth keeping. It doesn’t scratch the surface of the tangle, but it does remove a bit of duplication.

It also makes a minor stylistic ES6 change in the handling of default arguments.

Ref: #2027
2018-11-05 16:55:49 -05:00
Paul Melnikow
600c369823 Remove some uses of to-be-deprecated url.format and url.parse APIs (#2265)
See #2225
2018-11-05 16:48:04 -05:00
Marcin Mielnicki
bc4bd79e90 Metrics with Prometheus (#2069)
* Basic process metrics

* Enable Prometheus by an environment variable

* Code formatting

* Documentation for Prometheus metrics

* Link from README to documentation of Prometheus

* Link from README to documentation of Prometheus

* Link from README to documentation of Prometheus

* Separate module for metrics + tests

* Metrics limited by IP

* Metrics are forbidded for all requets by default

* Code refactoring

* allowedIps passed as a string to PrometheusMetrics

* Handle missing config

* METRICS_PROMETHEUS_ALLOWED_IPS added to documentation

* Log info about enabled metrics

* Unused code removed

* package-lock.json updated

* prom-client updated to 11.1.2

* Code refactoring

* Do not read IP address from X-Forwarder-For header
2018-11-04 18:54:43 +01:00
Paul Melnikow
d55e1c15a6 Enforce using async-await [f-droid] (#2241)
Close #2028
2018-11-04 00:33:47 -04:00