diff --git a/Tasks/SonarQubePostTest/PRCA/ReportProcessor-Module.psm1 b/Tasks/SonarQubePostTest/PRCA/ReportProcessor-Module.psm1 index 45e219f8d591..7558a260eab7 100644 --- a/Tasks/SonarQubePostTest/PRCA/ReportProcessor-Module.psm1 +++ b/Tasks/SonarQubePostTest/PRCA/ReportProcessor-Module.psm1 @@ -28,12 +28,19 @@ function FetchAnnotatedNewIssues CreateComponentKeyToPathMap $json # '@' makes sure the result set is returned as an array - $newIssues = @($json.issues | Where {$_.isNew -eq $true}) + $newIssues = @($json.issues | Where { $_.isNew -eq $true }) Write-Host "SonarQube found $($json.issues.Count) issues out of which $($newIssues.Count) are new" + + $newFileLevelIssues = @($newIssues | Where {(IsFileLevelIssue $_)}) + $difference = $newIssues.Count - $newFileLevelIssues.Count + if ($difference -gt 0) + { + Write-Host "$difference issue(s) do not relate to a specific file and will not be posted to the code review" + } - $newIssues = AnnotateIssuesWithRelativePath $newIssues + $newFileLevelIssues = AnnotateIssuesWithRelativePath $newFileLevelIssues - return $newIssues + return $newFileLevelIssues } #endregion @@ -128,11 +135,6 @@ function GetComponentGuid $tokens = $component.Split(":") - if ($tokens.Count -ne 4) - { - throw "Internal error: component $component is not in the expected format (expected 4 parts)" - } - #third token must be a guid $guidToken = $tokens[2] @@ -215,7 +217,7 @@ function AnnotateIssuesWithRelativePath param ([Array]$issues) foreach ($issue in $issues) - { + { $filePath = GetPathRelativeToRepoRoot $($issue.component) # Add a new property in the object which stores the file path so it can be consumed directly @@ -225,6 +227,18 @@ function AnnotateIssuesWithRelativePath return $issues } +# +# File level issues have a 4-part component. Assembly level issues have a 3-part component. +# +function IsFileLevelIssue +{ + param ([ValidateNotNullOrEmpty()]$issue) + + $tokens = $issue.component.Split(":") + + return ($tokens.Count -eq 4) +} + #endregion # Export the public functions diff --git a/Tasks/SonarQubePostTest/task.json b/Tasks/SonarQubePostTest/task.json index c25b17aac9a0..67cc71505234 100644 --- a/Tasks/SonarQubePostTest/task.json +++ b/Tasks/SonarQubePostTest/task.json @@ -12,7 +12,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 45 + "Patch": 46 }, "minimumAgentVersion": "1.99.0", "demands": [ diff --git a/Tasks/SonarQubePostTest/task.loc.json b/Tasks/SonarQubePostTest/task.loc.json index 4736a6400aa9..cfd313615852 100644 --- a/Tasks/SonarQubePostTest/task.loc.json +++ b/Tasks/SonarQubePostTest/task.loc.json @@ -12,7 +12,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 45 + "Patch": 46 }, "minimumAgentVersion": "1.99.0", "demands": [ diff --git a/Tests/L0/SonarQubePostTest/PRCA/data/out/.sonar/sonar-report.json b/Tests/L0/SonarQubePostTest/PRCA/data/out/.sonar/sonar-report.json index a4d071145756..2c4272c392a5 100644 --- a/Tests/L0/SonarQubePostTest/PRCA/data/out/.sonar/sonar-report.json +++ b/Tests/L0/SonarQubePostTest/PRCA/data/out/.sonar/sonar-report.json @@ -16,6 +16,16 @@ "isNew": true, "creationDate": "2016-02-29T14:10:20+0000" }, + { + "key": "3d04d8a1-1c8d-47be-8e47-09a1b4c037f6", + "component": "prca_test:prca_test:8C269B30-29BC-4BCD-9AB0-7ACFB763DB2E", + "message": "This issue is reported at the assembly level!", + "severity": "MAJOR", + "rule": "fxcop:MarkAssembliesWithNeutralResourcesLanguage", + "status": "OPEN", + "isNew": true, + "creationDate": "2016-05-17T23:16:56+0200" + }, { "key": "AVMtPj5t2ux5vOqxVSsN", "component": "prca_test:prca_test:8C269B30-29BC-4BCD-9AB0-7ACFB763DB2E:Class1.cs",