Created
March 2, 2023 18:48
-
-
Save jaredpar/68b8c5187a3033e76a5d80c76a7760c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Parse-Channels([string]$repo) { | |
$output = Invoke-Expression "& darc get-default-channels --source-repo $repo" | |
$map = @{ } | |
foreach ($line in $output) { | |
$parts = $line.Split('@') | |
$repoUrl = $parts[0].Split(' ')[1].Trim() | |
if (-not $repoUrl.EndsWith($repo)) { | |
continue | |
} | |
$parts = $parts[1].Split("->") | |
$branch = $parts[0].Trim() | |
$channel = $parts[1].Trim() | |
if ($map.ContainsKey($branch)) { | |
$map[$branch] = $map[$branch] + $channel | |
} | |
else { | |
$map[$branch] = @($channel) | |
} | |
} | |
return $map | |
} | |
function Parse-Subscriptions([string]$filter) { | |
$output = Invoke-Expression "& darc get-subscriptions $filter" | |
$urlPattern = "https://[a-z0-9./-]+" | |
$channelPattern = "[a-z0-9. ]+" | |
$headerPattern = "($urlPattern)\s+\(($channelPattern)\)" | |
$all = @() | |
$index = 0 | |
$inRecord = $false; | |
$record = @{ } | |
while ($index -lt $output.Length) { | |
$line = $output[$index] | |
if ($line -match $headerPattern) { | |
if ($inRecord) { | |
$all += $record | |
$record = @{ } | |
} | |
$inRecord = $true | |
$record.RepoUrl = $Matches.1 | |
$record.Channel = $Matches.2 | |
$items = $record.RepoUrl.Split('/') | |
$record.RepoName = $items[$items.Length - 1] | |
$record.RepoOrg = $items[$items.Length - 2] | |
$record.Commit = "" | |
} | |
elseif ($line -match "Last Build: .* \(([a-z0-9]+)\)") { | |
$record.Commit = $Matches.1 | |
} | |
$index++ | |
} | |
if ($inRecord) { | |
$all += $record | |
} | |
return $all | |
} | |
function Print-Summary([string]$branch) { | |
$all = Parse-Subscriptions " --target-repo dotnet/sdk --target-branch release/$branch" | |
Write-Host $branch | |
Write-Host "=====" | |
foreach ($table in $all) { | |
$repoName = $table.RepoName | |
$repoOrg = $table.RepoOrg | |
$channel = $table.Channel | |
if ($script:bigMap.ContainsKey($repoName)) { | |
$map = $script:bigMap[$repoName] | |
foreach ($key in $map.Keys) { | |
$value = $map[$key] | |
if ($value.Contains($channel)) { | |
[int]$time = (Get-TimeSinceCommit $table).TotalDays | |
Write-Host "Repository: $repoName" | |
Write-Host "Branch: $key" | |
Write-Host "Channel: $channel" | |
Write-Host "Last Update: $time days" | |
Write-Host "Last Commit: https://github.com/$repoOrg/$repoName/commits/$($table.Commit)" | |
Write-Host | |
} | |
} | |
} | |
} | |
} | |
function Get-TimeSinceCommit($table) { | |
if ([string]::IsNullOrEmpty($table.Commit)) { | |
Write-Host "No commit for $($table.RepoOrg)/$($table.RepoName)" | |
return [TimeSpan]::FromDays(100) | |
} | |
$uri = "https://api.github.com/repos/$($table.RepoOrg)/$($table.RepoName)/commits/$($table.Commit)" | |
try { | |
Write-Debug $uri | |
$json = Invoke-WebRequest -Uri $uri | |
$data = ConvertFrom-Json $json | |
$now = [DateTime]::UtcNow | |
$committed = [DateTime]$data.commit.committer.date | |
return $now - $committed | |
} | |
catch { | |
Write-Host "Cannot get commit $uri" | |
Write-Host $_ | |
return [TimeSpan]::FromDays(100) | |
} | |
} | |
function Print-BigMap() { | |
Write-Host "Big Map" | |
foreach ($repo in $bigMap.Keys) { | |
Write-Host $repo | |
$table = $bigMap[$repo] | |
foreach ($branch in $table.Keys) { | |
Write-Host "$branch - $($table[$branch])" | |
} | |
} | |
} | |
try { | |
$script:bigMap = @{} | |
$script:bigMap.roslyn = Parse-Channels "roslyn" | |
$script:bigMap.razor = Parse-Channels "razor" | |
# Print-BigMap | |
Print-Summary "7.0.2xx" | |
Print-Summary "7.0.3xx" | |
# Print-Summary "8.0.1xx" | |
exit 0 | |
} | |
catch { | |
Write-Host $_ | |
Write-Host $_.Exception | |
Write-Host $_.ScriptStackTrace | |
exit 1 | |
} | |
finally { | |
Pop-Location | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment