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.
69 lines
1.4 KiB
JavaScript
69 lines
1.4 KiB
JavaScript
'use strict'
|
|
|
|
const SonarBase = require('./sonar-base')
|
|
const { documentation, keywords, queryParamSchema } = require('./sonar-helpers')
|
|
|
|
module.exports = class SonarQualityGate extends SonarBase {
|
|
static get category() {
|
|
return 'analysis'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'sonar',
|
|
pattern: ':metric(quality_gate|alert_status)/:component',
|
|
queryParamSchema,
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Sonar Quality Gate',
|
|
namedParams: {
|
|
component: 'swellaby:azdo-shellcheck',
|
|
metric: 'quality_gate',
|
|
},
|
|
queryParams: {
|
|
server: 'https://sonarcloud.io',
|
|
sonarVersion: '4.2',
|
|
},
|
|
staticPreview: this.render({ qualityState: 'OK' }),
|
|
keywords,
|
|
documentation,
|
|
},
|
|
]
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return { label: 'quality gate' }
|
|
}
|
|
|
|
static render({ qualityState }) {
|
|
if (qualityState === 'OK') {
|
|
return {
|
|
message: 'passed',
|
|
color: 'success',
|
|
}
|
|
}
|
|
return {
|
|
message: 'failed',
|
|
color: 'critical',
|
|
}
|
|
}
|
|
|
|
async handle({ component }, { server, sonarVersion }) {
|
|
const json = await this.fetch({
|
|
sonarVersion,
|
|
server,
|
|
component,
|
|
metricName: 'alert_status',
|
|
})
|
|
const { alert_status: qualityState } = this.transform({
|
|
json,
|
|
sonarVersion,
|
|
})
|
|
return this.constructor.render({ qualityState })
|
|
}
|
|
}
|