Remove no download handling and add API warning to [Wordpress] badges (#7606)

This commit is contained in:
Pierre-Yves Bigourdan
2022-02-13 16:17:03 +00:00
committed by GitHub
parent 567e284ffb
commit a1885cdd37
7 changed files with 24 additions and 72 deletions

View File

@@ -41,7 +41,7 @@ const notFoundSchema = Joi.object()
const pluginSchemas = Joi.alternatives(pluginSchema, notFoundSchema)
const themeSchemas = Joi.alternatives(themeSchema, notFoundSchema)
export default class BaseWordpress extends BaseJsonService {
export class BaseWordpress extends BaseJsonService {
async fetch({ extensionType, slug }) {
const url = `https://api.wordpress.org/${extensionType}s/info/1.2/`
let schemas
@@ -84,3 +84,12 @@ export default class BaseWordpress extends BaseJsonService {
return json
}
}
export const documentation = `
<p>
These badges rely on an API that is no longer supported by Wordpress. You are
still free to use them, simply bear in mind that Shields.io cannot guarantee
that they'll keep on working in the future. Please also double-check the
provided slug, as an incorrect value may lead to unexpected results.
</p>
`

View File

@@ -1,7 +1,6 @@
import Joi from 'joi'
import { renderDownloadsBadge } from '../downloads.js'
import { NotFound } from '../index.js'
import BaseWordpress from './wordpress-base.js'
import { documentation, BaseWordpress } from './wordpress-base.js'
const dateSchema = Joi.object()
.pattern(Joi.date().iso(), Joi.number().integer())
@@ -58,6 +57,7 @@ function DownloadsForExtensionType(extensionType) {
title: `WordPress ${capt} Downloads`,
namedParams: { interval: 'dm', slug: exampleSlug },
staticPreview: this.render({ interval: 'dm', downloads: 200000 }),
documentation,
},
]
@@ -91,17 +91,9 @@ function DownloadsForExtensionType(extensionType) {
},
},
})
const size = Object.keys(json).length
downloads = Object.values(json).reduce(
(a, b) => parseInt(a) + parseInt(b)
)
// This check is for non-existent and brand-new plugins both having new stats.
// Non-Existent plugins results are the same as a brandspanking new plugin with no downloads.
if (downloads <= 0 && size <= 1) {
throw new NotFound({
prettyMessage: `${extensionType} not found or too new`,
})
}
}
return this.constructor.render({ interval, downloads })
@@ -127,6 +119,7 @@ function InstallsForExtensionType(extensionType) {
title: `WordPress ${capt} Active Installs`,
namedParams: { slug: exampleSlug },
staticPreview: renderDownloadsBadge({ downloads: 300000 }),
documentation,
},
]

View File

@@ -98,34 +98,6 @@ t.create('Plugin Downloads - Active | Not Found')
message: 'not found',
})
t.create('Plugin Downloads - Day | Not Found')
.get('/plugin/dd/100.json')
.expectBadge({
label: 'downloads',
message: 'plugin not found or too new',
})
t.create('Plugin Downloads - Week | Not Found')
.get('/plugin/dw/100.json')
.expectBadge({
label: 'downloads',
message: 'plugin not found or too new',
})
t.create('Plugin Downloads - Month | Not Found')
.get('/plugin/dm/100.json')
.expectBadge({
label: 'downloads',
message: 'plugin not found or too new',
})
t.create('Plugin Downloads - Year | Not Found')
.get('/plugin/dy/100.json')
.expectBadge({
label: 'downloads',
message: 'plugin not found or too new',
})
t.create('Theme Downloads - Total | Not Found')
.get('/theme/dt/100.json')
.expectBadge({
@@ -139,31 +111,3 @@ t.create('Theme Downloads - Active | Not Found')
label: 'active installs',
message: 'not found',
})
t.create('Theme Downloads - Day | Not Found')
.get('/theme/dd/100.json')
.expectBadge({
label: 'downloads',
message: 'theme not found or too new',
})
t.create('Theme Downloads - Week | Not Found')
.get('/theme/dw/100.json')
.expectBadge({
label: 'downloads',
message: 'theme not found or too new',
})
t.create('Theme Downloads - Month | Not Found')
.get('/theme/dm/100.json')
.expectBadge({
label: 'downloads',
message: 'theme not found or too new',
})
t.create('Theme Downloads - Year | Not Found')
.get('/theme/dy/100.json')
.expectBadge({
label: 'downloads',
message: 'theme not found or too new',
})

View File

@@ -2,7 +2,7 @@ import moment from 'moment'
import { InvalidResponse } from '../index.js'
import { formatDate } from '../text-formatters.js'
import { age as ageColor } from '../color-formatters.js'
import BaseWordpress from './wordpress-base.js'
import { documentation, BaseWordpress } from './wordpress-base.js'
const extensionData = {
plugin: {
@@ -35,6 +35,7 @@ function LastUpdateForType(extensionType) {
title: `WordPress ${capt} Last Updated`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ lastUpdated: '2020-08-11' }),
documentation,
},
]

View File

@@ -1,7 +1,7 @@
import { NotFound } from '../index.js'
import { addv } from '../text-formatters.js'
import { version as versionColor } from '../color-formatters.js'
import BaseWordpress from './wordpress-base.js'
import { documentation, BaseWordpress } from './wordpress-base.js'
import { versionColorForWordpressVersion } from './wordpress-version-color.js'
const extensionData = {
@@ -33,6 +33,7 @@ function WordpressRequiresVersion(extensionType) {
title: `WordPress ${capt}: Required WP Version`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ wordpressVersion: '4.8' }),
documentation,
},
]
@@ -77,6 +78,7 @@ class WordpressPluginTestedVersion extends BaseWordpress {
staticPreview: this.renderStaticPreview({
testedVersion: '4.9.8',
}),
documentation,
},
]
@@ -128,6 +130,7 @@ function RequiresPHPVersionForType(extensionType) {
title: `WordPress ${capt} Required PHP Version`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ version: '5.5' }),
documentation,
},
]

View File

@@ -1,6 +1,6 @@
import { starRating, metric } from '../text-formatters.js'
import { floorCount } from '../color-formatters.js'
import BaseWordpress from './wordpress-base.js'
import { documentation, BaseWordpress } from './wordpress-base.js'
const extensionData = {
plugin: {
@@ -38,6 +38,7 @@ function RatingForExtensionType(extensionType) {
rating: 80,
numRatings: 100,
}),
documentation,
},
]
@@ -78,7 +79,7 @@ function StarsForExtensionType(extensionType) {
staticPreview: this.render({
rating: 80,
}),
documentation: 'There is an alias <code>/r/:slug.svg</code> as well.',
documentation,
},
]

View File

@@ -1,6 +1,6 @@
import { addv } from '../text-formatters.js'
import { version as versionColor } from '../color-formatters.js'
import BaseWordpress from './wordpress-base.js'
import { documentation, BaseWordpress } from './wordpress-base.js'
function VersionForExtensionType(extensionType) {
const { capt, exampleSlug } = {
@@ -29,6 +29,7 @@ function VersionForExtensionType(extensionType) {
title: `WordPress ${capt} Version`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ version: 2.5 }),
documentation,
},
]