Files
shields/services/microbadger/microbadger-base.js
dependabot-preview[bot] 294aa1e1df Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0; autofixes (#3671)
* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0

Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0.
- [Release notes](https://github.com/benmosher/eslint-plugin-import/releases)
- [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Autofixes
2019-07-08 12:13:46 -04:00

60 lines
1.3 KiB
JavaScript

'use strict'
const Joi = require('@hapi/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 get category() {
return '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
}
}