Files
shields/services/sonar/sonar-tech-debt.service.js
Caleb Cartwright 8a6eba330e feat: support branches in sonar badges (#7065)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2021-10-13 21:31:45 +00:00

63 lines
1.4 KiB
JavaScript

import SonarBase from './sonar-base.js'
import {
negativeMetricColorScale,
getLabel,
documentation,
keywords,
queryParamSchema,
} from './sonar-helpers.js'
export default class SonarTechDebt extends SonarBase {
static category = 'analysis'
static route = {
base: 'sonar',
pattern: ':metric(tech_debt|sqale_debt_ratio)/:component/:branch*',
queryParamSchema,
}
static examples = [
{
title: 'Sonar Tech Debt',
namedParams: {
component: 'org.ow2.petals:petals-se-ase',
metric: 'tech_debt',
branch: 'master',
},
queryParams: {
server: 'http://sonar.petalslink.com',
sonarVersion: '4.2',
},
staticPreview: this.render({
debt: 1,
metric: 'tech_debt',
}),
keywords,
documentation,
},
]
static defaultBadgeData = { label: 'tech debt' }
static render({ debt, metric }) {
return {
label: getLabel({ metric }),
message: `${debt}%`,
color: negativeMetricColorScale(debt),
}
}
async handle({ component, metric, branch }, { server, sonarVersion }) {
const json = await this.fetch({
sonarVersion,
server,
component,
branch,
// Special condition for backwards compatibility.
metricName: 'sqale_debt_ratio',
})
const { sqale_debt_ratio: debt } = this.transform({ json, sonarVersion })
return this.constructor.render({ debt, metric })
}
}