Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support branches in [Sonar] badges #7065

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion services/sonar/sonar-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,6 +64,7 @@ export default class SonarBase extends BaseJsonService {
depth: 0,
metrics: metricName,
includeTrends: true,
branch,
}
} else {
schema = modernSchema
Expand All @@ -74,6 +75,7 @@ export default class SonarBase extends BaseJsonService {
qs = {
[componentKey]: component,
metricKeys: metricName,
branch,
}
}

Expand Down
6 changes: 4 additions & 2 deletions services/sonar/sonar-coverage.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class SonarCoverage extends SonarBase {

static route = {
base: 'sonar/coverage',
pattern: ':component',
pattern: ':component/:branch*',
queryParamSchema,
}

Expand All @@ -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',
Expand All @@ -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({
Expand Down
7 changes: 7 additions & 0 deletions services/sonar/sonar-coverage.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions services/sonar/sonar-documented-api-density.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class SonarDocumentedApiDensity extends SonarBase {

static route = {
base: `sonar/${metric}`,
pattern: ':component',
pattern: ':component/:branch*',
queryParamSchema,
}

Expand All @@ -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',
Expand All @@ -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 })
Expand Down
5 changes: 3 additions & 2 deletions services/sonar/sonar-fortify-rating.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class SonarFortifyRating extends SonarBase {

static route = {
base: 'sonar/fortify-security-rating',
pattern: ':component',
pattern: ':component/:branch*',
queryParamSchema,
}

Expand Down Expand Up @@ -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',
})

Expand Down
5 changes: 3 additions & 2 deletions services/sonar/sonar-generic.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default class SonarGeneric extends SonarBase {

static route = {
base: 'sonar',
pattern: `:metricName(${metricNameRouteParam})/:component`,
pattern: `:metricName(${metricNameRouteParam})/:component/:branch*`,
queryParamSchema,
}

Expand All @@ -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,
})

Expand Down
11 changes: 11 additions & 0 deletions services/sonar/sonar-generic.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
6 changes: 4 additions & 2 deletions services/sonar/sonar-quality-gate.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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',
Expand All @@ -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({
Expand Down
9 changes: 9 additions & 0 deletions services/sonar/sonar-quality-gate.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions services/sonar/sonar-tech-debt.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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',
Expand All @@ -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',
})
Expand Down
9 changes: 9 additions & 0 deletions services/sonar/sonar-tech-debt.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 13 additions & 7 deletions services/sonar/sonar-tests.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SonarTestsSummary extends SonarBase {

static route = {
base: 'sonar/tests',
pattern: ':component',
pattern: ':component/:branch*',
queryParamSchema: queryParamSchema.concat(testResultQueryParamSchema),
}

Expand All @@ -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',
Expand Down Expand Up @@ -95,7 +96,7 @@ class SonarTestsSummary extends SonarBase {
}

async handle(
{ component },
{ component, branch },
{
server,
sonarVersion,
Expand All @@ -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({
Expand All @@ -134,18 +136,19 @@ 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,
}

static examples = [
{
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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions services/sonar/sonar-tests.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
Loading