Skip to content

Instantly share code, notes, and snippets.

@dzsquared
Created April 23, 2025 14:52
Show Gist options
  • Save dzsquared/96030693447c9f444fb2087c6437244b to your computer and use it in GitHub Desktop.
Save dzsquared/96030693447c9f444fb2087c6437244b to your computer and use it in GitHub Desktop.
PowerShell script to convert SQL code analysis findings into markdown
# output markdown summary of sql code analysis errors and warnings
# parsed out of StaticCodeAnalysis xml output
param(
[Parameter(Mandatory = $true)]
[string]$inputFile
)
$markdownOutput = "# SQL Code Analysis Output`n"
# initialize an array to hold the warnings and errors
$warnings = @()
$caErrors = @()
# load the XML file
[xml]$xml = Get-Content $inputFile
# iterate through the Problem nodes in the XML
foreach ($problem in $xml.Problems.Problem) {
$entry = @{
SourceFile = $problem.SourceFile
Rule = $problem.Rule
Description = $problem.ProblemDescription
}
if ($problem.Severity -eq "Warning") {
$warnings += $entry
} elseif ($problem.Severity -eq "Error") {
$caErrors += $entry
}
}
if ($caErrors.Count -eq 0) {
# if there are no errors, output a message
$markdownOutput += "## ✅ No Code Analysis Errors`n"
} else {
# if there are errors, output the header
$markdownOutput += "## ❌ Code Analysis Errors`n"
# sort the errors by file path
$caErrors = $caErrors | Sort-Object -Property SourceFile
}
foreach ($caError in $caErrors) {
# add the error to the markdown output
$markdownOutput += "- **$($caError.Rule)** in $($caError.SourceFile) $($caError.Description)`n"
}
$markdownOutput += "`n"
if ($warnings.Count -eq 0) {
# if there are no warnings, output a message
$markdownOutput += "## ✅ No Code Analysis Warnings`n"
} else {
# if there are warnings, output the header
$markdownOutput += "## 🟡 Code Analysis Warnings`n"
# sort the warnings by file path
$warnings = $warnings | Sort-Object -Property SourceFile
}
foreach ($warning in $warnings) {
# add the warning to the markdown output
$markdownOutput += "- **$($warning.Rule)** in $($warning.SourceFile) $($warning.Description)`n"
}
# output the markdown to the a file
$markdownOutput | Out-File -FilePath "CodeAnalysisOutput.md" -Encoding utf8
# Output the variables as return values
return @{
ErrorCount = $caErrors.Count
WarningCount = $warnings.Count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment