Skip to content

Commit a00eb3f

Browse files
stockalexanderondrejmirtes
authored andcommitted
Added severity field in gitlab error formatter, GitLab 13.x expects the field in code quality reports
1 parent 1eaef04 commit a00eb3f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Command/ErrorFormatter/GitlabErrorFormatter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
3737
]
3838
)
3939
),
40+
'severity' => $fileSpecificError->canBeIgnored() ? 'major' : 'blocker',
4041
'location' => [
4142
'path' => $this->relativePathHelper->getRelativePath($fileSpecificError->getFile()),
4243
'lines' => [
@@ -45,17 +46,14 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
4546
],
4647
];
4748

48-
if (!$fileSpecificError->canBeIgnored()) {
49-
$error['severity'] = 'blocker';
50-
}
51-
5249
$errorsArray[] = $error;
5350
}
5451

5552
foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) {
5653
$errorsArray[] = [
5754
'description' => $notFileSpecificError,
5855
'fingerprint' => hash('sha256', $notFileSpecificError),
56+
'severity' => 'major',
5957
'location' => [
6058
'path' => '',
6159
'lines' => [

tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function dataFormatterOutputProvider(): iterable
2727
{
2828
"description": "Foo",
2929
"fingerprint": "e82b7e1f1d4255352b19ecefa9116a12f129c7edb4351cf2319285eccdb1565e",
30+
"severity": "major",
3031
"location": {
3132
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
3233
"lines": {
@@ -46,6 +47,7 @@ public function dataFormatterOutputProvider(): iterable
4647
{
4748
"description": "first generic error",
4849
"fingerprint": "53ed216d77c9a9b21d9535322457ca7d7b037d6596d76484b3481f161adfd96f",
50+
"severity": "major",
4951
"location": {
5052
"path": "",
5153
"lines": {
@@ -65,6 +67,7 @@ public function dataFormatterOutputProvider(): iterable
6567
{
6668
"description": "Bar\nBar2",
6769
"fingerprint": "034b4afbfb347494c14e396ed8327692f58be4cd27e8aff5f19f4194934db7c9",
70+
"severity": "major",
6871
"location": {
6972
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
7073
"lines": {
@@ -75,6 +78,7 @@ public function dataFormatterOutputProvider(): iterable
7578
{
7679
"description": "Foo",
7780
"fingerprint": "e82b7e1f1d4255352b19ecefa9116a12f129c7edb4351cf2319285eccdb1565e",
81+
"severity": "major",
7882
"location": {
7983
"path": "with space/and unicode 😃/project/folder with unicode 😃/file name with \"spaces\" and unicode 😃.php",
8084
"lines": {
@@ -85,6 +89,7 @@ public function dataFormatterOutputProvider(): iterable
8589
{
8690
"description": "Foo",
8791
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
92+
"severity": "major",
8893
"location": {
8994
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
9095
"lines": {
@@ -95,6 +100,7 @@ public function dataFormatterOutputProvider(): iterable
95100
{
96101
"description": "Bar\nBar2",
97102
"fingerprint": "829f6c782152fdac840b39208c5b519d18e51bff2c601b6197812fffb8bcd9ed",
103+
"severity": "major",
98104
"location": {
99105
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
100106
"lines": {
@@ -114,6 +120,7 @@ public function dataFormatterOutputProvider(): iterable
114120
{
115121
"description": "first generic error",
116122
"fingerprint": "53ed216d77c9a9b21d9535322457ca7d7b037d6596d76484b3481f161adfd96f",
123+
"severity": "major",
117124
"location": {
118125
"path": "",
119126
"lines": {
@@ -124,6 +131,7 @@ public function dataFormatterOutputProvider(): iterable
124131
{
125132
"description": "second generic error",
126133
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
134+
"severity": "major",
127135
"location": {
128136
"path": "",
129137
"lines": {
@@ -143,6 +151,7 @@ public function dataFormatterOutputProvider(): iterable
143151
{
144152
"description": "Bar\nBar2",
145153
"fingerprint": "034b4afbfb347494c14e396ed8327692f58be4cd27e8aff5f19f4194934db7c9",
154+
"severity": "major",
146155
"location": {
147156
"path": "with space/and unicode \ud83d\ude03/project/folder with unicode \ud83d\ude03/file name with \"spaces\" and unicode \ud83d\ude03.php",
148157
"lines": {
@@ -153,6 +162,7 @@ public function dataFormatterOutputProvider(): iterable
153162
{
154163
"description": "Foo",
155164
"fingerprint": "e82b7e1f1d4255352b19ecefa9116a12f129c7edb4351cf2319285eccdb1565e",
165+
"severity": "major",
156166
"location": {
157167
"path": "with space/and unicode \ud83d\ude03/project/folder with unicode \ud83d\ude03/file name with \"spaces\" and unicode \ud83d\ude03.php",
158168
"lines": {
@@ -163,6 +173,7 @@ public function dataFormatterOutputProvider(): iterable
163173
{
164174
"description": "Foo",
165175
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
176+
"severity": "major",
166177
"location": {
167178
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
168179
"lines": {
@@ -173,6 +184,7 @@ public function dataFormatterOutputProvider(): iterable
173184
{
174185
"description": "Bar\nBar2",
175186
"fingerprint": "829f6c782152fdac840b39208c5b519d18e51bff2c601b6197812fffb8bcd9ed",
187+
"severity": "major",
176188
"location": {
177189
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
178190
"lines": {
@@ -183,6 +195,7 @@ public function dataFormatterOutputProvider(): iterable
183195
{
184196
"description": "first generic error",
185197
"fingerprint": "53ed216d77c9a9b21d9535322457ca7d7b037d6596d76484b3481f161adfd96f",
198+
"severity": "major",
186199
"location": {
187200
"path": "",
188201
"lines": {
@@ -193,6 +206,7 @@ public function dataFormatterOutputProvider(): iterable
193206
{
194207
"description": "second generic error",
195208
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
209+
"severity": "major",
196210
"location": {
197211
"path": "",
198212
"lines": {

0 commit comments

Comments
 (0)