Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Param(
# Path to the repo containing TODO-annotated files
[Parameter(Mandatory)]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]$RepoRoot
)
& {
enum Priority {
Low = 3
Medium = 2
High = 1
}
class ToDo {
[string] $FilePath
[Nullable[Priority]] $Priority
[int] $Line
[string] $Task
}
Push-Location $RepoRoot
$files = Get-ChildItem . -File -Recurse `
| % FullName `
| ? {$_ -ne $PSCommandPath} `
| Resolve-Path -Relative
Pop-Location
foreach ($file in $files) {
$lines = Get-Content $file
foreach ($i in 1..$lines.Count) {
if ($lines[$i] -match "TODO: \(([^)]+)\) (.*)$") {
# parse prioritized ToDo
[ToDo]@{
FilePath = $file
Priority = $Matches[1]
Line = $i + 1
Task = $Matches[2]
}
} elseif ($lines[$i] -match "TODO: (.*)$") {
# parse unprioritized ToDo
[ToDo]@{
FilePath = $file
Priority = $null
Line = $i + 1 # line numbers are 1-indexed
Task = $Matches[1]
}
}
}
}
} | Sort Priority, FilePath, Line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment