This is the preferred way we’re handling server URLs: in the query string. While we still have a mix of these, I’ve argued this way is better for these reasons: 1. It allows us to make the URLs a bit more standardized across services. 2. It makes the routes unambiguous. 3. It requires less code. While it introduces a URL-encoding requirement on the parameter, I think these tradeoffs are worth it.
63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const { coveragePercentage } = require('../color-formatters')
|
|
const SonarBase = require('./sonar-base')
|
|
const { documentation, keywords, queryParamSchema } = require('./sonar-helpers')
|
|
|
|
module.exports = class SonarCoverage extends SonarBase {
|
|
static get category() {
|
|
return 'coverage'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'sonar/coverage',
|
|
pattern: ':component',
|
|
queryParamSchema,
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Sonar Coverage',
|
|
namedParams: {
|
|
component: 'org.ow2.petals:petals-se-ase',
|
|
},
|
|
queryParams: {
|
|
server: 'http://sonar.petalslink.com',
|
|
sonarVersion: '4.2',
|
|
},
|
|
staticPreview: this.render({ coverage: 63 }),
|
|
keywords,
|
|
documentation,
|
|
},
|
|
]
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return { label: 'coverage' }
|
|
}
|
|
|
|
static render({ coverage }) {
|
|
return {
|
|
message: `${coverage.toFixed(0)}%`,
|
|
color: coveragePercentage(coverage),
|
|
}
|
|
}
|
|
|
|
async handle({ component }, { server, sonarVersion }) {
|
|
const json = await this.fetch({
|
|
sonarVersion,
|
|
server,
|
|
component,
|
|
metricName: 'coverage',
|
|
})
|
|
const { coverage } = this.transform({
|
|
json,
|
|
sonarVersion,
|
|
})
|
|
return this.constructor.render({ coverage })
|
|
}
|
|
}
|