Skip to content

Commit 0bcde89

Browse files
committed
feat(formatters): add severity custom attribute to TeamCity inspections
1 parent 724c7f8 commit 0bcde89

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

packages/formatters/src/__tests__/teamcity.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ describe('Teamcity formatter', () => {
88
const result = teamcity(mixedErrors, { failSeverity: DiagnosticSeverity.Error });
99
expect(result)
1010
.toContain(`##teamcity[inspectionType category='openapi' id='info-contact' name='info-contact' description='hint -- Info object should contain \`contact\` object.']
11-
##teamcity[inspection typeId='info-contact' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='3' message='hint -- Info object should contain \`contact\` object.']
11+
##teamcity[inspection typeId='info-contact' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='3' message='hint -- Info object should contain \`contact\` object.' SEVERITY='HINT']
1212
##teamcity[inspectionType category='openapi' id='info-description' name='info-description' description='warning -- OpenAPI object info \`description\` must be present and non-empty string.']
13-
##teamcity[inspection typeId='info-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='3' message='warning -- OpenAPI object info \`description\` must be present and non-empty string.']
13+
##teamcity[inspection typeId='info-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='3' message='warning -- OpenAPI object info \`description\` must be present and non-empty string.' SEVERITY='WARNING']
1414
##teamcity[inspectionType category='openapi' id='info-matches-stoplight' name='info-matches-stoplight' description='error -- Info must contain Stoplight']
15-
##teamcity[inspection typeId='info-matches-stoplight' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='5' message='error -- Info must contain Stoplight']
15+
##teamcity[inspection typeId='info-matches-stoplight' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='5' message='error -- Info must contain Stoplight' SEVERITY='ERROR']
1616
##teamcity[inspectionType category='openapi' id='operation-description' name='operation-description' description='information -- Operation \`description\` must be present and non-empty string.']
17-
##teamcity[inspection typeId='operation-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='17' message='information -- Operation \`description\` must be present and non-empty string.']
17+
##teamcity[inspection typeId='operation-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='17' message='information -- Operation \`description\` must be present and non-empty string.' SEVERITY='INFO']
1818
##teamcity[inspectionType category='openapi' id='operation-description' name='operation-description' description='information -- Operation \`description\` must be present and non-empty string.']
19-
##teamcity[inspection typeId='operation-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='64' message='information -- Operation \`description\` must be present and non-empty string.']
19+
##teamcity[inspection typeId='operation-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='64' message='information -- Operation \`description\` must be present and non-empty string.' SEVERITY='INFO']
2020
##teamcity[inspectionType category='openapi' id='operation-description' name='operation-description' description='information -- Operation \`description\` must be present and non-empty string.']
21-
##teamcity[inspection typeId='operation-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='86' message='information -- Operation \`description\` must be present and non-empty string.']`);
21+
##teamcity[inspection typeId='operation-description' file='/home/Stoplight/spectral/src/__tests__/__fixtures__/petstore.oas3.json' line='86' message='information -- Operation \`description\` must be present and non-empty string.' SEVERITY='INFO']`);
2222
});
2323
});

packages/formatters/src/teamcity.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Dictionary, Optional } from '@stoplight/types';
1+
import { DiagnosticSeverity, Dictionary, Optional } from '@stoplight/types';
22
import { IRuleResult } from '@stoplight/spectral-core';
33
import { Formatter } from './types';
44
import { getSeverityName, groupBySource } from './utils';
@@ -27,12 +27,20 @@ function inspectionType(result: IRuleResult & { source: string }): string {
2727
return `##teamcity[inspectionType category='openapi' id='${code}' name='${code}' description='${severity} -- ${message}${documentationUrl}']`;
2828
}
2929

30+
const SEVERITY_TEAMCITY_NAMES: Dictionary<string, DiagnosticSeverity> = {
31+
[DiagnosticSeverity.Error]: 'ERROR',
32+
[DiagnosticSeverity.Warning]: 'WARNING',
33+
[DiagnosticSeverity.Information]: 'INFO',
34+
[DiagnosticSeverity.Hint]: 'HINT',
35+
};
36+
3037
function inspection(result: IRuleResult & { source: string }): string {
3138
const code = escapeString(result.code);
3239
const severity = getSeverityName(result.severity);
40+
const teamCitySeverity = SEVERITY_TEAMCITY_NAMES[result.severity];
3341
const message = escapeString(result.message);
3442
const line = result.range.start.line + 1;
35-
return `##teamcity[inspection typeId='${code}' file='${result.source}' line='${line}' message='${severity} -- ${message}']`;
43+
return `##teamcity[inspection typeId='${code}' file='${result.source}' line='${line}' message='${severity} -- ${message}' SEVERITY='${teamCitySeverity}']`;
3644
}
3745

3846
function renderResults(results: IRuleResult[]): string {

test-harness/scenarios/documentation-url/results-format-teamcity.scenario

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ info:
5454
====command====
5555
{bin} lint {document} --format=teamcity --ruleset "{asset:ruleset.json}" --show-documentation-url
5656
====stdout====
57-
##teamcity[inspectionType category='openapi' id='api-servers' name='api-servers' description='warning -- "servers" must be present and non-empty array. -- https://www.example.com/docs/api-servers.md']##teamcity[inspection typeId='api-servers' file='{document}' line='1' message='warning -- "servers" must be present and non-empty array.']
57+
##teamcity[inspectionType category='openapi' id='api-servers' name='api-servers' description='warning -- "servers" must be present and non-empty array. -- https://www.example.com/docs/api-servers.md']##teamcity[inspection typeId='api-servers' file='{document}' line='1' message='warning -- "servers" must be present and non-empty array.' SEVERITY='WARNING']
5858
##teamcity[inspectionType category='openapi' id='info-contact' name='info-contact' description='warning -- Info object must have a "contact" object.']
59-
##teamcity[inspection typeId='info-contact' file='{document}' line='2' message='warning -- Info object must have a "contact" object.']
59+
##teamcity[inspection typeId='info-contact' file='{document}' line='2' message='warning -- Info object must have a "contact" object.' SEVERITY='WARNING']
6060
##teamcity[inspectionType category='openapi' id='info-description' name='info-description' description='warning -- Info "description" must be present and non-empty string. -- https://www.example.com/docs/info-description.md']
61-
##teamcity[inspection typeId='info-description' file='{document}' line='2' message='warning -- Info "description" must be present and non-empty string.']
61+
##teamcity[inspection typeId='info-description' file='{document}' line='2' message='warning -- Info "description" must be present and non-empty string.' SEVERITY='WARNING']

0 commit comments

Comments
 (0)