diff --git a/services/sonar/sonar-base.js b/services/sonar/sonar-base.js index 72139f14f9aea..86d86df1273ca 100644 --- a/services/sonar/sonar-base.js +++ b/services/sonar/sonar-base.js @@ -52,7 +52,7 @@ const legacySchema = Joi.array() export default class SonarBase extends BaseJsonService { static auth = { userKey: 'sonarqube_token', serviceKey: 'sonar' } - async fetch({ sonarVersion, server, component, metricName }) { + async fetch({ sonarVersion, server, component, metricName, branch }) { const useLegacyApi = isLegacyVersion({ sonarVersion }) let qs, url, schema @@ -64,6 +64,7 @@ export default class SonarBase extends BaseJsonService { depth: 0, metrics: metricName, includeTrends: true, + branch, } } else { schema = modernSchema @@ -74,6 +75,7 @@ export default class SonarBase extends BaseJsonService { qs = { [componentKey]: component, metricKeys: metricName, + branch, } } diff --git a/services/sonar/sonar-coverage.service.js b/services/sonar/sonar-coverage.service.js index ca71ab8264bc5..cd6351e58e9e3 100644 --- a/services/sonar/sonar-coverage.service.js +++ b/services/sonar/sonar-coverage.service.js @@ -7,7 +7,7 @@ export default class SonarCoverage extends SonarBase { static route = { base: 'sonar/coverage', - pattern: ':component', + pattern: ':component/:branch*', queryParamSchema, } @@ -16,6 +16,7 @@ export default class SonarCoverage extends SonarBase { title: 'Sonar Coverage', namedParams: { component: 'org.ow2.petals:petals-se-ase', + branch: 'master', }, queryParams: { server: 'http://sonar.petalslink.com', @@ -36,11 +37,12 @@ export default class SonarCoverage extends SonarBase { } } - async handle({ component }, { server, sonarVersion }) { + async handle({ component, branch }, { server, sonarVersion }) { const json = await this.fetch({ sonarVersion, server, component, + branch, metricName: 'coverage', }) const { coverage } = this.transform({ diff --git a/services/sonar/sonar-coverage.tester.js b/services/sonar/sonar-coverage.tester.js index 6a03fa2171d4d..ed360b0aae116 100644 --- a/services/sonar/sonar-coverage.tester.js +++ b/services/sonar/sonar-coverage.tester.js @@ -15,6 +15,13 @@ t.create('Coverage') message: isIntegerPercentage, }) +t.create('Coverage (branch)') + .get('/swellaby%3Aletra/master.json?server=https://sonarcloud.io') + .expectBadge({ + label: 'coverage', + message: isIntegerPercentage, + }) + t.create('Coverage (legacy API supported)') .get( '/org.ow2.petals%3Apetals-se-ase.json?server=http://sonar.petalslink.com&sonarVersion=4.2' diff --git a/services/sonar/sonar-documented-api-density.service.js b/services/sonar/sonar-documented-api-density.service.js index 9c605f94beb5a..6e79354164dd2 100644 --- a/services/sonar/sonar-documented-api-density.service.js +++ b/services/sonar/sonar-documented-api-density.service.js @@ -14,7 +14,7 @@ export default class SonarDocumentedApiDensity extends SonarBase { static route = { base: `sonar/${metric}`, - pattern: ':component', + pattern: ':component/:branch*', queryParamSchema, } @@ -23,6 +23,7 @@ export default class SonarDocumentedApiDensity extends SonarBase { title: 'Sonar Documented API Density', namedParams: { component: 'org.ow2.petals:petals-se-ase', + branch: 'master', }, queryParams: { server: 'http://sonar.petalslink.com', @@ -43,11 +44,12 @@ export default class SonarDocumentedApiDensity extends SonarBase { } } - async handle({ component }, { server, sonarVersion }) { + async handle({ component, branch }, { server, sonarVersion }) { const json = await this.fetch({ sonarVersion, server, component, + branch, metricName: metric, }) const metrics = this.transform({ json, sonarVersion }) diff --git a/services/sonar/sonar-fortify-rating.service.js b/services/sonar/sonar-fortify-rating.service.js index 2e375c18f0345..96ca325b60e11 100644 --- a/services/sonar/sonar-fortify-rating.service.js +++ b/services/sonar/sonar-fortify-rating.service.js @@ -15,7 +15,7 @@ export default class SonarFortifyRating extends SonarBase { static route = { base: 'sonar/fortify-security-rating', - pattern: ':component', + pattern: ':component/:branch*', queryParamSchema, } @@ -50,11 +50,12 @@ export default class SonarFortifyRating extends SonarBase { } } - async handle({ component }, { server, sonarVersion }) { + async handle({ component, branch }, { server, sonarVersion }) { const json = await this.fetch({ sonarVersion, server, component, + branch, metricName: 'fortify-security-rating', }) diff --git a/services/sonar/sonar-generic.service.js b/services/sonar/sonar-generic.service.js index adc6bcd6af36c..9f18e39272c0d 100644 --- a/services/sonar/sonar-generic.service.js +++ b/services/sonar/sonar-generic.service.js @@ -109,7 +109,7 @@ export default class SonarGeneric extends SonarBase { static route = { base: 'sonar', - pattern: `:metricName(${metricNameRouteParam})/:component`, + pattern: `:metricName(${metricNameRouteParam})/:component/:branch*`, queryParamSchema, } @@ -123,11 +123,12 @@ export default class SonarGeneric extends SonarBase { } } - async handle({ component, metricName }, { server, sonarVersion }) { + async handle({ component, metricName, branch }, { server, sonarVersion }) { const json = await this.fetch({ sonarVersion, server, component, + branch, metricName, }) diff --git a/services/sonar/sonar-generic.tester.js b/services/sonar/sonar-generic.tester.js index 2c17598222760..6124eee2adc87 100644 --- a/services/sonar/sonar-generic.tester.js +++ b/services/sonar/sonar-generic.tester.js @@ -12,3 +12,14 @@ t.create('Security Rating') message: isMetric, color: 'blue', }) + +t.create('Security Rating (branch)') + .timeout(10000) + .get( + '/security_rating/com.luckybox:luckybox/master.json?server=https://sonarcloud.io' + ) + .expectBadge({ + label: 'security rating', + message: isMetric, + color: 'blue', + }) diff --git a/services/sonar/sonar-quality-gate.service.js b/services/sonar/sonar-quality-gate.service.js index d2b8a31f0fb96..525b4dc5d041a 100644 --- a/services/sonar/sonar-quality-gate.service.js +++ b/services/sonar/sonar-quality-gate.service.js @@ -6,7 +6,7 @@ export default class SonarQualityGate extends SonarBase { static route = { base: 'sonar', - pattern: ':metric(quality_gate|alert_status)/:component', + pattern: ':metric(quality_gate|alert_status)/:component/:branch*', queryParamSchema, } @@ -16,6 +16,7 @@ export default class SonarQualityGate extends SonarBase { namedParams: { component: 'swellaby:azdo-shellcheck', metric: 'quality_gate', + branch: 'master', }, queryParams: { server: 'https://sonarcloud.io', @@ -42,11 +43,12 @@ export default class SonarQualityGate extends SonarBase { } } - async handle({ component }, { server, sonarVersion }) { + async handle({ component, branch }, { server, sonarVersion }) { const json = await this.fetch({ sonarVersion, server, component, + branch, metricName: 'alert_status', }) const { alert_status: qualityState } = this.transform({ diff --git a/services/sonar/sonar-quality-gate.tester.js b/services/sonar/sonar-quality-gate.tester.js index d6e2ca30d224d..2deca1defc49e 100644 --- a/services/sonar/sonar-quality-gate.tester.js +++ b/services/sonar/sonar-quality-gate.tester.js @@ -19,6 +19,15 @@ t.create('Quality Gate') message: isQualityGateStatus, }) +t.create('Quality Gate (branch)') + .get( + '/quality_gate/swellaby%3Aazdo-shellcheck/master.json?server=https://sonarcloud.io' + ) + .expectBadge({ + label: 'quality gate', + message: isQualityGateStatus, + }) + t.create('Quality Gate (Alert Status)') .get( '/alert_status/org.ow2.petals%3Apetals-se-ase.json?server=http://sonar.petalslink.com&sonarVersion=4.2' diff --git a/services/sonar/sonar-tech-debt.service.js b/services/sonar/sonar-tech-debt.service.js index b8c1de4cd25ed..f9182ca6e9477 100644 --- a/services/sonar/sonar-tech-debt.service.js +++ b/services/sonar/sonar-tech-debt.service.js @@ -12,7 +12,7 @@ export default class SonarTechDebt extends SonarBase { static route = { base: 'sonar', - pattern: ':metric(tech_debt|sqale_debt_ratio)/:component', + pattern: ':metric(tech_debt|sqale_debt_ratio)/:component/:branch*', queryParamSchema, } @@ -22,6 +22,7 @@ export default class SonarTechDebt extends SonarBase { namedParams: { component: 'org.ow2.petals:petals-se-ase', metric: 'tech_debt', + branch: 'master', }, queryParams: { server: 'http://sonar.petalslink.com', @@ -46,11 +47,12 @@ export default class SonarTechDebt extends SonarBase { } } - async handle({ component, metric }, { server, sonarVersion }) { + 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', }) diff --git a/services/sonar/sonar-tech-debt.tester.js b/services/sonar/sonar-tech-debt.tester.js index f9137fe570a87..835d34c8e46e4 100644 --- a/services/sonar/sonar-tech-debt.tester.js +++ b/services/sonar/sonar-tech-debt.tester.js @@ -17,6 +17,15 @@ t.create('Tech Debt') message: isPercentage, }) +t.create('Tech Debt (branch)') + .get( + '/tech_debt/org.sonarsource.sonarqube%3Asonarqube/master.json?server=https://sonarcloud.io' + ) + .expectBadge({ + label: 'tech debt', + message: isPercentage, + }) + t.create('Tech Debt (legacy API supported)') .get( '/tech_debt/org.ow2.petals%3Apetals-se-ase.json?server=http://sonar.petalslink.com&sonarVersion=4.2' diff --git a/services/sonar/sonar-tests.service.js b/services/sonar/sonar-tests.service.js index ec10994ba3f7e..24e7d4d80107a 100644 --- a/services/sonar/sonar-tests.service.js +++ b/services/sonar/sonar-tests.service.js @@ -17,7 +17,7 @@ class SonarTestsSummary extends SonarBase { static route = { base: 'sonar/tests', - pattern: ':component', + pattern: ':component/:branch*', queryParamSchema: queryParamSchema.concat(testResultQueryParamSchema), } @@ -26,6 +26,7 @@ class SonarTestsSummary extends SonarBase { title: 'Sonar Tests', namedParams: { component: 'org.ow2.petals:petals-se-ase', + branch: 'master', }, queryParams: { server: 'http://sonar.petalslink.com', @@ -95,7 +96,7 @@ class SonarTestsSummary extends SonarBase { } async handle( - { component }, + { component, branch }, { server, sonarVersion, @@ -109,6 +110,7 @@ class SonarTestsSummary extends SonarBase { sonarVersion, server, component, + branch, metricName: 'tests,test_failures,skipped_tests', }) const { total, passed, failed, skipped } = this.transform({ @@ -134,7 +136,7 @@ class SonarTests extends SonarBase { static route = { base: 'sonar', pattern: - ':metric(total_tests|skipped_tests|test_failures|test_errors|test_execution_time|test_success_density)/:component', + ':metric(total_tests|skipped_tests|test_failures|test_errors|test_execution_time|test_success_density)/:component/:branch*', queryParamSchema, } @@ -142,10 +144,11 @@ class SonarTests extends SonarBase { { title: 'Sonar Test Count', pattern: - ':metric(total_tests|skipped_tests|test_failures|test_errors)/:component', + ':metric(total_tests|skipped_tests|test_failures|test_errors)/:component/:branch*', namedParams: { component: 'org.ow2.petals:petals-log', metric: 'total_tests', + branch: 'master', }, queryParams: { server: 'http://sonar.petalslink.com', @@ -160,9 +163,10 @@ class SonarTests extends SonarBase { }, { title: 'Sonar Test Execution Time', - pattern: 'test_execution_time/:component', + pattern: 'test_execution_time/:component/:branch*', namedParams: { component: 'swellaby:azure-pipelines-templates', + branch: 'master', }, queryParams: { server: 'https://sonarcloud.io', @@ -177,9 +181,10 @@ class SonarTests extends SonarBase { }, { title: 'Sonar Test Success Rate', - pattern: 'test_success_density/:component', + pattern: 'test_success_density/:component/:branch*', namedParams: { component: 'swellaby:azure-pipelines-templates', + branch: 'master', }, queryParams: { server: 'https://sonarcloud.io', @@ -218,11 +223,12 @@ class SonarTests extends SonarBase { } } - async handle({ component, metric }, { server, sonarVersion }) { + async handle({ component, metric, branch }, { server, sonarVersion }) { const json = await this.fetch({ sonarVersion, server, component, + branch, // We're using 'tests' as the metric key to provide our standard // formatted test badge (passed, failed, skipped) that exists for other // services. Therefore, we're exposing 'total_tests' to the user, and diff --git a/services/sonar/sonar-tests.tester.js b/services/sonar/sonar-tests.tester.js index 86f26d68a576f..b9315a266a0f1 100644 --- a/services/sonar/sonar-tests.tester.js +++ b/services/sonar/sonar-tests.tester.js @@ -34,6 +34,16 @@ t.create('Tests') message: isDefaultTestTotals, }) +t.create('Tests (branch)') + .timeout(10000) + .get( + '/tests/swellaby:azure-pipelines-templates/master.json?server=https://sonarcloud.io' + ) + .expectBadge({ + label: 'tests', + message: isDefaultTestTotals, + }) + t.create('Tests (legacy API supported)') .get( '/tests/org.ow2.petals%3Apetals-se-ase.json?server=http://sonar.petalslink.com&sonarVersion=4.2' @@ -119,6 +129,16 @@ t.create('Total Test Count') message: isMetric, }) +t.create('Total Test Count (branch)') + .timeout(10000) + .get( + '/total_tests/swellaby:azdo-shellcheck/master.json?server=https://sonarcloud.io' + ) + .expectBadge({ + label: 'total tests', + message: isMetric, + }) + t.create('Total Test Count (legacy API supported)') .get( '/total_tests/org.ow2.petals%3Apetals-se-ase.json?server=http://sonar.petalslink.com&sonarVersion=4.2' diff --git a/services/sonar/sonar-violations.service.js b/services/sonar/sonar-violations.service.js index e82364bb9e184..6675e6720a621 100644 --- a/services/sonar/sonar-violations.service.js +++ b/services/sonar/sonar-violations.service.js @@ -27,7 +27,7 @@ export default class SonarViolations extends SonarBase { static route = { base: 'sonar', pattern: - ':metric(violations|blocker_violations|critical_violations|major_violations|minor_violations|info_violations)/:component', + ':metric(violations|blocker_violations|critical_violations|major_violations|minor_violations|info_violations)/:component/:branch*', queryParamSchema: queryParamWithFormatSchema, } @@ -37,6 +37,7 @@ export default class SonarViolations extends SonarBase { namedParams: { component: 'swellaby:azdo-shellcheck', metric: 'violations', + branch: 'master', }, queryParams: { server: 'https://sonarcloud.io', @@ -56,6 +57,7 @@ export default class SonarViolations extends SonarBase { namedParams: { component: 'org.ow2.petals:petals-se-ase', metric: 'violations', + branch: 'master', }, queryParams: { server: 'http://sonar.petalslink.com', @@ -144,7 +146,10 @@ export default class SonarViolations extends SonarBase { return { violations: metrics } } - async handle({ component, metric }, { server, sonarVersion, format }) { + async handle( + { component, metric, branch }, + { server, sonarVersion, format } + ) { // If the user has requested the long format for the violations badge // then we need to include each individual violation metric in the call to the API // in order to get the count breakdown per each violation category. @@ -156,6 +161,7 @@ export default class SonarViolations extends SonarBase { sonarVersion, server, component, + branch, metricName: metricKeys, }) diff --git a/services/sonar/sonar-violations.tester.js b/services/sonar/sonar-violations.tester.js index b757df1712bec..98b472652641b 100644 --- a/services/sonar/sonar-violations.tester.js +++ b/services/sonar/sonar-violations.tester.js @@ -25,6 +25,16 @@ t.create('Violations') message: isMetric, }) +t.create('Violations (branch)') + .timeout(10000) + .get( + '/violations/org.sonarsource.sonarqube%3Asonarqube/master.json?server=https://sonarcloud.io' + ) + .expectBadge({ + label: 'violations', + message: isMetric, + }) + t.create('Violations (legacy API supported)') .get( '/violations/org.ow2.petals%3Apetals-se-ase.json?server=http://sonar.petalslink.com&sonarVersion=4.2'