-
Notifications
You must be signed in to change notification settings - Fork 1
/
write-console.ps1
40 lines (34 loc) · 1.21 KB
/
write-console.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Param([Parameter(Mandatory)][string]$ResharperReport,
[switch]$Colorize = $False,
[switch]$FailOnIssues = $False)
if (-not (Test-Path $ResharperReport)) {
Write-Host ("Could not find file: '{0}'" -f $ResharperReport)
exit 1
}
function Analyze-Report([xml]$Xml) {
$HasIssues = $Xml.DocumentElement["Issues"].ChildNodes.Count -ne 0
$ExitCode = if ($HasIssues) {1} else {0}
return $ExitCode
}
$ContextFile = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
$ReportContext = Get-Content $ResharperReport
$HasIssues = Analyze-Report -Xml $ReportContext
if ($HasIssues -gt 0) {
try {
Write-Host ("InspectCode reported issues in codebase")
Push-Location (Split-Path -Parent $MyInvocation.MyCommand.Path)
.\_Transform-Context.ps1 -Xml $ReportContext -DumpTo $ContextFile -UrlFormat "{0}#{1}"
.\_Write-Console.ps1 -ContextFile (Get-Content $ContextFile) -Colorize $Colorize
} finally{
if (Test-Path $ContextFile) {
Remove-Item -Path $ContextFile -Force
}
Pop-Location
}
} else {
Write-Host "ReSharper detected no issues in the codebase"
}
if (-not $FailOnIssues){
$HasIssues = 0
}
exit $HasIssues