Files
shields/services/sonar/sonar-documented-api-density.service.js
Paul Melnikow 6a2f384860 Update [Sonar] routes: metric first, and server in the query string (#3696)
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.
2019-07-14 17:06:14 -04:00

67 lines
1.4 KiB
JavaScript

'use strict'
const SonarBase = require('./sonar-base')
const {
queryParamSchema,
getLabel,
positiveMetricColorScale,
keywords,
documentation,
} = require('./sonar-helpers')
const metric = 'public_documented_api_density'
module.exports = class SonarDocumentedApiDensity extends SonarBase {
static get category() {
return 'analysis'
}
static get route() {
return {
base: `sonar/${metric}`,
pattern: ':component',
queryParamSchema,
}
}
static get examples() {
return [
{
title: 'Sonar Documented API Density',
namedParams: {
component: 'org.ow2.petals:petals-se-ase',
},
queryParams: {
server: 'http://sonar.petalslink.com',
sonarVersion: '4.2',
},
staticPreview: this.render({ density: 82 }),
keywords,
documentation,
},
]
}
static get defaultBadgeData() {
return { label: getLabel({ metric }) }
}
static render({ density }) {
return {
message: `${density}%`,
color: positiveMetricColorScale(density),
}
}
async handle({ component }, { server, sonarVersion }) {
const json = await this.fetch({
sonarVersion,
server,
component,
metricName: metric,
})
const metrics = this.transform({ json, sonarVersion })
return this.constructor.render({ density: metrics[metric] })
}
}