Restored coverity service (#2967)
This commit is contained in:
committed by
Pierre-Yves B
parent
dfb8d0392c
commit
9b4fec0d2e
@@ -1,17 +1,77 @@
|
||||
'use strict'
|
||||
|
||||
const { deprecatedService } = require('..')
|
||||
const Joi = require('joi')
|
||||
const { BaseJsonService } = require('..')
|
||||
|
||||
// coverity scan integration -
|
||||
// **temporarily deprecated as of January 2019 due to extended outage**
|
||||
// https://community.synopsys.com/s/article/Coverity-Scan-Update
|
||||
// https://github.com/badges/shields/issues/2722
|
||||
module.exports = deprecatedService({
|
||||
route: {
|
||||
base: 'coverity/scan',
|
||||
format: '(?:.+)',
|
||||
},
|
||||
label: 'coverity',
|
||||
category: 'analysis',
|
||||
message: 'extended downtime',
|
||||
})
|
||||
const messageRegex = /passed|passed .* new defects|pending|failed/
|
||||
const schema = Joi.object({
|
||||
message: Joi.string()
|
||||
.regex(messageRegex)
|
||||
.required(),
|
||||
}).required()
|
||||
|
||||
module.exports = class CoverityScan extends BaseJsonService {
|
||||
static render({ message }) {
|
||||
let color
|
||||
if (message === 'passed') {
|
||||
color = 'brightgreen'
|
||||
message = 'passing'
|
||||
} else if (/^passed .* new defects$/.test(message)) {
|
||||
color = 'yellow'
|
||||
} else if (message === 'pending') {
|
||||
color = 'orange'
|
||||
} else {
|
||||
color = 'red'
|
||||
}
|
||||
|
||||
return {
|
||||
message,
|
||||
color,
|
||||
}
|
||||
}
|
||||
|
||||
static get category() {
|
||||
return 'analysis'
|
||||
}
|
||||
|
||||
static get defaultBadgeData() {
|
||||
return {
|
||||
label: 'coverity',
|
||||
}
|
||||
}
|
||||
|
||||
static get route() {
|
||||
return {
|
||||
base: 'coverity/scan',
|
||||
pattern: ':projectId',
|
||||
}
|
||||
}
|
||||
|
||||
static get examples() {
|
||||
return [
|
||||
{
|
||||
title: 'Coverity Scan',
|
||||
namedParams: {
|
||||
projectId: '3997',
|
||||
},
|
||||
staticPreview: this.render({
|
||||
message: 'passed',
|
||||
}),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
async handle({ projectId }) {
|
||||
const url = `https://scan.coverity.com/projects/${projectId}/badge.json`
|
||||
const json = await this._requestJson({
|
||||
url,
|
||||
schema,
|
||||
errorMessages: {
|
||||
// At the moment Coverity returns an HTTP 200 with an HTML page
|
||||
// displaying the text 404 when project is not found.
|
||||
404: 'project not found',
|
||||
},
|
||||
})
|
||||
return this.constructor.render({ message: json.message })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,87 @@
|
||||
'use strict'
|
||||
|
||||
const { ServiceTester } = require('../tester')
|
||||
const Joi = require('joi')
|
||||
const t = (module.exports = require('../tester').createServiceTester())
|
||||
|
||||
const t = (module.exports = new ServiceTester({
|
||||
id: 'CoverityScan',
|
||||
title: 'Coverity Scan',
|
||||
pathPrefix: '/coverity/scan',
|
||||
}))
|
||||
|
||||
t.create('extended downtime')
|
||||
t.create('live: known project id')
|
||||
.get('/3997.json')
|
||||
.expectJSONTypes(
|
||||
Joi.object().keys({
|
||||
name: 'coverity',
|
||||
value: Joi.string().regex(/passing|passed .* new defects|pending|failed/),
|
||||
})
|
||||
)
|
||||
|
||||
t.create('live: unknown project id')
|
||||
.get('/abc.json')
|
||||
// Coverity actually returns an HTTP 200 status with an HTML page when the project is not found.
|
||||
.expectJSON({ name: 'coverity', value: 'unparseable json response' })
|
||||
|
||||
t.create('404 response')
|
||||
.get('/1.json')
|
||||
.intercept(nock =>
|
||||
nock('https://scan.coverity.com/projects/1')
|
||||
.get('/badge.json')
|
||||
.reply(404)
|
||||
)
|
||||
.expectJSON({ name: 'coverity', value: 'project not found' })
|
||||
|
||||
t.create('passed')
|
||||
.get('/2.json?style=_shields_test')
|
||||
.intercept(nock =>
|
||||
nock('https://scan.coverity.com/projects/2')
|
||||
.get('/badge.json')
|
||||
.reply(200, {
|
||||
message: 'passed',
|
||||
})
|
||||
)
|
||||
.expectJSON({
|
||||
name: 'coverity',
|
||||
value: 'extended downtime',
|
||||
value: 'passing',
|
||||
color: 'brightgreen',
|
||||
})
|
||||
|
||||
t.create('passed with defects')
|
||||
.get('/2.json?style=_shields_test')
|
||||
.intercept(nock =>
|
||||
nock('https://scan.coverity.com/projects/2')
|
||||
.get('/badge.json')
|
||||
.reply(200, {
|
||||
message: 'passed 51 new defects',
|
||||
})
|
||||
)
|
||||
.expectJSON({
|
||||
name: 'coverity',
|
||||
value: 'passed 51 new defects',
|
||||
color: 'yellow',
|
||||
})
|
||||
|
||||
t.create('pending')
|
||||
.get('/2.json?style=_shields_test')
|
||||
.intercept(nock =>
|
||||
nock('https://scan.coverity.com/projects/2')
|
||||
.get('/badge.json')
|
||||
.reply(200, {
|
||||
message: 'pending',
|
||||
})
|
||||
)
|
||||
.expectJSON({
|
||||
name: 'coverity',
|
||||
value: 'pending',
|
||||
color: 'orange',
|
||||
})
|
||||
|
||||
t.create('failed')
|
||||
.get('/2.json?style=_shields_test')
|
||||
.intercept(nock =>
|
||||
nock('https://scan.coverity.com/projects/2')
|
||||
.get('/badge.json')
|
||||
.reply(200, {
|
||||
message: 'failed',
|
||||
})
|
||||
)
|
||||
.expectJSON({
|
||||
name: 'coverity',
|
||||
value: 'failed',
|
||||
color: 'red',
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user