Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion services/wordpress/wordpress-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
`
13 changes: 3 additions & 10 deletions services/wordpress/wordpress-downloads.service.js
Original file line number Diff line number Diff line change
@@ -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())
Expand Down Expand Up @@ -58,6 +57,7 @@ function DownloadsForExtensionType(extensionType) {
title: `WordPress ${capt} Downloads`,
namedParams: { interval: 'dm', slug: exampleSlug },
staticPreview: this.render({ interval: 'dm', downloads: 200000 }),
documentation,
},
]

Expand Down Expand Up @@ -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 })
Expand All @@ -127,6 +119,7 @@ function InstallsForExtensionType(extensionType) {
title: `WordPress ${capt} Active Installs`,
namedParams: { slug: exampleSlug },
staticPreview: renderDownloadsBadge({ downloads: 300000 }),
documentation,
},
]

Expand Down
56 changes: 0 additions & 56 deletions services/wordpress/wordpress-downloads.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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',
})
3 changes: 2 additions & 1 deletion services/wordpress/wordpress-last-update.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -35,6 +35,7 @@ function LastUpdateForType(extensionType) {
title: `WordPress ${capt} Last Updated`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ lastUpdated: '2020-08-11' }),
documentation,
},
]

Expand Down
5 changes: 4 additions & 1 deletion services/wordpress/wordpress-platform.service.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -33,6 +33,7 @@ function WordpressRequiresVersion(extensionType) {
title: `WordPress ${capt}: Required WP Version`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ wordpressVersion: '4.8' }),
documentation,
},
]

Expand Down Expand Up @@ -77,6 +78,7 @@ class WordpressPluginTestedVersion extends BaseWordpress {
staticPreview: this.renderStaticPreview({
testedVersion: '4.9.8',
}),
documentation,
},
]

Expand Down Expand Up @@ -128,6 +130,7 @@ function RequiresPHPVersionForType(extensionType) {
title: `WordPress ${capt} Required PHP Version`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ version: '5.5' }),
documentation,
},
]

Expand Down
5 changes: 3 additions & 2 deletions services/wordpress/wordpress-rating.service.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -38,6 +38,7 @@ function RatingForExtensionType(extensionType) {
rating: 80,
numRatings: 100,
}),
documentation,
},
]

Expand Down Expand Up @@ -78,7 +79,7 @@ function StarsForExtensionType(extensionType) {
staticPreview: this.render({
rating: 80,
}),
documentation: 'There is an alias <code>/r/:slug.svg</code> as well.',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not consistent with our usage of the /r/ abbreviation in the rating category, I chose to stop advertising it in the docs.

documentation,
},
]

Expand Down
3 changes: 2 additions & 1 deletion services/wordpress/wordpress-version.service.js
Original file line number Diff line number Diff line change
@@ -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 } = {
Expand Down Expand Up @@ -29,6 +29,7 @@ function VersionForExtensionType(extensionType) {
title: `WordPress ${capt} Version`,
namedParams: { slug: exampleSlug },
staticPreview: this.render({ version: 2.5 }),
documentation,
},
]

Expand Down