From d4ce24b1068e888c23582eedd1788b189d752109 Mon Sep 17 00:00:00 2001 From: chris48s Date: Sat, 3 Jul 2021 20:59:32 +0100 Subject: [PATCH] deprecate [microbadger] (#6709) Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> --- services/microbadger/microbadger-base.js | 53 ------------- .../microbadger/microbadger-layers.service.js | 42 ----------- .../microbadger/microbadger-layers.tester.js | 41 ---------- .../microbadger/microbadger-size.service.js | 74 ------------------- .../microbadger/microbadger-size.tester.js | 53 ------------- services/microbadger/microbadger.service.js | 13 ++++ services/microbadger/microbadger.tester.js | 35 +++++++++ 7 files changed, 48 insertions(+), 263 deletions(-) delete mode 100644 services/microbadger/microbadger-base.js delete mode 100644 services/microbadger/microbadger-layers.service.js delete mode 100644 services/microbadger/microbadger-layers.tester.js delete mode 100644 services/microbadger/microbadger-size.service.js delete mode 100644 services/microbadger/microbadger-size.tester.js create mode 100644 services/microbadger/microbadger.service.js create mode 100644 services/microbadger/microbadger.tester.js diff --git a/services/microbadger/microbadger-base.js b/services/microbadger/microbadger-base.js deleted file mode 100644 index 81b98f4b9f8cd..0000000000000 --- a/services/microbadger/microbadger-base.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict' - -const Joi = require('joi') -const { nonNegativeInteger } = require('../validators') -const { BaseJsonService, NotFound } = require('..') - -const schema = Joi.object({ - LayerCount: nonNegativeInteger, - // DownloadSize may be missing in some cases - DownloadSize: Joi.number().integer().min(0), - Versions: Joi.array() - .items( - Joi.object({ - Tags: Joi.array() - .items( - Joi.object({ - tag: Joi.string().required(), - }) - ) - .required(), - LayerCount: nonNegativeInteger, - DownloadSize: Joi.number().integer().min(0), - }) - ) - .required(), -}).required() - -module.exports = class BaseMicrobadgerService extends BaseJsonService { - static category = 'size' - - async fetch({ user, repo }) { - if (user === '_') { - user = 'library' - } - return this._requestJson({ - schema, - url: `https://api.microbadger.com/v1/images/${user}/${repo}`, - }) - } - - static getImage(response, tag) { - if (!tag) { - return response - } - const image = - response.Versions && - response.Versions.find(v => v.Tags.some(t => t.tag === tag)) - if (!image) { - throw new NotFound() - } - return image - } -} diff --git a/services/microbadger/microbadger-layers.service.js b/services/microbadger/microbadger-layers.service.js deleted file mode 100644 index 46e45ff36ed60..0000000000000 --- a/services/microbadger/microbadger-layers.service.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict' - -const BaseMicrobadgerService = require('./microbadger-base') - -module.exports = class MicrobadgerLayers extends BaseMicrobadgerService { - static route = { - base: 'microbadger/layers', - pattern: ':user/:repo/:tag*', - } - - static examples = [ - { - title: 'MicroBadger Layers', - pattern: ':user/:repo', - namedParams: { user: '_', repo: 'alpine' }, - staticPreview: this.render({ layers: 15 }), - keywords: ['docker'], - }, - { - title: 'MicroBadger Layers (tag)', - pattern: ':user/:repo/:tag', - namedParams: { user: '_', repo: 'alpine', tag: '2.7' }, - staticPreview: this.render({ layers: 12 }), - keywords: ['docker'], - }, - ] - - static defaultBadgeData = { label: 'layers' } - - static render({ layers }) { - return { - message: layers, - color: 'blue', - } - } - - async handle({ user, repo, tag }) { - const data = await this.fetch({ user, repo }) - const image = this.constructor.getImage(data, tag) - return this.constructor.render({ layers: image.LayerCount }) - } -} diff --git a/services/microbadger/microbadger-layers.tester.js b/services/microbadger/microbadger-layers.tester.js deleted file mode 100644 index d2fd1a828babb..0000000000000 --- a/services/microbadger/microbadger-layers.tester.js +++ /dev/null @@ -1,41 +0,0 @@ -'use strict' - -const { nonNegativeInteger } = require('../validators') -const t = (module.exports = require('../tester').createServiceTester()) - -t.create('layers without a specified tag') - .get('/_/alpine.json') - .timeout(150000) - .expectBadge({ - label: 'layers', - message: nonNegativeInteger, - }) - -t.create('layers with a specified tag') - .get('/_/alpine/2.7.json') - .timeout(150000) - .expectBadge({ - label: 'layers', - message: nonNegativeInteger, - }) - -t.create('specified tag when repository has only one') - .get('/_/alpine/wrong-tag.json') - .expectBadge({ label: 'layers', message: 'not found' }) - -t.create('nonexistent repository') - .get('/_/not-a-real-repo.json') - .expectBadge({ label: 'layers', message: 'not found' }) - -t.create('nonexistent tag') - .get('/_/unknown/wrong-tag.json') - .intercept(nock => - nock('https://api.microbadger.com') - .get('/v1/images/library/unknown') - .reply(200, { - LayerCount: 1, - DownloadSize: 1, - Versions: [], - }) - ) - .expectBadge({ label: 'layers', message: 'not found' }) diff --git a/services/microbadger/microbadger-size.service.js b/services/microbadger/microbadger-size.service.js deleted file mode 100644 index afeb7efe281dd..0000000000000 --- a/services/microbadger/microbadger-size.service.js +++ /dev/null @@ -1,74 +0,0 @@ -'use strict' - -const prettyBytes = require('pretty-bytes') -const { NotFound } = require('..') -const BaseMicrobadgerService = require('./microbadger-base') - -const documentation = ` -

- The MicroBadger API can sometimes be a bit temperamental when it comes to retrieving the size of your image. - If the website indicates "Layer information not yet retrieved" for your image, Shields.io will display the size as unknown in its badge. - In some cases, the size is also reported as 0. -

-

- To speed things up on the MicroBadger side of things, you may want to hit their webhook manually. - Simply go to your image's page on the MicroBadger website, click "Get the webhook" and follow the instructions listed there. - Please be patient, it may still take several minutes for the information to be made available to Shields.io! -

-

- Feel free to open an issue if you're still facing issues, but you may want to have a glance at some of these beforehand: -

-

-` - -module.exports = class MicrobadgerSize extends BaseMicrobadgerService { - static route = { - base: 'microbadger/image-size', - pattern: ':user/:repo/:tag*', - } - - static examples = [ - { - title: 'MicroBadger Size', - pattern: ':user/:repo', - namedParams: { user: 'fedora', repo: 'apache' }, - staticPreview: this.render({ size: 126000000 }), - keywords: ['docker'], - documentation, - }, - { - title: 'MicroBadger Size (tag)', - pattern: ':user/:repo/:tag', - namedParams: { user: 'fedora', repo: 'apache', tag: 'latest' }, - staticPreview: this.render({ size: 103000000 }), - keywords: ['docker'], - documentation, - }, - ] - - static defaultBadgeData = { - label: 'image size', - } - - static render({ size }) { - return { - message: prettyBytes(parseInt(size)), - color: 'blue', - } - } - - async handle({ user, repo, tag }) { - const data = await this.fetch({ user, repo }) - const image = this.constructor.getImage(data, tag) - if (image.DownloadSize === undefined) { - throw new NotFound({ prettyMessage: 'unknown' }) - } - return this.constructor.render({ size: image.DownloadSize }) - } -} diff --git a/services/microbadger/microbadger-size.tester.js b/services/microbadger/microbadger-size.tester.js deleted file mode 100644 index 4e6613e6e7f0f..0000000000000 --- a/services/microbadger/microbadger-size.tester.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict' - -const { isFileSize } = require('../test-validators') -const t = (module.exports = require('../tester').createServiceTester()) - -t.create('image size without a specified tag') - .get('/fedora/apache.json') - .timeout(150000) - .expectBadge({ - label: 'image size', - message: isFileSize, - }) - -t.create('image size with a specified tag') - .get('/fedora/apache/latest.json') - .timeout(150000) - .expectBadge({ - label: 'image size', - message: isFileSize, - }) - -t.create('missing download size') - .get('/puppet/puppetserver.json') - .intercept(nock => - nock('https://api.microbadger.com') - .get('/v1/images/puppet/puppetserver') - .reply(200, { - LayerCount: 1, - Versions: [], - }) - ) - .expectBadge({ label: 'image size', message: 'unknown' }) - -t.create('specified tag when repository has only one') - .get('/_/alpine/wrong-tag.json') - .expectBadge({ label: 'image size', message: 'not found' }) - -t.create('nonexistent repository') - .get('/_/not-a-real-repo.json') - .expectBadge({ label: 'image size', message: 'not found' }) - -t.create('nonexistent tag') - .get('/_/unknown/wrong-tag.json') - .intercept(nock => - nock('https://api.microbadger.com') - .get('/v1/images/library/unknown') - .reply(200, { - LayerCount: 1, - DownloadSize: 1, - Versions: [], - }) - ) - .expectBadge({ label: 'image size', message: 'not found' }) diff --git a/services/microbadger/microbadger.service.js b/services/microbadger/microbadger.service.js new file mode 100644 index 0000000000000..ba9196d9fd37e --- /dev/null +++ b/services/microbadger/microbadger.service.js @@ -0,0 +1,13 @@ +'use strict' + +const { deprecatedService } = require('..') + +module.exports = deprecatedService({ + category: 'build', + route: { + base: 'microbadger', + pattern: ':various+', + }, + label: 'microbadger', + dateAdded: new Date('2021-07-03'), +}) diff --git a/services/microbadger/microbadger.tester.js b/services/microbadger/microbadger.tester.js new file mode 100644 index 0000000000000..12842da39d2d5 --- /dev/null +++ b/services/microbadger/microbadger.tester.js @@ -0,0 +1,35 @@ +'use strict' + +const { ServiceTester } = require('../tester') +const t = (module.exports = new ServiceTester({ + id: 'microbadger', + title: 'Microbadger', +})) + +t.create('no longer available (previously image size)') + .get('/image-size/fedora/apache.json') + .expectBadge({ + label: 'microbadger', + message: 'no longer available', + }) + +t.create('no longer available (previously image size with tag)') + .get('/image-size/fedora/apache/latest.json') + .expectBadge({ + label: 'microbadger', + message: 'no longer available', + }) + +t.create('no longer available (previously layers)') + .get('/layers/fedora/apache.json') + .expectBadge({ + label: 'microbadger', + message: 'no longer available', + }) + +t.create('no longer available (previously layers with tag)') + .get('/layers/fedora/apache/latest.json') + .expectBadge({ + label: 'microbadger', + message: 'no longer available', + })