Skip to content

Commit 634216f

Browse files
committed
Fix a bug where the assembly level issues would crash PR-CA (based on… (#1753)
* Fix a bug where the assembly level issues would crash PR-CA (based on master commit 4e68906)
1 parent 2027d31 commit 634216f

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

Tasks/SonarQubePostTest/PRCA/ReportProcessor-Module.psm1

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ function FetchAnnotatedNewIssues
2828
CreateComponentKeyToPathMap $json
2929

3030
# '@' makes sure the result set is returned as an array
31-
$newIssues = @($json.issues | Where {$_.isNew -eq $true})
31+
$newIssues = @($json.issues | Where { $_.isNew -eq $true })
3232
Write-Host "SonarQube found $($json.issues.Count) issues out of which $($newIssues.Count) are new"
33+
34+
$newFileLevelIssues = @($newIssues | Where {(IsFileLevelIssue $_)})
35+
$difference = $newIssues.Count - $newFileLevelIssues.Count
36+
if ($difference -gt 0)
37+
{
38+
Write-Host "$difference issue(s) do not relate to a specific file and will not be posted to the code review"
39+
}
3340

34-
$newIssues = AnnotateIssuesWithRelativePath $newIssues
41+
$newFileLevelIssues = AnnotateIssuesWithRelativePath $newFileLevelIssues
3542

36-
return $newIssues
43+
return $newFileLevelIssues
3744
}
3845

3946
#endregion
@@ -128,11 +135,6 @@ function GetComponentGuid
128135

129136
$tokens = $component.Split(":")
130137

131-
if ($tokens.Count -ne 4)
132-
{
133-
throw "Internal error: component $component is not in the expected format (expected 4 parts)"
134-
}
135-
136138
#third token must be a guid
137139
$guidToken = $tokens[2]
138140

@@ -215,7 +217,7 @@ function AnnotateIssuesWithRelativePath
215217
param ([Array]$issues)
216218

217219
foreach ($issue in $issues)
218-
{
220+
{
219221
$filePath = GetPathRelativeToRepoRoot $($issue.component)
220222

221223
# Add a new property in the object which stores the file path so it can be consumed directly
@@ -225,6 +227,18 @@ function AnnotateIssuesWithRelativePath
225227
return $issues
226228
}
227229

230+
#
231+
# File level issues have a 4-part component. Assembly level issues have a 3-part component.
232+
#
233+
function IsFileLevelIssue
234+
{
235+
param ([ValidateNotNullOrEmpty()]$issue)
236+
237+
$tokens = $issue.component.Split(":")
238+
239+
return ($tokens.Count -eq 4)
240+
}
241+
228242
#endregion
229243

230244
# Export the public functions

Tasks/SonarQubePostTest/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"version": {
1313
"Major": 1,
1414
"Minor": 0,
15-
"Patch": 45
15+
"Patch": 46
1616
},
1717
"minimumAgentVersion": "1.99.0",
1818
"demands": [

Tasks/SonarQubePostTest/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"version": {
1313
"Major": 1,
1414
"Minor": 0,
15-
"Patch": 45
15+
"Patch": 46
1616
},
1717
"minimumAgentVersion": "1.99.0",
1818
"demands": [

Tests/L0/SonarQubePostTest/PRCA/data/out/.sonar/sonar-report.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
"isNew": true,
1717
"creationDate": "2016-02-29T14:10:20+0000"
1818
},
19+
{
20+
"key": "3d04d8a1-1c8d-47be-8e47-09a1b4c037f6",
21+
"component": "prca_test:prca_test:8C269B30-29BC-4BCD-9AB0-7ACFB763DB2E",
22+
"message": "This issue is reported at the assembly level!",
23+
"severity": "MAJOR",
24+
"rule": "fxcop:MarkAssembliesWithNeutralResourcesLanguage",
25+
"status": "OPEN",
26+
"isNew": true,
27+
"creationDate": "2016-05-17T23:16:56+0200"
28+
},
1929
{
2030
"key": "AVMtPj5t2ux5vOqxVSsN",
2131
"component": "prca_test:prca_test:8C269B30-29BC-4BCD-9AB0-7ACFB763DB2E:Class1.cs",

0 commit comments

Comments
 (0)