Close #2334 To avoid merge conflicts, I've deferred removing the aliasing logic in `prepareExamples`. That whole function will be refactored momentarily, and there's also #2339 open.
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
const BaseJsonService = require('../base-json')
|
|
const { metric } = require('../../lib/text-formatters')
|
|
const { nonNegativeInteger } = require('../validators')
|
|
const {
|
|
dockerBlue,
|
|
buildDockerUrl,
|
|
getDockerHubUser,
|
|
} = require('./docker-helpers')
|
|
|
|
const pullsSchema = Joi.object({
|
|
pull_count: nonNegativeInteger,
|
|
}).required()
|
|
|
|
module.exports = class DockerPulls extends BaseJsonService {
|
|
async fetch({ user, repo }) {
|
|
return this._requestJson({
|
|
schema: pullsSchema,
|
|
url: `https://hub.docker.com/v2/repositories/${getDockerHubUser(
|
|
user
|
|
)}/${repo}`,
|
|
errorMessages: { 404: 'repo not found' },
|
|
})
|
|
}
|
|
|
|
static render({ count }) {
|
|
return {
|
|
message: metric(count),
|
|
color: dockerBlue,
|
|
}
|
|
}
|
|
|
|
async handle({ user, repo }) {
|
|
const data = await this.fetch({ user, repo })
|
|
return this.constructor.render({ count: data.pull_count })
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return { label: 'docker pulls' }
|
|
}
|
|
|
|
static get category() {
|
|
return 'downloads'
|
|
}
|
|
|
|
static get route() {
|
|
return buildDockerUrl('pulls')
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Docker Pulls',
|
|
exampleUrl: '_/ubuntu',
|
|
keywords: ['docker', 'pulls'],
|
|
pattern: ':user/:repo',
|
|
staticExample: this.render({ count: 765400000 }),
|
|
},
|
|
]
|
|
}
|
|
}
|