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 [David] badges #7197

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
106 changes: 12 additions & 94 deletions services/david/david.service.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,13 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'

const schema = Joi.object({
status: Joi.allow(
'insecure',
'outofdate',
'notsouptodate',
'uptodate',
'none'
).required(),
}).required()

const queryParamSchema = Joi.object({
path: Joi.string(),
}).required()

const statusMap = {
insecure: {
color: 'red',
message: 'insecure',
},
outofdate: {
color: 'red',
message: 'out of date',
},
notsouptodate: {
color: 'yellow',
message: 'up to date',
},
uptodate: {
color: 'brightgreen',
message: 'up to date',
},
none: {
color: 'brightgreen',
message: 'none',
},
}

export default class David extends BaseJsonService {
static category = 'dependencies'
static route = {
base: 'david',
pattern: ':kind(dev|optional|peer)?/:user/:repo',
queryParamSchema,
}

static examples = [
{
title: 'David',
namedParams: { user: 'expressjs', repo: 'express' },
staticPreview: this.render({ status: 'uptodate' }),
},
{
title: 'David (path)',
namedParams: { user: 'babel', repo: 'babel' },
queryParams: { path: 'packages/babel-core' },
staticPreview: this.render({ status: 'uptodate' }),
import { deprecatedService } from '../index.js'

export default [
deprecatedService({
category: 'dependencies',
route: {
base: 'david',
pattern: ':various+',
},
]

static defaultBadgeData = { label: 'dependencies' }

static render({ status, kind }) {
return {
message: statusMap[status].message,
color: statusMap[status].color,
label: `${kind ? `${kind} ` : ''}dependencies`,
}
}

async fetch({ kind, user, repo, path }) {
// Note: David does not return canonical 404 response codes for 'not found'
// cases, but will instead return various 50x errors. Accordingly we account
// for both 'not found' as well as typical/real internal server errors.
const notFoundError = 'repo or path not found or david internal error'

return this._requestJson({
schema,
url: `https://status.david-dm.org/gh/${user}/${repo}`,
options: { qs: { path, type: kind } },
errorMessages: {
502: notFoundError,
503: notFoundError,
504: notFoundError,
},
})
}

async handle({ kind, user, repo }, { path }) {
const json = await this.fetch({ kind, user, repo, path })
return this.constructor.render({ status: json.status, kind })
}
}
label: 'david',
dateAdded: new Date('2021-10-30'),
}),
]
72 changes: 11 additions & 61 deletions services/david/david.tester.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,20 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
import { ServiceTester } from '../tester.js'

const isDependencyStatus = Joi.string().valid(
'insecure',
'up to date',
'out of date'
)
export const t = new ServiceTester({
id: 'david',
title: 'David',
})

t.create('david dependencies (valid)')
t.create('no longer available (previously dependencies)')
.get('/expressjs/express.json')
.timeout(15000)
.expectBadge({
label: 'dependencies',
message: isDependencyStatus,
label: 'david',
message: 'no longer available',
})

t.create('david dev dependencies (valid)')
t.create('no longer available (previously dev dependencies)')
.get('/dev/expressjs/express.json')
.timeout(15000)
.expectBadge({
label: 'dev dependencies',
message: isDependencyStatus,
})

t.create('david optional dependencies (valid)')
.get('/optional/elnounch/byebye.json')
.timeout(15000)
.expectBadge({
label: 'optional dependencies',
message: isDependencyStatus,
})

t.create('david peer dependencies (valid)')
.get('/peer/webcomponents/generator-element.json')
.timeout(15000)
.expectBadge({
label: 'peer dependencies',
message: isDependencyStatus,
})

t.create('david dependencies with path (valid)')
.get('/babel/babel.json?path=packages/babel-core')
.timeout(15000)
.expectBadge({
label: 'dependencies',
message: isDependencyStatus,
})

t.create('david dependencies (none)')
.get('/peer/expressjs/express.json') // express does not specify peer dependencies
.timeout(15000)
.expectBadge({ label: 'peer dependencies', message: 'none' })

t.create('david dependencies (repo not found)')
.get('/pyvesb/emptyrepo.json')
.timeout(15000)
.expectBadge({
label: 'dependencies',
message: 'repo or path not found or david internal error',
})

t.create('david dependencies (path not found')
.get('/babel/babel.json?path=invalid/path')
.timeout(15000)
.expectBadge({
label: 'dependencies',
message: 'repo or path not found or david internal error',
label: 'david',
message: 'no longer available',
})