Compare commits
38 Commits
integratio
...
server-202
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1954963cd3 | ||
|
|
fbb2ff3619 | ||
|
|
9e29d3d3f2 | ||
|
|
1fad0888b2 | ||
|
|
4bf0675de2 | ||
|
|
4fb2896597 | ||
|
|
647a466399 | ||
|
|
bf15ad1f3a | ||
|
|
202d72d365 | ||
|
|
efa705d925 | ||
|
|
5234ecde93 | ||
|
|
345da16365 | ||
|
|
37a36f5fea | ||
|
|
3f63990049 | ||
|
|
0605a074e9 | ||
|
|
74ada5af29 | ||
|
|
04d5a9d4d1 | ||
|
|
f185167b7d | ||
|
|
567cae8e9c | ||
|
|
b7da0f8a56 | ||
|
|
19363f2245 | ||
|
|
ba6fdfb5a6 | ||
|
|
9bfca5a575 | ||
|
|
324e6be067 | ||
|
|
15a7b074f4 | ||
|
|
35fbbad90e | ||
|
|
fe8031af27 | ||
|
|
5cc21ce040 | ||
|
|
7621603bef | ||
|
|
786149ccbe | ||
|
|
60125707ad | ||
|
|
c64bb7e1f3 | ||
|
|
e1c1a021f9 | ||
|
|
daf5ad5b2a | ||
|
|
a9e67c8b19 | ||
|
|
62cabe0b32 | ||
|
|
ae7960244d | ||
|
|
e8686395b1 |
@@ -149,6 +149,8 @@ jobs:
|
||||
main@node-17:
|
||||
docker:
|
||||
- image: cimg/node:17.9
|
||||
environment:
|
||||
NPM_CONFIG_ENGINE_STRICT: 'false'
|
||||
|
||||
<<: *main_steps
|
||||
|
||||
@@ -163,6 +165,8 @@ jobs:
|
||||
docker:
|
||||
- image: cimg/node:17.9
|
||||
- image: redis
|
||||
environment:
|
||||
NPM_CONFIG_ENGINE_STRICT: 'false'
|
||||
|
||||
<<: *integration_steps
|
||||
|
||||
@@ -239,6 +243,8 @@ jobs:
|
||||
services@node-17:
|
||||
docker:
|
||||
- image: cimg/node:17.9
|
||||
environment:
|
||||
NPM_CONFIG_ENGINE_STRICT: 'false'
|
||||
|
||||
<<: *services_steps
|
||||
|
||||
|
||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -4,6 +4,19 @@ Note: this changelog is for the shields.io server. The changelog for the badge-m
|
||||
|
||||
---
|
||||
|
||||
## server-2022-08-01
|
||||
|
||||
- [pypi] Add Framework Version Badges support [#8261](https://github.com/badges/shields/issues/8261)
|
||||
- feat: add [GitlabForks] server [#8208](https://github.com/badges/shields/issues/8208)
|
||||
- Update PyPI api according to https://warehouse.pypa.io/api-reference/json.html [#8251](https://github.com/badges/shields/issues/8251)
|
||||
- Add [galaxytoolshed] Activity [#8164](https://github.com/badges/shields/issues/8164)
|
||||
- [greasyfork] Add Greasy Fork rating badges [#8087](https://github.com/badges/shields/issues/8087)
|
||||
- refactor(deps): Replace moment with dayjs [#8192](https://github.com/badges/shields/issues/8192)
|
||||
- add spaces round pipe in [conda] badge [#8189](https://github.com/badges/shields/issues/8189)
|
||||
- Add [ROS] version service [#8169](https://github.com/badges/shields/issues/8169)
|
||||
- feat: add [gitlabissues] service [#8108](https://github.com/badges/shields/issues/8108)
|
||||
- Dependency updates
|
||||
|
||||
## server-2022-07-03
|
||||
|
||||
- Add [galaxytoolshed] services [#8114](https://github.com/badges/shields/issues/8114)
|
||||
|
||||
10
app.json
10
app.json
@@ -35,6 +35,16 @@
|
||||
"WEBLATE_API_KEY": {
|
||||
"description": "Configure the API key to be used for the Weblate service.",
|
||||
"required": false
|
||||
},
|
||||
"METRICS_INFLUX_ENABLED": {
|
||||
"description": "Disable influx metrics",
|
||||
"value": "false",
|
||||
"required": false
|
||||
},
|
||||
"REQUIRE_CLOUDFLARE": {
|
||||
"description": "Allow direct traffic",
|
||||
"value": "false",
|
||||
"required": false
|
||||
}
|
||||
},
|
||||
"formation": {
|
||||
|
||||
@@ -58,7 +58,7 @@ The tests are also divided into several parts:
|
||||
[redis-token-persistence.integration]: https://github.com/badges/shields/blob/master/core/token-pooling/redis-token-persistence.integration.js
|
||||
[github-api-provider.integration]: https://github.com/badges/shields/blob/master/services/github/github-api-provider.integration.js
|
||||
|
||||
Our goal is for the core code is to reach 100% coverage of the code in the
|
||||
Our goal is to reach 100% coverage of the code in the
|
||||
frontend, core, and service helper functions when the unit and functional
|
||||
tests are run.
|
||||
|
||||
@@ -95,7 +95,7 @@ test this kind of logic through unit tests (e.g. of `render()` and
|
||||
callback with the four parameters `( queryParams, match, end, ask )` which
|
||||
is created in a legacy helper function in
|
||||
[`legacy-request-handler.js`][legacy-request-handler]. This callback
|
||||
delegates to a callback in `BaseService.register` with four different
|
||||
delegates to a callback in `BaseService.register` with three different
|
||||
parameters `( queryParams, match, sendBadge )`, which
|
||||
then runs `BaseService.invoke`. `BaseService.invoke` instantiates the
|
||||
service and runs `BaseService#handle`.
|
||||
|
||||
@@ -67,7 +67,7 @@ t.create('Build status')
|
||||
- All badges on shields can be requested in a number of formats. As well as calling https://img.shields.io/wercker/build/wercker/go-wercker-api.svg to generate  we can also call https://img.shields.io/wercker/build/wercker/go-wercker-api.json to request the same content as JSON. When writing service tests, we request the badge in JSON format so it is easier to make assertions about the content.
|
||||
- We don't need to explicitly call `/wercker/build/wercker/go-wercker-api.json` here, only `/build/wercker/go-wercker-api.json`. When we create a tester object with `createServiceTester()` the URL base defined in our service class (in this case `/wercker`) is used as the base URL for any requests made by the tester object.
|
||||
3. `expectBadge()` is a helper function which accepts either a string literal, a [RegExp][] or a [Joi][] schema for the different fields.
|
||||
Joi is a validation library that is build into IcedFrisby which you can use to
|
||||
Joi is a validation library that is built into IcedFrisby which you can use to
|
||||
match based on a set of allowed strings, regexes, or specific values. You can
|
||||
refer to their [API reference][joi api].
|
||||
4. We expect `label` to be a string literal `"build"`.
|
||||
|
||||
1393
package-lock.json
generated
1393
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
40
package.json
40
package.json
@@ -24,7 +24,7 @@
|
||||
"@fontsource/lato": "^4.5.8",
|
||||
"@fontsource/lekton": "^4.5.9",
|
||||
"@renovate/pep440": "^1.0.0",
|
||||
"@sentry/node": "^7.5.1",
|
||||
"@sentry/node": "^7.8.0",
|
||||
"@shields_io/camp": "^18.1.1",
|
||||
"badge-maker": "file:badge-maker",
|
||||
"bytes": "^3.1.2",
|
||||
@@ -34,16 +34,17 @@
|
||||
"cloudflare-middleware": "^1.0.4",
|
||||
"config": "^3.3.7",
|
||||
"cross-env": "^7.0.3",
|
||||
"dayjs": "^1.11.4",
|
||||
"decamelize": "^3.2.0",
|
||||
"emojic": "^1.1.17",
|
||||
"escape-string-regexp": "^4.0.0",
|
||||
"fast-xml-parser": "^4.0.8",
|
||||
"fast-xml-parser": "^4.0.9",
|
||||
"glob": "^8.0.3",
|
||||
"global-agent": "^3.0.0",
|
||||
"got": "^12.1.0",
|
||||
"got": "^12.3.0",
|
||||
"graphql": "^15.6.1",
|
||||
"graphql-tag": "^2.12.6",
|
||||
"ioredis": "5.1.0",
|
||||
"ioredis": "5.2.2",
|
||||
"joi": "17.6.0",
|
||||
"joi-extension-semver": "5.0.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
@@ -51,7 +52,6 @@
|
||||
"lodash.countby": "^4.6.0",
|
||||
"lodash.groupby": "^4.6.0",
|
||||
"lodash.times": "^4.3.2",
|
||||
"moment": "^2.29.4",
|
||||
"node-env-flag": "^0.1.0",
|
||||
"parse-link-header": "^2.0.0",
|
||||
"path-to-regexp": "^6.2.1",
|
||||
@@ -61,7 +61,7 @@
|
||||
"qs": "^6.11.0",
|
||||
"query-string": "^7.1.1",
|
||||
"semver": "~7.3.7",
|
||||
"simple-icons": "7.4.0",
|
||||
"simple-icons": "7.5.0",
|
||||
"webextension-store-meta": "^1.0.5",
|
||||
"xmldom": "~0.6.0",
|
||||
"xpath": "~0.0.32"
|
||||
@@ -141,9 +141,9 @@
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.18.6",
|
||||
"@babel/core": "^7.18.9",
|
||||
"@babel/polyfill": "^7.12.1",
|
||||
"@babel/register": "7.18.6",
|
||||
"@babel/register": "7.18.9",
|
||||
"@istanbuljs/schema": "^0.1.3",
|
||||
"@mapbox/react-click-to-select": "^2.2.1",
|
||||
"@types/chai": "^4.3.1",
|
||||
@@ -155,11 +155,11 @@
|
||||
"@types/react-modal": "^3.13.1",
|
||||
"@types/react-select": "^4.0.17",
|
||||
"@types/styled-components": "5.1.25",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
||||
"@typescript-eslint/parser": "^5.27.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
||||
"@typescript-eslint/parser": "^5.30.7",
|
||||
"babel-plugin-inline-react-svg": "^2.0.1",
|
||||
"babel-preset-gatsby": "^2.14.0",
|
||||
"c8": "^7.11.3",
|
||||
"babel-preset-gatsby": "^2.19.0",
|
||||
"c8": "^7.12.0",
|
||||
"caller": "^1.1.0",
|
||||
"chai": "^4.3.6",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
@@ -167,8 +167,8 @@
|
||||
"chai-string": "^1.4.0",
|
||||
"child-process-promise": "^2.2.1",
|
||||
"clipboard-copy": "^4.0.1",
|
||||
"concurrently": "^7.2.2",
|
||||
"cypress": "^10.3.0",
|
||||
"concurrently": "^7.3.0",
|
||||
"cypress": "^10.3.1",
|
||||
"danger": "^11.1.1",
|
||||
"danger-plugin-no-test-shortcuts": "^2.0.0",
|
||||
"deepmerge": "^4.2.2",
|
||||
@@ -181,7 +181,7 @@
|
||||
"eslint-plugin-cypress": "^2.12.1",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-jsdoc": "^39.3.3",
|
||||
"eslint-plugin-mocha": "^10.0.5",
|
||||
"eslint-plugin-mocha": "^10.1.0",
|
||||
"eslint-plugin-no-extension-in-require": "^0.2.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^5.2.0",
|
||||
@@ -191,18 +191,18 @@
|
||||
"fetch-ponyfill": "^7.1.0",
|
||||
"form-data": "^4.0.0",
|
||||
"gatsby": "4.6.2",
|
||||
"gatsby-plugin-catch-links": "^4.11.0",
|
||||
"gatsby-plugin-catch-links": "^4.19.0",
|
||||
"gatsby-plugin-page-creator": "^4.7.0",
|
||||
"gatsby-plugin-react-helmet": "^5.10.0",
|
||||
"gatsby-plugin-remove-trailing-slashes": "^4.9.0",
|
||||
"gatsby-plugin-styled-components": "^5.11.0",
|
||||
"gatsby-plugin-styled-components": "^5.19.0",
|
||||
"gatsby-plugin-typescript": "^4.11.1",
|
||||
"humanize-string": "^2.1.0",
|
||||
"icedfrisby": "4.0.0",
|
||||
"icedfrisby-nock": "^2.1.0",
|
||||
"is-svg": "^4.3.2",
|
||||
"js-yaml-loader": "^1.2.2",
|
||||
"jsdoc": "^3.6.10",
|
||||
"jsdoc": "^3.6.11",
|
||||
"lint-staged": "^13.0.3",
|
||||
"lodash.debounce": "^4.0.8",
|
||||
"lodash.difference": "^4.5.0",
|
||||
@@ -211,7 +211,7 @@
|
||||
"mocha-env-reporter": "^4.0.0",
|
||||
"mocha-junit-reporter": "^2.0.2",
|
||||
"mocha-yaml-loader": "^1.0.3",
|
||||
"nock": "13.2.8",
|
||||
"nock": "13.2.9",
|
||||
"node-mocks-http": "^1.11.0",
|
||||
"nodemon": "^2.0.19",
|
||||
"npm-run-all": "^4.1.5",
|
||||
@@ -241,7 +241,7 @@
|
||||
"url": "^0.11.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.13.0",
|
||||
"node": "^16.13.0",
|
||||
"npm": ">=8.0.0"
|
||||
},
|
||||
"type": "module",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @module
|
||||
*/
|
||||
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import pep440 from '@renovate/pep440'
|
||||
|
||||
/**
|
||||
@@ -182,7 +182,7 @@ function colorScale(steps, colors, reversed) {
|
||||
*/
|
||||
function age(date) {
|
||||
const colorByAge = colorScale([7, 30, 180, 365, 730], undefined, true)
|
||||
const daysElapsed = moment().diff(moment(date), 'days')
|
||||
const daysElapsed = dayjs().diff(dayjs(date), 'days')
|
||||
return colorByAge(daysElapsed)
|
||||
}
|
||||
|
||||
|
||||
41
services/galaxytoolshed/galaxytoolshed-activity.service.js
Normal file
41
services/galaxytoolshed/galaxytoolshed-activity.service.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { formatDate } from '../text-formatters.js'
|
||||
import BaseGalaxyToolshedService from './galaxytoolshed-base.js'
|
||||
|
||||
export default class GalaxyToolshedCreatedDate extends BaseGalaxyToolshedService {
|
||||
static category = 'activity'
|
||||
static route = {
|
||||
base: 'galaxytoolshed/created-date',
|
||||
pattern: ':repository/:owner',
|
||||
}
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'Galaxy Toolshed (created date)',
|
||||
namedParams: {
|
||||
repository: 'sra_tools',
|
||||
owner: 'iuc',
|
||||
},
|
||||
staticPreview: this.render({
|
||||
date: this.render({ date: '2022-01-01' }),
|
||||
}),
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = {
|
||||
label: 'created date',
|
||||
color: 'blue',
|
||||
}
|
||||
|
||||
static render({ date }) {
|
||||
return { message: formatDate(date) }
|
||||
}
|
||||
|
||||
async handle({ repository, owner }) {
|
||||
const response = await this.fetchLastOrderedInstallableRevisionsSchema({
|
||||
repository,
|
||||
owner,
|
||||
})
|
||||
const { create_time: date } = response[0]
|
||||
return this.constructor.render({ date })
|
||||
}
|
||||
}
|
||||
23
services/galaxytoolshed/galaxytoolshed-activity.tester.js
Normal file
23
services/galaxytoolshed/galaxytoolshed-activity.tester.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { isFormattedDate } from '../test-validators.js'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('Created Date')
|
||||
.get('/sra_tools/iuc.json')
|
||||
.expectBadge({ label: 'created date', message: isFormattedDate })
|
||||
|
||||
t.create('Created Date - repository not found')
|
||||
.get('/sra_tool/iuc.json')
|
||||
.expectBadge({ label: 'created date', message: 'not found' })
|
||||
|
||||
t.create('Created Date - owner not found')
|
||||
.get('/sra_tools/iu.json')
|
||||
.expectBadge({ label: 'created date', message: 'not found' })
|
||||
|
||||
t.create('Created Date - changesetRevision not found')
|
||||
.get('/bioqc/badilla.json')
|
||||
.expectBadge({
|
||||
label: 'created date',
|
||||
message: 'changesetRevision not found',
|
||||
})
|
||||
@@ -9,6 +9,7 @@ const orderedInstallableRevisionsSchema = Joi.array()
|
||||
const repositoryRevisionInstallInfoSchema = Joi.array()
|
||||
.ordered(
|
||||
Joi.object({
|
||||
create_time: Joi.date().required(),
|
||||
times_downloaded: nonNegativeInteger,
|
||||
}).required()
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import gql from 'graphql-tag'
|
||||
import Joi from 'joi'
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import { metric, maybePluralize } from '../text-formatters.js'
|
||||
import { nonNegativeInteger } from '../validators.js'
|
||||
import { GithubAuthV4Service } from './github-auth-service.js'
|
||||
@@ -121,7 +121,7 @@ export default class GithubHacktoberfestCombinedStatus extends GithubAuthV4Servi
|
||||
// The global cutoff time is 11/1 noon UTC.
|
||||
// https://github.com/badges/shields/pull/4109#discussion_r330782093
|
||||
// We want to show "1 day left" on the last day so we add 1.
|
||||
daysLeft = moment(`${year}-11-01 12:00:00 Z`).diff(moment(), 'days') + 1
|
||||
daysLeft = dayjs(`${year}-11-01 12:00:00 Z`).diff(dayjs(), 'days') + 1
|
||||
}
|
||||
if (daysLeft < 0) {
|
||||
return {
|
||||
@@ -205,10 +205,7 @@ export default class GithubHacktoberfestCombinedStatus extends GithubAuthV4Servi
|
||||
}
|
||||
|
||||
static getCalendarPosition(year) {
|
||||
const daysToStart = moment(`${year}-10-01 00:00:00 Z`).diff(
|
||||
moment(),
|
||||
'days'
|
||||
)
|
||||
const daysToStart = dayjs(`${year}-10-01 00:00:00 Z`).diff(dayjs(), 'days')
|
||||
const isBefore = daysToStart > 0
|
||||
return { daysToStart, isBefore }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import Joi from 'joi'
|
||||
import { age } from '../color-formatters.js'
|
||||
import { formatDate } from '../text-formatters.js'
|
||||
@@ -51,7 +51,7 @@ export default class GithubReleaseDate extends GithubAuthV3Service {
|
||||
static defaultBadgeData = { label: 'release date' }
|
||||
|
||||
static render({ date }) {
|
||||
const releaseDate = moment(date)
|
||||
const releaseDate = dayjs(date)
|
||||
return {
|
||||
message: formatDate(releaseDate),
|
||||
color: age(releaseDate),
|
||||
|
||||
77
services/gitlab/gitlab-forks.service.js
Normal file
77
services/gitlab/gitlab-forks.service.js
Normal file
@@ -0,0 +1,77 @@
|
||||
import Joi from 'joi'
|
||||
import { optionalUrl, nonNegativeInteger } from '../validators.js'
|
||||
import { metric } from '../text-formatters.js'
|
||||
import GitLabBase from './gitlab-base.js'
|
||||
|
||||
const schema = Joi.object({
|
||||
forks_count: nonNegativeInteger,
|
||||
}).required()
|
||||
|
||||
const queryParamSchema = Joi.object({
|
||||
gitlab_url: optionalUrl,
|
||||
}).required()
|
||||
|
||||
const documentation = `
|
||||
<p>
|
||||
You may use your GitLab Project Id (e.g. 278964) or your Project Path (e.g. gitlab-org/gitlab ).
|
||||
Note that only internet-accessible GitLab instances are supported, for example https://jihulab.com, https://gitlab.gnome.org, or https://gitlab.com/.
|
||||
</p>
|
||||
`
|
||||
|
||||
export default class GitlabForks extends GitLabBase {
|
||||
static category = 'social'
|
||||
|
||||
static route = {
|
||||
base: 'gitlab/forks',
|
||||
pattern: ':project+',
|
||||
queryParamSchema,
|
||||
}
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'GitLab forks',
|
||||
namedParams: {
|
||||
project: 'gitlab-org/gitlab',
|
||||
},
|
||||
queryParams: { gitlab_url: 'https://gitlab.com' },
|
||||
staticPreview: {
|
||||
label: 'Fork',
|
||||
message: '6.4k',
|
||||
style: 'social',
|
||||
},
|
||||
documentation,
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'forks', namedLogo: 'gitlab' }
|
||||
|
||||
static render({ baseUrl, project, forkCount }) {
|
||||
return {
|
||||
message: metric(forkCount),
|
||||
color: 'blue',
|
||||
link: [
|
||||
`${baseUrl}/${project}/-/forks/new`,
|
||||
`${baseUrl}/${project}/-/forks`,
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
async fetch({ project, baseUrl }) {
|
||||
// https://docs.gitlab.com/ee/api/projects.html#get-single-project
|
||||
return super.fetch({
|
||||
schema,
|
||||
url: `${baseUrl}/api/v4/projects/${encodeURIComponent(project)}`,
|
||||
errorMessages: {
|
||||
404: 'project not found',
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async handle({ project }, { gitlab_url: baseUrl = 'https://gitlab.com' }) {
|
||||
const { forks_count: forkCount } = await this.fetch({
|
||||
project,
|
||||
baseUrl,
|
||||
})
|
||||
return this.constructor.render({ baseUrl, project, forkCount })
|
||||
}
|
||||
}
|
||||
35
services/gitlab/gitlab-forks.tester.js
Normal file
35
services/gitlab/gitlab-forks.tester.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import { isMetric } from '../test-validators.js'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('Forks')
|
||||
.get('/gitlab-org/gitlab.json')
|
||||
.expectBadge({
|
||||
label: 'forks',
|
||||
message: isMetric,
|
||||
color: 'blue',
|
||||
link: [
|
||||
'https://gitlab.com/gitlab-org/gitlab/-/forks/new',
|
||||
'https://gitlab.com/gitlab-org/gitlab/-/forks',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('Forks (self-managed)')
|
||||
.get('/gitlab-cn/gitlab.json?gitlab_url=https://jihulab.com')
|
||||
.expectBadge({
|
||||
label: 'forks',
|
||||
message: isMetric,
|
||||
color: 'blue',
|
||||
link: [
|
||||
'https://jihulab.com/gitlab-cn/gitlab/-/forks/new',
|
||||
'https://jihulab.com/gitlab-cn/gitlab/-/forks',
|
||||
],
|
||||
})
|
||||
|
||||
t.create('Forks (project not found)')
|
||||
.get('/user1/gitlab-does-not-have-this-repo.json')
|
||||
.expectBadge({
|
||||
label: 'forks',
|
||||
message: 'project not found',
|
||||
})
|
||||
40
services/greasyfork/greasyfork-rating.service.js
Normal file
40
services/greasyfork/greasyfork-rating.service.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { floorCount as floorCountColor } from '../color-formatters.js'
|
||||
import { metric } from '../text-formatters.js'
|
||||
import BaseGreasyForkService from './greasyfork-base.js'
|
||||
|
||||
export default class GreasyForkRatingCount extends BaseGreasyForkService {
|
||||
static category = 'rating'
|
||||
static route = { base: 'greasyfork', pattern: 'rating-count/:scriptId' }
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'Greasy Fork',
|
||||
namedParams: { scriptId: '407466' },
|
||||
staticPreview: this.render({ good: 17, ok: 2, bad: 3 }),
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'rating' }
|
||||
|
||||
static render({ good, ok, bad }) {
|
||||
let color = 'lightgrey'
|
||||
const total = good + bad + ok
|
||||
if (total > 0) {
|
||||
const score = (good * 3 + ok * 2 + bad * 1) / total - 1
|
||||
color = floorCountColor(score, 1, 1.5, 2)
|
||||
}
|
||||
return {
|
||||
message: `${metric(good)} good, ${metric(ok)} ok, ${metric(bad)} bad`,
|
||||
color,
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ scriptId }) {
|
||||
const data = await this.fetch({ scriptId })
|
||||
return this.constructor.render({
|
||||
good: data.good_ratings,
|
||||
ok: data.ok_ratings,
|
||||
bad: data.bad_ratings,
|
||||
})
|
||||
}
|
||||
}
|
||||
31
services/greasyfork/greasyfork-rating.spec.js
Normal file
31
services/greasyfork/greasyfork-rating.spec.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { test, given } from 'sazerac'
|
||||
import GreasyForkRatingCount from './greasyfork-rating.service.js'
|
||||
|
||||
describe('GreasyForkRatingCount', function () {
|
||||
test(GreasyForkRatingCount.render, () => {
|
||||
given({ good: 0, ok: 0, bad: 30 }).expect({
|
||||
message: '0 good, 0 ok, 30 bad',
|
||||
color: 'red',
|
||||
})
|
||||
given({ good: 10, ok: 20, bad: 30 }).expect({
|
||||
message: '10 good, 20 ok, 30 bad',
|
||||
color: 'yellow',
|
||||
})
|
||||
given({ good: 10, ok: 20, bad: 10 }).expect({
|
||||
message: '10 good, 20 ok, 10 bad',
|
||||
color: 'yellowgreen',
|
||||
})
|
||||
given({ good: 20, ok: 10, bad: 0 }).expect({
|
||||
message: '20 good, 10 ok, 0 bad',
|
||||
color: 'green',
|
||||
})
|
||||
given({ good: 30, ok: 0, bad: 0 }).expect({
|
||||
message: '30 good, 0 ok, 0 bad',
|
||||
color: 'brightgreen',
|
||||
})
|
||||
given({ good: 0, ok: 0, bad: 0 }).expect({
|
||||
message: '0 good, 0 ok, 0 bad',
|
||||
color: 'lightgrey',
|
||||
})
|
||||
})
|
||||
})
|
||||
14
services/greasyfork/greasyfork-rating.tester.js
Normal file
14
services/greasyfork/greasyfork-rating.tester.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import Joi from 'joi'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('Rating Count')
|
||||
.get('/rating-count/407466.json')
|
||||
.expectBadge({
|
||||
label: 'rating',
|
||||
message: Joi.string().regex(/^\d+ good, \d+ ok, \d+ bad$/),
|
||||
})
|
||||
|
||||
t.create('Rating Count (not found)')
|
||||
.get('/rating-count/000000.json')
|
||||
.expectBadge({ label: 'rating', message: 'not found' })
|
||||
@@ -1,4 +1,4 @@
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import semver from 'semver'
|
||||
import { getCachedResource } from '../../core/base-service/resource-cache.js'
|
||||
|
||||
@@ -23,7 +23,7 @@ async function getVersion(version) {
|
||||
}
|
||||
|
||||
function ltsVersionsScraper(versions) {
|
||||
const currentDate = moment().format(dateFormat)
|
||||
const currentDate = dayjs().format(dateFormat)
|
||||
return Object.keys(versions).filter(function (version) {
|
||||
const data = versions[version]
|
||||
return data.lts && data.lts < currentDate && data.end > currentDate
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const dateFormat = 'YYYY-MM-DD'
|
||||
|
||||
@@ -67,7 +67,7 @@ const mockVersionsSha = () => nock => {
|
||||
}
|
||||
|
||||
const mockReleaseSchedule = () => nock => {
|
||||
const currentDate = moment()
|
||||
const currentDate = dayjs()
|
||||
const schedule = {
|
||||
'v0.10': {
|
||||
start: '2013-03-11',
|
||||
|
||||
@@ -9,16 +9,11 @@ const schema = Joi.object({
|
||||
license: Joi.string().allow('').allow(null),
|
||||
classifiers: Joi.array().items(Joi.string()).required(),
|
||||
}).required(),
|
||||
releases: Joi.object()
|
||||
.pattern(
|
||||
Joi.string(),
|
||||
Joi.array()
|
||||
.items(
|
||||
Joi.object({
|
||||
packagetype: Joi.string().required(),
|
||||
})
|
||||
)
|
||||
.required()
|
||||
urls: Joi.array()
|
||||
.items(
|
||||
Joi.object({
|
||||
packagetype: Joi.string().required(),
|
||||
})
|
||||
)
|
||||
.required(),
|
||||
}).required()
|
||||
|
||||
@@ -1,45 +1,12 @@
|
||||
import PypiBase from './pypi-base.js'
|
||||
import { sortDjangoVersions, parseClassifiers } from './pypi-helpers.js'
|
||||
import { redirector } from '../index.js'
|
||||
|
||||
export default class PypiDjangoVersions extends PypiBase {
|
||||
static category = 'platform-support'
|
||||
|
||||
static route = this.buildRoute('pypi/djversions')
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'PyPI - Django Version',
|
||||
pattern: ':packageName',
|
||||
namedParams: { packageName: 'djangorestframework' },
|
||||
staticPreview: this.render({ versions: ['1.11', '2.0', '2.1'] }),
|
||||
keywords: ['python'],
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'django versions' }
|
||||
|
||||
static render({ versions }) {
|
||||
if (versions.length > 0) {
|
||||
return {
|
||||
message: sortDjangoVersions(versions).join(' | '),
|
||||
color: 'blue',
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
message: 'missing',
|
||||
color: 'red',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ egg }) {
|
||||
const packageData = await this.fetch({ egg })
|
||||
|
||||
const versions = parseClassifiers(
|
||||
packageData,
|
||||
/^Framework :: Django :: ([\d.]+)$/
|
||||
)
|
||||
|
||||
return this.constructor.render({ versions })
|
||||
}
|
||||
}
|
||||
export default redirector({
|
||||
category: 'platform-support',
|
||||
route: {
|
||||
base: 'pypi/djversions',
|
||||
pattern: ':packageName*',
|
||||
},
|
||||
transformPath: ({ packageName }) =>
|
||||
`/pypi/frameworkversions/django/${packageName}`,
|
||||
dateAdded: new Date('2022-07-28'),
|
||||
})
|
||||
|
||||
@@ -1,32 +1,24 @@
|
||||
import Joi from 'joi'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
export const t = await createServiceTester()
|
||||
|
||||
const isPipeSeparatedDjangoVersions = Joi.string().regex(
|
||||
/^([1-9]\.[0-9]+(?: \| )?)+$/
|
||||
t.create(
|
||||
'redirect supported django versions (valid, package version in request)'
|
||||
)
|
||||
|
||||
t.create('supported django versions (valid, package version in request)')
|
||||
.get('/djangorestframework/3.7.3.json')
|
||||
.expectBadge({
|
||||
label: 'django versions',
|
||||
message: isPipeSeparatedDjangoVersions,
|
||||
})
|
||||
.expectRedirect(
|
||||
'/pypi/frameworkversions/django/djangorestframework/3.7.3.json'
|
||||
)
|
||||
|
||||
t.create('supported django versions (valid, no package version specified)')
|
||||
t.create(
|
||||
'redirect supported django versions (valid, no package version specified)'
|
||||
)
|
||||
.get('/djangorestframework.json')
|
||||
.expectBadge({
|
||||
label: 'django versions',
|
||||
message: isPipeSeparatedDjangoVersions,
|
||||
})
|
||||
.expectRedirect('/pypi/frameworkversions/django/djangorestframework.json')
|
||||
|
||||
t.create('supported django versions (no versions specified)')
|
||||
t.create('redirect supported django versions (no versions specified)')
|
||||
.get('/django/1.11.json')
|
||||
.expectBadge({ label: 'django versions', message: 'missing' })
|
||||
.expectRedirect('/pypi/frameworkversions/django/django/1.11.json')
|
||||
|
||||
t.create('supported django versions (invalid)')
|
||||
t.create('redirect supported django versions (invalid)')
|
||||
.get('/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'django versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
.expectRedirect('/pypi/frameworkversions/django/not-a-package.json')
|
||||
|
||||
103
services/pypi/pypi-framework-versions.service.js
Normal file
103
services/pypi/pypi-framework-versions.service.js
Normal file
@@ -0,0 +1,103 @@
|
||||
import { InvalidResponse } from '../index.js'
|
||||
import PypiBase from './pypi-base.js'
|
||||
import { sortPypiVersions, parseClassifiers } from './pypi-helpers.js'
|
||||
|
||||
const frameworkNameMap = {
|
||||
'aws-cdk': {
|
||||
name: 'AWS CDK',
|
||||
classifier: 'AWS CDK',
|
||||
},
|
||||
django: {
|
||||
name: 'Django',
|
||||
classifier: 'Django',
|
||||
},
|
||||
'django-cms': {
|
||||
name: 'Django CMS',
|
||||
classifier: 'Django CMS',
|
||||
},
|
||||
jupyterlab: {
|
||||
name: 'JupyterLab',
|
||||
classifier: 'Jupyter :: JupyterLab',
|
||||
},
|
||||
odoo: {
|
||||
name: 'Odoo',
|
||||
classifier: 'Odoo',
|
||||
},
|
||||
plone: {
|
||||
name: 'Plone',
|
||||
classifier: 'Plone',
|
||||
},
|
||||
wagtail: {
|
||||
name: 'Wagtail',
|
||||
classifier: 'Wagtail',
|
||||
},
|
||||
zope: {
|
||||
name: 'Zope',
|
||||
classifier: 'Zope',
|
||||
},
|
||||
}
|
||||
|
||||
const documentation = `
|
||||
<p>
|
||||
This service currently support the following Frameworks: <br/>
|
||||
${Object.values(frameworkNameMap).map(obj => `<strong>${obj.name}</strong>`)}
|
||||
</p>
|
||||
`
|
||||
export default class PypiFrameworkVersion extends PypiBase {
|
||||
static category = 'platform-support'
|
||||
|
||||
static route = {
|
||||
base: 'pypi/frameworkversions',
|
||||
pattern: `:frameworkName(${Object.keys(frameworkNameMap).join(
|
||||
'|'
|
||||
)})/:packageName*`,
|
||||
}
|
||||
|
||||
static examples = [
|
||||
{
|
||||
title: 'PyPI - Versions from Framework Classifiers',
|
||||
namedParams: {
|
||||
frameworkName: 'Plone',
|
||||
packageName: 'plone.volto',
|
||||
},
|
||||
staticPreview: this.render({
|
||||
name: 'Plone',
|
||||
versions: ['5.2', '6.0'],
|
||||
}),
|
||||
keywords: ['python'],
|
||||
documentation,
|
||||
},
|
||||
]
|
||||
|
||||
static defaultBadgeData = { label: 'versions' }
|
||||
|
||||
static render({ name, versions }) {
|
||||
name = name ? name.toLowerCase() : ''
|
||||
const label = `${name} versions`
|
||||
return {
|
||||
label,
|
||||
message: sortPypiVersions(versions).join(' | '),
|
||||
color: 'blue',
|
||||
}
|
||||
}
|
||||
|
||||
async handle({ frameworkName, packageName }) {
|
||||
const classifier = frameworkNameMap[frameworkName]
|
||||
? frameworkNameMap[frameworkName].classifier
|
||||
: frameworkName
|
||||
const name = frameworkNameMap[frameworkName]
|
||||
? frameworkNameMap[frameworkName].name
|
||||
: frameworkName
|
||||
const regex = new RegExp(`^Framework :: ${classifier} :: ([\\d.]+)$`)
|
||||
const packageData = await this.fetch({ egg: packageName })
|
||||
const versions = parseClassifiers(packageData, regex)
|
||||
|
||||
if (versions.length === 0) {
|
||||
throw new InvalidResponse({
|
||||
prettyMessage: `${name} versions are missing for ${packageName}`,
|
||||
})
|
||||
}
|
||||
|
||||
return this.constructor.render({ name, versions })
|
||||
}
|
||||
}
|
||||
164
services/pypi/pypi-framework-versions.tester.js
Normal file
164
services/pypi/pypi-framework-versions.tester.js
Normal file
@@ -0,0 +1,164 @@
|
||||
import Joi from 'joi'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
export const t = await createServiceTester()
|
||||
|
||||
const isPipeSeparatedFrameworkVersions = Joi.string().regex(
|
||||
/^([1-9]+(\.[0-9]+)?(?: \| )?)+$/
|
||||
)
|
||||
|
||||
t.create('supported django versions (valid, package version in request)')
|
||||
.get('/django/djangorestframework/3.7.3.json')
|
||||
.expectBadge({
|
||||
label: 'django versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported django versions (valid, no package version specified)')
|
||||
.get('/django/djangorestframework.json')
|
||||
.expectBadge({
|
||||
label: 'django versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported django versions (no versions specified)')
|
||||
.get('/django/django/1.11.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'Django versions are missing for django/1.11',
|
||||
})
|
||||
|
||||
t.create('supported django versions (invalid)')
|
||||
.get('/django/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported plone versions (valid, package version in request)')
|
||||
.get('/plone/plone.rest/1.6.2.json')
|
||||
.expectBadge({ label: 'plone versions', message: '4.3 | 5.0 | 5.1 | 5.2' })
|
||||
|
||||
t.create('supported plone versions (valid, no package version specified)')
|
||||
.get('/plone/plone.rest.json')
|
||||
.expectBadge({
|
||||
label: 'plone versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported plone versions (invalid)')
|
||||
.get('/plone/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported zope versions (valid, package version in request)')
|
||||
.get('/zope/plone/5.2.9.json')
|
||||
.expectBadge({ label: 'zope versions', message: '4' })
|
||||
|
||||
t.create('supported zope versions (valid, no package version specified)')
|
||||
.get('/zope/Plone.json')
|
||||
.expectBadge({
|
||||
label: 'zope versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported zope versions (invalid)')
|
||||
.get('/zope/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported wagtail versions (valid, package version in request)')
|
||||
.get('/wagtail/wagtail-headless-preview/0.3.0.json')
|
||||
.expectBadge({ label: 'wagtail versions', message: '2 | 3' })
|
||||
|
||||
t.create('supported wagtail versions (valid, no package version specified)')
|
||||
.get('/wagtail/wagtail-headless-preview.json')
|
||||
.expectBadge({
|
||||
label: 'wagtail versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported wagtail versions (invalid)')
|
||||
.get('/wagtail/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported django cms versions (valid, package version in request)')
|
||||
.get('/django-cms/djangocms-ads/1.1.0.json')
|
||||
.expectBadge({
|
||||
label: 'django cms versions',
|
||||
message: '3.7 | 3.8 | 3.9 | 3.10',
|
||||
})
|
||||
|
||||
t.create('supported django cms versions (valid, no package version specified)')
|
||||
.get('/django-cms/djangocms-ads.json')
|
||||
.expectBadge({
|
||||
label: 'django cms versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported django cms versions (invalid)')
|
||||
.get('/django-cms/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported odoo versions (valid, package version in request)')
|
||||
.get('/odoo/odoo-addon-sale-tier-validation/15.0.1.0.0.6.json')
|
||||
.expectBadge({ label: 'odoo versions', message: '15.0' })
|
||||
|
||||
t.create('supported odoo versions (valid, no package version specified)')
|
||||
.get('/odoo/odoo-addon-sale-tier-validation.json')
|
||||
.expectBadge({
|
||||
label: 'odoo versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported odoo versions (invalid)')
|
||||
.get('/odoo/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported aws cdk versions (valid, package version in request)')
|
||||
.get('/aws-cdk/aws-cdk.aws-glue-alpha/2.34.0a0.json')
|
||||
.expectBadge({ label: 'aws cdk versions', message: '2' })
|
||||
|
||||
t.create('supported aws cdk versions (valid, no package version specified)')
|
||||
.get('/aws-cdk/aws-cdk.aws-glue-alpha.json')
|
||||
.expectBadge({
|
||||
label: 'aws cdk versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported aws cdk versions (invalid)')
|
||||
.get('/aws-cdk/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
|
||||
t.create('supported jupyterlab versions (valid, package version in request)')
|
||||
.get('/jupyterlab/structured-text/0.0.2.json')
|
||||
.expectBadge({ label: 'jupyterlab versions', message: '3' })
|
||||
|
||||
t.create('supported jupyterlab versions (valid, no package version specified)')
|
||||
.get('/jupyterlab/structured-text.json')
|
||||
.expectBadge({
|
||||
label: 'jupyterlab versions',
|
||||
message: isPipeSeparatedFrameworkVersions,
|
||||
})
|
||||
|
||||
t.create('supported jupyterlab versions (invalid)')
|
||||
.get('/jupyterlab/not-a-package.json')
|
||||
.expectBadge({
|
||||
label: 'versions',
|
||||
message: 'package or version not found',
|
||||
})
|
||||
@@ -6,7 +6,7 @@
|
||||
our own functions to parse and sort django versions
|
||||
*/
|
||||
|
||||
function parseDjangoVersionString(str) {
|
||||
function parsePypiVersionString(str) {
|
||||
if (typeof str !== 'string') {
|
||||
return false
|
||||
}
|
||||
@@ -20,18 +20,12 @@ function parseDjangoVersionString(str) {
|
||||
}
|
||||
|
||||
// Sort an array of django versions low to high.
|
||||
function sortDjangoVersions(versions) {
|
||||
function sortPypiVersions(versions) {
|
||||
return versions.sort((a, b) => {
|
||||
if (
|
||||
parseDjangoVersionString(a).major === parseDjangoVersionString(b).major
|
||||
) {
|
||||
return (
|
||||
parseDjangoVersionString(a).minor - parseDjangoVersionString(b).minor
|
||||
)
|
||||
if (parsePypiVersionString(a).major === parsePypiVersionString(b).major) {
|
||||
return parsePypiVersionString(a).minor - parsePypiVersionString(b).minor
|
||||
} else {
|
||||
return (
|
||||
parseDjangoVersionString(a).major - parseDjangoVersionString(b).major
|
||||
)
|
||||
return parsePypiVersionString(a).major - parsePypiVersionString(b).major
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -88,16 +82,12 @@ function getLicenses(packageData) {
|
||||
}
|
||||
|
||||
function getPackageFormats(packageData) {
|
||||
const {
|
||||
info: { version },
|
||||
releases,
|
||||
} = packageData
|
||||
const releasesForVersion = releases[version]
|
||||
const { urls } = packageData
|
||||
return {
|
||||
hasWheel: releasesForVersion.some(({ packagetype }) =>
|
||||
hasWheel: urls.some(({ packagetype }) =>
|
||||
['wheel', 'bdist_wheel'].includes(packagetype)
|
||||
),
|
||||
hasEgg: releasesForVersion.some(({ packagetype }) =>
|
||||
hasEgg: urls.some(({ packagetype }) =>
|
||||
['egg', 'bdist_egg'].includes(packagetype)
|
||||
),
|
||||
}
|
||||
@@ -105,8 +95,8 @@ function getPackageFormats(packageData) {
|
||||
|
||||
export {
|
||||
parseClassifiers,
|
||||
parseDjangoVersionString,
|
||||
sortDjangoVersions,
|
||||
parsePypiVersionString,
|
||||
sortPypiVersions,
|
||||
getLicenses,
|
||||
getPackageFormats,
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { test, given, forCases } from 'sazerac'
|
||||
import {
|
||||
parseClassifiers,
|
||||
parseDjangoVersionString,
|
||||
sortDjangoVersions,
|
||||
parsePypiVersionString,
|
||||
sortPypiVersions,
|
||||
getLicenses,
|
||||
getPackageFormats,
|
||||
} from './pypi-helpers.js'
|
||||
@@ -60,7 +60,7 @@ describe('PyPI helpers', function () {
|
||||
given(classifiersFixture, /^(?!.*)*$/).expect([])
|
||||
})
|
||||
|
||||
test(parseDjangoVersionString, function () {
|
||||
test(parsePypiVersionString, function () {
|
||||
given('1').expect({ major: 1, minor: 0 })
|
||||
given('1.0').expect({ major: 1, minor: 0 })
|
||||
given('7.2').expect({ major: 7, minor: 2 })
|
||||
@@ -69,7 +69,7 @@ describe('PyPI helpers', function () {
|
||||
given('foo').expect({ major: 0, minor: 0 })
|
||||
})
|
||||
|
||||
test(sortDjangoVersions, function () {
|
||||
test(sortPypiVersions, function () {
|
||||
// Each of these includes a different variant: 2.0, 2, and 2.0rc1.
|
||||
given(['2.0', '1.9', '10', '1.11', '2.1', '2.11']).expect([
|
||||
'1.9',
|
||||
@@ -164,34 +164,17 @@ describe('PyPI helpers', function () {
|
||||
|
||||
test(getPackageFormats, () => {
|
||||
given({
|
||||
info: { version: '2.19.1' },
|
||||
releases: {
|
||||
'1.0.4': [{ packagetype: 'sdist' }],
|
||||
'2.19.1': [{ packagetype: 'bdist_wheel' }, { packagetype: 'sdist' }],
|
||||
},
|
||||
urls: [{ packagetype: 'bdist_wheel' }, { packagetype: 'sdist' }],
|
||||
}).expect({ hasWheel: true, hasEgg: false })
|
||||
given({
|
||||
info: { version: '1.0.4' },
|
||||
releases: {
|
||||
'1.0.4': [{ packagetype: 'sdist' }],
|
||||
'2.19.1': [{ packagetype: 'bdist_wheel' }, { packagetype: 'sdist' }],
|
||||
},
|
||||
urls: [{ packagetype: 'sdist' }],
|
||||
}).expect({ hasWheel: false, hasEgg: false })
|
||||
given({
|
||||
info: { version: '0.8.2' },
|
||||
releases: {
|
||||
0.8: [{ packagetype: 'sdist' }],
|
||||
'0.8.1': [
|
||||
{ packagetype: 'bdist_egg' },
|
||||
{ packagetype: 'bdist_egg' },
|
||||
{ packagetype: 'sdist' },
|
||||
],
|
||||
'0.8.2': [
|
||||
{ packagetype: 'bdist_egg' },
|
||||
{ packagetype: 'bdist_egg' },
|
||||
{ packagetype: 'sdist' },
|
||||
],
|
||||
},
|
||||
urls: [
|
||||
{ packagetype: 'bdist_egg' },
|
||||
{ packagetype: 'bdist_egg' },
|
||||
{ packagetype: 'sdist' },
|
||||
],
|
||||
}).expect({ hasWheel: false, hasEgg: true })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@ t.create('license (from trove classifier)')
|
||||
license: '',
|
||||
classifiers: ['License :: OSI Approved :: MIT License'],
|
||||
},
|
||||
releases: {},
|
||||
urls: [],
|
||||
})
|
||||
)
|
||||
.expectBadge({
|
||||
@@ -46,7 +46,7 @@ t.create('license (as acronym from trove classifier)')
|
||||
'License :: OSI Approved :: GNU General Public License (GPL)',
|
||||
],
|
||||
},
|
||||
releases: {},
|
||||
urls: [],
|
||||
})
|
||||
)
|
||||
.expectBadge({
|
||||
|
||||
@@ -43,7 +43,7 @@ t.create('no trove classifiers')
|
||||
license: 'foo',
|
||||
classifiers: [],
|
||||
},
|
||||
releases: {},
|
||||
urls: [],
|
||||
})
|
||||
)
|
||||
.expectBadge({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Joi from 'joi'
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import { renderDownloadsBadge } from '../downloads.js'
|
||||
import { nonNegativeInteger } from '../validators.js'
|
||||
import { BaseJsonService } from '../index.js'
|
||||
@@ -15,15 +15,15 @@ const intervalMap = {
|
||||
},
|
||||
dw: {
|
||||
// 6 days, since date range is inclusive,
|
||||
startDate: endDate => moment(endDate).subtract(6, 'days'),
|
||||
startDate: endDate => dayjs(endDate).subtract(6, 'days'),
|
||||
interval: 'week',
|
||||
},
|
||||
dm: {
|
||||
startDate: endDate => moment(endDate).subtract(30, 'days'),
|
||||
startDate: endDate => dayjs(endDate).subtract(30, 'days'),
|
||||
interval: 'month',
|
||||
},
|
||||
dt: {
|
||||
startDate: () => moment(0),
|
||||
startDate: () => dayjs(0),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ export default class Sourceforge extends BaseJsonService {
|
||||
folder ? `${folder}/` : ''
|
||||
}stats/json`
|
||||
// get yesterday since today is incomplete
|
||||
const endDate = moment().subtract(24, 'hours')
|
||||
const endDate = dayjs().subtract(24, 'hours')
|
||||
const startDate = intervalMap[interval].startDate(endDate)
|
||||
const options = {
|
||||
searchParams: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import Joi from 'joi'
|
||||
import { nonNegativeInteger } from '../validators.js'
|
||||
import { BaseJsonService } from '../index.js'
|
||||
@@ -19,10 +19,10 @@ export default class StackExchangeMonthlyQuestions extends BaseJsonService {
|
||||
static examples = [
|
||||
{
|
||||
title: 'Stack Exchange monthly questions',
|
||||
namedParams: { stackexchangesite: 'stackoverflow', query: 'momentjs' },
|
||||
namedParams: { stackexchangesite: 'stackoverflow', query: 'dayjs' },
|
||||
staticPreview: this.render({
|
||||
stackexchangesite: 'stackoverflow',
|
||||
query: 'momentjs',
|
||||
query: 'dayjs',
|
||||
numValue: 2000,
|
||||
}),
|
||||
keywords: ['stackexchange', 'stackoverflow'],
|
||||
@@ -41,12 +41,12 @@ export default class StackExchangeMonthlyQuestions extends BaseJsonService {
|
||||
}
|
||||
|
||||
async handle({ stackexchangesite, query }) {
|
||||
const today = moment().toDate()
|
||||
const prevMonthStart = moment(today)
|
||||
const today = dayjs().toDate()
|
||||
const prevMonthStart = dayjs(today)
|
||||
.subtract(1, 'months')
|
||||
.startOf('month')
|
||||
.unix()
|
||||
const prevMonthEnd = moment(today)
|
||||
const prevMonthEnd = dayjs(today)
|
||||
.subtract(1, 'months')
|
||||
.endOf('month')
|
||||
.unix()
|
||||
|
||||
@@ -2,10 +2,10 @@ import { isMetricOverTimePeriod } from '../test-validators.js'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('Monthly Questions for StackOverflow Momentjs')
|
||||
.get('/stackoverflow/qm/momentjs.json')
|
||||
t.create('Monthly Questions for StackOverflow dayjs')
|
||||
.get('/stackoverflow/qm/dayjs.json')
|
||||
.expectBadge({
|
||||
label: 'stackoverflow momentjs questions',
|
||||
label: 'stackoverflow dayjs questions',
|
||||
message: isMetricOverTimePeriod,
|
||||
})
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
* Commonly-used functions for formatting text in badge labels. Includes
|
||||
* ordinal numbers, currency codes, star ratings, versions, etc.
|
||||
*/
|
||||
import moment from 'moment'
|
||||
moment().format()
|
||||
import dayjs from 'dayjs'
|
||||
import calendar from 'dayjs/plugin/calendar.js'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime.js'
|
||||
dayjs.extend(calendar)
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
function starRating(rating, max = 5) {
|
||||
const flooredRating = Math.floor(rating)
|
||||
@@ -109,7 +112,7 @@ function maybePluralize(singular, countable, plural) {
|
||||
}
|
||||
|
||||
function formatDate(d) {
|
||||
const date = moment(d)
|
||||
const date = dayjs(d)
|
||||
const dateString = date.calendar(null, {
|
||||
lastDay: '[yesterday]',
|
||||
sameDay: '[today]',
|
||||
@@ -117,12 +120,12 @@ function formatDate(d) {
|
||||
sameElse: 'MMMM YYYY',
|
||||
})
|
||||
// Trim current year from date string
|
||||
return dateString.replace(` ${moment().year()}`, '').toLowerCase()
|
||||
return dateString.replace(` ${dayjs().year()}`, '').toLowerCase()
|
||||
}
|
||||
|
||||
function formatRelativeDate(timestamp) {
|
||||
return moment()
|
||||
.to(moment.unix(parseInt(timestamp, 10)))
|
||||
return dayjs()
|
||||
.to(dayjs.unix(parseInt(timestamp, 10)))
|
||||
.toLowerCase()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import moment from 'moment'
|
||||
import dayjs from 'dayjs'
|
||||
import customParseFormat from 'dayjs/plugin/customParseFormat.js'
|
||||
import { InvalidResponse } from '../index.js'
|
||||
import { formatDate } from '../text-formatters.js'
|
||||
import { age as ageColor } from '../color-formatters.js'
|
||||
import { documentation, BaseWordpress } from './wordpress-base.js'
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
const extensionData = {
|
||||
plugin: {
|
||||
capt: 'Plugin',
|
||||
exampleSlug: 'bbpress',
|
||||
lastUpdateFormat: 'YYYY-MM-DD hh:mma GMT',
|
||||
lastUpdateFormat: 'YYYY-MM-DD hh:mma [GMT]',
|
||||
},
|
||||
theme: {
|
||||
capt: 'Theme',
|
||||
@@ -50,7 +52,7 @@ function LastUpdateForType(extensionType) {
|
||||
}
|
||||
|
||||
transform(lastUpdate) {
|
||||
const date = moment(lastUpdate, lastUpdateFormat)
|
||||
const date = dayjs(lastUpdate, lastUpdateFormat)
|
||||
|
||||
if (date.isValid()) {
|
||||
return date.format('YYYY-MM-DD')
|
||||
|
||||
Reference in New Issue
Block a user