|
| 1 | +param |
| 2 | +( |
| 3 | + [Parameter(Mandatory = $true)] [String]$BranchName |
| 4 | +) |
| 5 | + |
| 6 | +Set-StrictMode -Version 3.0 |
| 7 | +$ErrorActionPreference = "Stop" |
| 8 | + |
| 9 | +$skippedDirectories = @("node_modules", ` |
| 10 | + "dist", ` |
| 11 | + "obj", ` |
| 12 | + "bin", ` |
| 13 | + "lib", ` |
| 14 | + "Libraries", ` |
| 15 | + "packages", ` |
| 16 | + "Service References", ` |
| 17 | + ".idea", ` |
| 18 | + ".vscode", ` |
| 19 | + "BuildArtifacts", ` |
| 20 | + ".sass-cache", ` |
| 21 | + "Typings", ` |
| 22 | + ".git", ` |
| 23 | + ".sql" ` |
| 24 | + ) ` |
| 25 | + | ForEach-Object { ([IO.Path]::DirectorySeparatorChar + $_).ToLower() } |
| 26 | + |
| 27 | +Write-Host "::group::Checking for TODOs" |
| 28 | + |
| 29 | +$directoriesToProcess = @() |
| 30 | +foreach ($item in Get-ChildItem -Recurse -Directory) { |
| 31 | + $add = $true |
| 32 | + foreach ($directory in $skippedDirectories) { |
| 33 | + if ($item.FullName.ToLower() -like "*$directory*") { |
| 34 | + $add = $false |
| 35 | + continue |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + if ($add) { |
| 40 | + $directoriesToProcess += $item.FullName |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +Write-Host "Looking for TODO $BranchName" |
| 45 | +$regexPattern = "(TODO[\s-\:]*$BranchName)" |
| 46 | + |
| 47 | +function checkForTodoComments { |
| 48 | + $directoriesToProcess | ForEach-Object -Parallel { |
| 49 | + foreach ($item in Get-ChildItem -Path "$_\*" -File -Exclude "*.exe", "*.dll", "*.pdf") { |
| 50 | + if ($item.FullName.EndsWith(".js") -or $item.FullName.EndsWith(".js.map")) { |
| 51 | + if (Test-Path $item.FullName.Replace(".js.map", ".ts").Replace(".js", ".ts")) { |
| 52 | + continue |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + Select-String -Pattern "$using:regexPattern" -Path $item.FullName |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +$todoMatches = checkForTodoComments |
| 62 | + |
| 63 | +Write-Host "::endgroup::" |
| 64 | +if ($null -eq $todoMatches) { |
| 65 | + exit 0 |
| 66 | +} |
| 67 | + |
| 68 | +Write-Host "`nFound TODOs that need to be addressed." |
| 69 | +foreach ($todoMatch in $todoMatches) { |
| 70 | + $relativePath = $todoMatch.Path.Substring($PWD.ToString().Length + 1) |
| 71 | + Write-Host "::error file=$relativePath,line=$( $todoMatch.LineNumber )::This TODO needs to be cleaned up" |
| 72 | + Write-Host " $( $relativePath ):$( $todoMatch.LineNumber )" |
| 73 | + Write-Host " $( $todoMatch.Line )" |
| 74 | +} |
| 75 | + |
| 76 | +exit 1 |
0 commit comments