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.
71 lines
1.5 KiB
JavaScript
71 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const SonarBase = require('./sonar-base')
|
|
const {
|
|
negativeMetricColorScale,
|
|
getLabel,
|
|
documentation,
|
|
keywords,
|
|
queryParamSchema,
|
|
} = require('./sonar-helpers')
|
|
|
|
module.exports = class SonarTechDebt extends SonarBase {
|
|
static get category() {
|
|
return 'analysis'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'sonar',
|
|
pattern: ':metric(tech_debt|sqale_debt_ratio)/:component',
|
|
queryParamSchema,
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Sonar Tech Debt',
|
|
namedParams: {
|
|
component: 'org.ow2.petals:petals-se-ase',
|
|
metric: 'tech_debt',
|
|
},
|
|
queryParams: {
|
|
server: 'http://sonar.petalslink.com',
|
|
sonarVersion: '4.2',
|
|
},
|
|
staticPreview: this.render({
|
|
debt: 1,
|
|
metric: 'tech_debt',
|
|
}),
|
|
keywords,
|
|
documentation,
|
|
},
|
|
]
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return { label: 'tech debt' }
|
|
}
|
|
|
|
static render({ debt, metric }) {
|
|
return {
|
|
label: getLabel({ metric }),
|
|
message: `${debt}%`,
|
|
color: negativeMetricColorScale(debt),
|
|
}
|
|
}
|
|
|
|
async handle({ component, metric }, { server, sonarVersion }) {
|
|
const json = await this.fetch({
|
|
sonarVersion,
|
|
server,
|
|
component,
|
|
// Special condition for backwards compatibility.
|
|
metricName: 'sqale_debt_ratio',
|
|
})
|
|
const { sqale_debt_ratio: debt } = this.transform({ json, sonarVersion })
|
|
return this.constructor.render({ debt, metric })
|
|
}
|
|
}
|