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

deprecate [DockerBuild] service #6529

Merged
merged 2 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
66 changes: 11 additions & 55 deletions services/docker/docker-build.service.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
'use strict'

const Joi = require('joi')
const { anyInteger } = require('../validators')
const { BaseJsonService } = require('..')
const {
dockerBlue,
buildDockerUrl,
getDockerHubUser,
} = require('./docker-helpers')

const buildSchema = Joi.object({
results: Joi.array()
.items(Joi.object({ status: anyInteger }).required())
.required(),
}).required()

module.exports = class DockerBuild extends BaseJsonService {
static category = 'build'
static route = buildDockerUrl('build')
static examples = [
{
title: 'Docker Build Status',
namedParams: {
user: 'jrottenberg',
repo: 'ffmpeg',
},
staticPreview: this.render({ status: 10 }),
},
]

static defaultBadgeData = { label: 'docker build' }

static render({ status }) {
if (status === 10) {
return { message: 'passing', color: 'brightgreen' }
} else if (status < 0) {
return { message: 'failing', color: 'red' }
}
return { message: 'building', color: dockerBlue }
}

async fetch({ user, repo }) {
return this._requestJson({
schema: buildSchema,
url: `https://registry.hub.docker.com/v2/repositories/${getDockerHubUser(
user
)}/${repo}/buildhistory`,
errorMessages: { 404: 'repo not found' },
})
}

async handle({ user, repo }) {
const data = await this.fetch({ user, repo })
return this.constructor.render({ status: data.results[0].status })
}
}
const { deprecatedService } = require('..')

module.exports = deprecatedService({
category: 'build',
route: {
base: 'docker/build',
pattern: ':various*',
},
label: 'docker build',
dateAdded: new Date('2021-05-24'),
})
61 changes: 12 additions & 49 deletions services/docker/docker-build.tester.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,14 @@
'use strict'

const { isBuildStatus } = require('../build-status')
const t = (module.exports = require('../tester').createServiceTester())
const { dockerBlue } = require('./docker-helpers')

t.create('docker build status (valid, user)')
.get('/jrottenberg/ffmpeg.json')
.expectBadge({
label: 'docker build',
message: isBuildStatus,
})

t.create('docker build status (not found)')
.get('/_/not-a-real-repo.json')
.expectBadge({ label: 'docker build', message: 'repo not found' })

t.create('docker build status (passing)')
.get('/_/ubuntu.json')
.intercept(nock =>
nock('https://registry.hub.docker.com/')
.get('/v2/repositories/library/ubuntu/buildhistory')
.reply(200, { results: [{ status: 10 }] })
)
.expectBadge({
label: 'docker build',
message: 'passing',
color: 'brightgreen',
})

t.create('docker build status (failing)')
.get('/_/ubuntu.json')
.intercept(nock =>
nock('https://registry.hub.docker.com/')
.get('/v2/repositories/library/ubuntu/buildhistory')
.reply(200, { results: [{ status: -1 }] })
)
.expectBadge({ label: 'docker build', message: 'failing', color: 'red' })

t.create('docker build status (building)')
.get('/_/ubuntu.json')
.intercept(nock =>
nock('https://registry.hub.docker.com/')
.get('/v2/repositories/library/ubuntu/buildhistory')
.reply(200, { results: [{ status: 1 }] })
)
.expectBadge({
label: 'docker build',
message: 'building',
color: `#${dockerBlue}`,
})
const { ServiceTester } = require('../tester')

const t = (module.exports = new ServiceTester({
id: 'dockerbuild',
title: 'DockerBuild',
pathPrefix: '/docker/build',
}))

t.create('no longer available').get('/jrottenberg/ffmpeg.json').expectBadge({
label: 'docker build',
message: 'no longer available',
})