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

migrate some services from examples to openApi part 44; affects [sonar] #9919

Merged
merged 3 commits into from
Feb 5, 2024
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
40 changes: 26 additions & 14 deletions services/sonar/sonar-coverage.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { pathParam } from '../index.js'
import { coveragePercentage } from '../color-formatters.js'
import SonarBase from './sonar-base.js'
import { documentation, keywords, queryParamSchema } from './sonar-helpers.js'
import {
documentation,
queryParamSchema,
openApiQueryParams,
} from './sonar-helpers.js'

export default class SonarCoverage extends SonarBase {
static category = 'coverage'
Expand All @@ -11,22 +16,29 @@ export default class SonarCoverage extends SonarBase {
queryParamSchema,
}

static examples = [
{
title: 'Sonar Coverage',
namedParams: {
component: 'org.ow2.petals:petals-se-ase',
branch: 'master',
static openApi = {
'/sonar/coverage/{component}': {
get: {
summary: 'Sonar Coverage',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
...openApiQueryParams,
],
},
queryParams: {
server: 'http://sonar.petalslink.com',
sonarVersion: '4.2',
},
'/sonar/coverage/{component}/{branch}': {
get: {
summary: 'Sonar Coverage (branch)',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
pathParam({ name: 'branch', example: 'master' }),
...openApiQueryParams,
],
},
staticPreview: this.render({ coverage: 63 }),
keywords,
documentation,
},
]
}

static defaultBadgeData = { label: 'coverage' }

Expand Down
40 changes: 25 additions & 15 deletions services/sonar/sonar-documented-api-density.service.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { pathParam } from '../index.js'
import SonarBase from './sonar-base.js'
import {
queryParamSchema,
openApiQueryParams,
getLabel,
positiveMetricColorScale,
keywords,
documentation,
} from './sonar-helpers.js'

Expand All @@ -18,22 +19,31 @@ export default class SonarDocumentedApiDensity extends SonarBase {
queryParamSchema,
}

static examples = [
{
title: 'Sonar Documented API Density',
namedParams: {
component: 'org.ow2.petals:petals-se-ase',
branch: 'master',
static get openApi() {
const routes = {}
routes[`/sonar/${metric}/{component}`] = {
get: {
summary: 'Sonar Documented API Density',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
...openApiQueryParams,
],
},
queryParams: {
server: 'http://sonar.petalslink.com',
sonarVersion: '4.2',
}
routes[`/sonar/${metric}/{component}/{branch}`] = {
get: {
summary: 'Sonar Documented API Density (branch)',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
pathParam({ name: 'branch', example: 'master' }),
...openApiQueryParams,
],
},
staticPreview: this.render({ density: 82 }),
keywords,
documentation,
},
]
}
return routes
}

static defaultBadgeData = { label: getLabel({ metric }) }

Expand Down
51 changes: 33 additions & 18 deletions services/sonar/sonar-fortify-rating.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { pathParam } from '../index.js'
import SonarBase from './sonar-base.js'
import { queryParamSchema, keywords, documentation } from './sonar-helpers.js'
import {
queryParamSchema,
openApiQueryParams,
documentation,
} from './sonar-helpers.js'

const colorMap = {
0: 'red',
Expand All @@ -10,6 +15,13 @@ const colorMap = {
5: 'brightgreen',
}

const description = `<p>
Note that the Fortify Security Rating badge will only work on Sonar instances that have the <a href='https://marketplace.microfocus.com/fortify/content/fortify-sonarqube-plugin'>Fortify SonarQube Plugin</a> installed.
The badge is not available for projects analyzed on SonarCloud.io
</p>
${documentation}
`

export default class SonarFortifyRating extends SonarBase {
static category = 'analysis'

Expand All @@ -19,26 +31,29 @@ export default class SonarFortifyRating extends SonarBase {
queryParamSchema,
}

static examples = [
{
title: 'Sonar Fortify Security Rating',
namedParams: {
component: 'org.ow2.petals:petals-se-ase',
static openApi = {
'/sonar/fortify-security-rating/{component}': {
get: {
summary: 'Sonar Fortify Security Rating',
description,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
...openApiQueryParams,
],
},
queryParams: {
server: 'http://sonar.petalslink.com',
sonarVersion: '4.2',
},
'/sonar/fortify-security-rating/{component}/{branch}': {
get: {
summary: 'Sonar Fortify Security Rating (branch)',
description,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
pathParam({ name: 'branch', example: 'master' }),
...openApiQueryParams,
],
},
staticPreview: this.render({ rating: 4 }),
keywords,
documentation: `<p>
Note that the Fortify Security Rating badge will only work on Sonar instances that have the <a href='https://marketplace.microfocus.com/fortify/content/fortify-sonarqube-plugin'>Fortify SonarQube Plugin</a> installed.
The badge is not available for projects analyzed on SonarCloud.io
</p>
${documentation}
`,
},
]
}

static defaultBadgeData = { label: 'fortify-security-rating' }

Expand Down
6 changes: 2 additions & 4 deletions services/sonar/sonar-generic.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export const t = await createServiceTester()

t.create('Security Rating')
.timeout(10000)
.get(
'/security_rating/com.luckybox:luckybox.json?server=https://sonarcloud.io',
)
.get('/security_rating/WebExtensions.Net.json?server=https://sonarcloud.io')
.expectBadge({
label: 'security rating',
message: isMetric,
Expand All @@ -16,7 +14,7 @@ t.create('Security Rating')
t.create('Security Rating (branch)')
.timeout(10000)
.get(
'/security_rating/com.luckybox:luckybox/master.json?server=https://sonarcloud.io',
'/security_rating/WebExtensions.Net/main.json?server=https://sonarcloud.io',
)
.expectBadge({
label: 'security rating',
Expand Down
7 changes: 7 additions & 0 deletions services/sonar/sonar-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Joi from 'joi'
import { queryParams } from '../index.js'
import { colorScale } from '../color-formatters.js'
import { optionalUrl } from '../validators.js'

Expand Down Expand Up @@ -40,6 +41,11 @@ const queryParamSchema = Joi.object({
server: optionalUrl.required(),
}).required()

const openApiQueryParams = queryParams(
{ name: 'server', example: 'https://sonarcloud.io', required: true },
{ name: 'sonarVersion', example: '4.2' },
)

const queryParamWithFormatSchema = Joi.object({
sonarVersion: sonarVersionSchema,
server: optionalUrl.required(),
Expand All @@ -61,6 +67,7 @@ export {
getLabel,
isLegacyVersion,
queryParamSchema,
openApiQueryParams,
queryParamWithFormatSchema,
negativeMetricColorScale,
positiveMetricColorScale,
Expand Down
41 changes: 26 additions & 15 deletions services/sonar/sonar-quality-gate.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { pathParam } from '../index.js'
import SonarBase from './sonar-base.js'
import { documentation, keywords, queryParamSchema } from './sonar-helpers.js'
import {
documentation,
queryParamSchema,
openApiQueryParams,
} from './sonar-helpers.js'

export default class SonarQualityGate extends SonarBase {
static category = 'analysis'
Expand All @@ -10,23 +15,29 @@ export default class SonarQualityGate extends SonarBase {
queryParamSchema,
}

static examples = [
{
title: 'Sonar Quality Gate',
namedParams: {
component: 'swellaby:azdo-shellcheck',
metric: 'quality_gate',
branch: 'master',
static openApi = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be an alert_status example?

'/sonar/quality_gate/{component}': {
get: {
summary: 'Sonar Quality Gate',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:azdo-shellcheck' }),
...openApiQueryParams,
],
},
queryParams: {
server: 'https://sonarcloud.io',
sonarVersion: '4.2',
},
'/sonar/quality_gate/{component}/{branch}': {
get: {
summary: 'Sonar Quality Gate (branch)',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:azdo-shellcheck' }),
pathParam({ name: 'branch', example: 'master' }),
...openApiQueryParams,
],
},
staticPreview: this.render({ qualityState: 'OK' }),
keywords,
documentation,
},
]
}

static defaultBadgeData = { label: 'quality gate' }

Expand Down
40 changes: 22 additions & 18 deletions services/sonar/sonar-tech-debt.service.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { pathParam } from '../index.js'
import SonarBase from './sonar-base.js'
import {
negativeMetricColorScale,
getLabel,
documentation,
keywords,
queryParamSchema,
openApiQueryParams,
} from './sonar-helpers.js'

export default class SonarTechDebt extends SonarBase {
Expand All @@ -16,26 +17,29 @@ export default class SonarTechDebt extends SonarBase {
queryParamSchema,
}

static examples = [
{
title: 'Sonar Tech Debt',
namedParams: {
component: 'org.ow2.petals:petals-se-ase',
metric: 'tech_debt',
branch: 'master',
static openApi = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a sqale_debt_ratio example?

'/sonar/tech_debt/{component}': {
get: {
summary: 'Sonar Tech Debt',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
...openApiQueryParams,
],
},
queryParams: {
server: 'http://sonar.petalslink.com',
sonarVersion: '4.2',
},
'/sonar/tech_debt/{component}/{branch}': {
get: {
summary: 'Sonar Tech Debt (branch)',
description: documentation,
parameters: [
pathParam({ name: 'component', example: 'swellaby:letra' }),
pathParam({ name: 'branch', example: 'master' }),
...openApiQueryParams,
],
},
staticPreview: this.render({
debt: 1,
metric: 'tech_debt',
}),
keywords,
documentation,
},
]
}

static defaultBadgeData = { label: 'tech debt' }

Expand Down
Loading
Loading