* update ESLint related packages
* migrate to flat config format
* Fix prefer-const error
Fixes
'overrideLogoSize' is never reassigned. Use 'const' instead
* remove irrelevant eslint-disable comment
These comments came from a swizzled upstream
component but never did anything in our codebase.
ESLint 9 does not allow disable comments
for rules that are not registered.
* remove irrelevant eslint-disable comments
These were here because in the past we were applying
mocha lint rules to files which contained no tests
ESLint 9 now flags eslint-disable comments
that aren't doing anythings
* remove irrelevant eslint-disable comment
ESLint 9 now flags eslint-disable comments
that aren't doing anything
* there are no .tsx files in our code any more
* include .mjs files in linting and formatting
* update sort-class-members rule for openApi property
and update the handful of files violating it
* add renderSizeBadge helper, use it everywhere
- switch from pretty-bytes to byte-size
- add renderSizeBadge() helper function
- match upstream conventions for metric/IEC units
- add new test helpers and use them in service tests
* unrelated: fix npm unpacked size query param schema
not strictly related to this PR
but I noticed it was broken
* chromewebstore: reformat size string, test against isIecFileSize
* add and consistently use parseDate and renderDateBadge helpers
also move
- age
- formatDate
- formatRelativeDate
to date.js
* fix bug in wordpress last update badge
* validate in formatDate() and age()
it is going to be unlikely we'll invoke either of these
directly now, but lets calidate here too
* remove unusued imports
* reverse colours for galaxy toolshed
* Added npm last update badge
* extended NpmBase class instead of BaseJsonService.
* added scoped packages to last update.
* introduced additionalQueryParamSchema
this is to add other query params schema, other than the one present in NpmBase.
* removed version query param
* in absence of modified date, it'll fetch created.
* removed version query param.
* added dist-tags.
* Update services/npm/npm-last-update.service.js
Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>
* refactored handle method for dist-tags.
* Update services/npm/npm-last-update.service.js
Co-authored-by: chris48s <chris48s@users.noreply.github.com>
* added date validation check.
* added date validation check.
* added date validation check.
---------
Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>
Co-authored-by: chris48s <chris48s@users.noreply.github.com>
* use defaultLabel in renderVersionBadge without tag
As we refactor the codebase to use renderVersionBadge.
some badges need to show default label regardless of tag existance.
This is usefull for cases where the label is dynamic.
This change requires fixing test for npm, not sure how it worked before.
* Refactor AurVersion to use renderVersionBadge
part of #2026
* Refactor CondaVersion to use renderVersionBadge
part of #2026
* Refactor WordpressRequiresVersion to use renderVersionBadge
* add postfix option to renderVersionBadge
* add missing tests for renderVersionBadge
add defaultLabel without tag test
add postfix test
add test for all options together
* Refactor WordpressPluginTestedVersion to use renderVersionBadge
* add prefix override to renderVersionBadge
adds tests for all options with prefix as well
used for #2026 but also usefull for usage letting people override v prefix for versions all over the project once #2026 is done as requested for example in #10574
* Refactor RequiresPHPVersionForType to use renderVersionBadge
* init npm-unpacked-size service
* add sample badge
* fetch unpacked size from latest version
* format unpacked size
* parametrize unpacked size by package name
* add optional version parameter
* fix typo on test
* rename test to tester
* test against json endpoint instead of svg
* test and impl version with undefined unpacked size
* test version with defined unpacked size
* change color to lightgray when unpackedSize is undefined
* add openapi docs
* extend NpmBase instead of BaseJsonService
* use isFileSize validator
* add schema to validate npm registry response body
* add tests for scoped packages
* impl scoped package route
* change the type of schema.dist.unpackedSize to optionalNonNegativeInteger
* add registry_uri query param
* add default label to badge
* unpack tag instead of version
* revert back to versions instead of tags
* allow serviceData to override cacheSeconds with a longer value
* prevent [endpoint] json cacheSeconds property exceeding service default
* allow ShieldsRuntimeError to specify a cacheSeconds property
By default error responses use the cacheLength of
the service class throwing the error.
This allows error to tell the handling layer the maxAge
that should be set on the error badge response.
* add customExceptions param
This
1. allows us to specify custom properties to pass to the exception
constructor if we throw any of the standard got errors
e.g: `ETIMEDOUT`, `ECONNRESET`, etc
2. uses a custom `cacheSeconds` property (if set on the exception)
to set the response maxAge
* customExceptions --> systemErrors
* errorMessages --> httpErrors
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* fix: node service has bad colors #4809
* chore: minor service test rename
Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
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
This moves the four npm download services into a single class, in line with #3174, and other service implementations we've written in the last couple months.
1. Change the suffixes from **/m** to **/month** for consistency.
2. Add tests of one of the intervals besides total.
3. Rewrite mocked service tests as unit tests.
4. Use (and work with) the `intervalMap` pattern that I think @calebcartwright started us using.
* 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
This moves a few helpers from `lib/` to `services/`:
build-status.js
build-status.spec.js
color-formatters.js
color-formatters.spec.js
contributor-count.js
licenses.js
licenses.spec.js
php-version.js
php-version.spec.js
text-formatters.js
text-formatters.spec.js
version.js
version.spec.js
And one from `lib/` to `core/`:
unhandled-rejection.spec.js
The diff is long, but the changes are straightforward.
Ref #2832
This picks up #2068 by adding per-badge stats as discussed in #966.
It ensures every service has a unique `name` property. By default this comes from the class name, and is overridden in all the various places where the class names are duplicated. (Some of those don't seem that useful, like the various download interval services, though those need to be refactored down into a single service anyway.) Tests enforce the names are unique. These are the names used by the service-test runner, so it's a good idea to make them unique anyway. (It was sort of strange before that you had to specify `nuget` instead of e.g. `resharper`.)
I've added validation to `deprecatedService` and `redirector`, and required that every `route` has a `base`, even if it's an empty string.
The name is used to generate unique metric labels, generating metrics like these:
```
service_requests_total{category="activity",family="eclipse-marketplace",service="eclipse_marketplace_update"} 2
service_requests_total{category="activity",family="npm",service="npm_collaborators"} 3
service_requests_total{category="activity",family="steam",service="steam_file_release_date"} 2
service_requests_total{category="analysis",family="ansible",service="ansible_galaxy_content_quality_score"} 2
service_requests_total{category="analysis",family="cii-best-practices",service="cii_best_practices_service"} 4
service_requests_total{category="analysis",family="cocoapods",service="cocoapods_docs"} 2
service_requests_total{category="analysis",family="codacy",service="codacy_grade"} 3
service_requests_total{category="analysis",family="coverity",service="coverity_scan"} 2
service_requests_total{category="analysis",family="coverity",service="deprecated_coverity_ondemand"} 2
service_requests_total{category="analysis",family="dependabot",service="dependabot_semver_compatibility"} 3
service_requests_total{category="analysis",family="lgtm",service="lgtm_alerts"} 2
service_requests_total{category="analysis",family="lgtm",service="lgtm_grade"} 3
service_requests_total{category="analysis",family="snyk",service="snyk_vulnerability_git_hub"} 4
service_requests_total{category="analysis",family="snyk",service="snyk_vulnerability_npm"} 5
service_requests_total{category="analysis",family="symfony",service="sensiolabs_i_redirector"} 1
service_requests_total{category="analysis",family="symfony",service="symfony_insight_grade"} 1
service_requests_total{category="build",family="appveyor",service="app_veyor_ci"} 3
service_requests_total{category="build",family="appveyor",service="app_veyor_tests"} 6
service_requests_total{category="build",family="azure-devops",service="azure_dev_ops_build"} 6
service_requests_total{category="build",family="azure-devops",service="azure_dev_ops_release"} 5
service_requests_total{category="build",family="azure-devops",service="azure_dev_ops_tests"} 6
service_requests_total{category="build",family="azure-devops",service="vso_build_redirector"} 2
service_requests_total{category="build",family="azure-devops",service="vso_release_redirector"} 1
service_requests_total{category="build",family="bitbucket",service="bitbucket_pipelines"} 5
service_requests_total{category="build",family="circleci",service="circle_ci"} 5
```
This is predicated on being able to use Prometheus's [`rate()`](https://prometheus.io/docs/prometheus/latest/querying/functions/#rate) function to visualize a counter's rate of change, as mentioned at https://github.com/badges/shields/issues/2068#issuecomment-466696561. Otherwise the stats will be disrupted every time a server restarts.
The metrics only appear on new-style services.
This will definitely save time, and ensure more uniformity.
It moves the `createServiceTester()` calls to a different place from where I'd like them, though I'm happy to have them checked by the linter.
Closes#2701
This is a mid-sized PR that adds query param validation to BaseService and updates most of the services which use query param validation to use it. There are a couple minor tweaks I made along the way.
Fix#2676
Fixes#2876 with @paulmelnikow's suggestion
Moved imports of `ServiceTester` and `createServiceTester` to a separate file so that dev dependencies are not imported by service classes.
Continue to implement #2698:
- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
- Replace the idea of color schemes with the idea of named colors (since none of our colorschemes have used `colorA`)
- Pass through the normalized color to `_shields_test` to harmonize with BaseService and simplify testing
- Update service tests
- Move responsibility for color generation into the npm package
- Remove several color helper functions and their tests
- Update gh-badge public API to accept `color` and `labelColor`
This is a precursor to refactoring some of the logo code for #2473.