Files
shields/services/docker/docker-automated.service.js
Paul Melnikow 226fa67a02 Create shortcut for BaseService-related imports (#2809)
Continue to implement #2698:

- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
2019-01-21 15:41:24 -05:00

64 lines
1.4 KiB
JavaScript

'use strict'
const Joi = require('joi')
const { BaseJsonService } = require('..')
const {
dockerBlue,
buildDockerUrl,
getDockerHubUser,
} = require('./docker-helpers')
const automatedBuildSchema = Joi.object({
is_automated: Joi.boolean().required(),
}).required()
module.exports = class DockerAutomatedBuild extends BaseJsonService {
async fetch({ user, repo }) {
return this._requestJson({
schema: automatedBuildSchema,
url: `https://registry.hub.docker.com/v2/repositories/${getDockerHubUser(
user
)}/${repo}`,
errorMessages: { 404: 'repo not found' },
})
}
static render({ isAutomated }) {
if (isAutomated) {
return { message: 'automated', color: dockerBlue }
} else {
return { message: 'manual', color: 'yellow' }
}
}
async handle({ user, repo }) {
const data = await this.fetch({ user, repo })
return this.constructor.render({ isAutomated: data.is_automated })
}
static get category() {
return 'build'
}
static get route() {
return buildDockerUrl('automated')
}
static get defaultBadgeData() {
return { label: 'docker build' }
}
static get examples() {
return [
{
title: 'Docker Automated build',
namedParams: {
user: 'jrottenberg',
repo: 'ffmpeg',
},
staticPreview: this.render({ isAutomated: true }),
},
]
}
}