mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-01 01:10:34 +08:00
47 lines
1.4 KiB
PowerShell
47 lines
1.4 KiB
PowerShell
$totalClearedSize = 0
|
|
$cacheList = gh cache list --json id,ref,sizeInBytes | ConvertFrom-Json
|
|
$branchSet = @{}
|
|
git ls-remote --heads origin | ForEach-Object {
|
|
if ($_ -match 'refs/heads/(.+)$') { $branchSet[$matches[1]] = $true }
|
|
}
|
|
|
|
foreach ($cache in $cacheList) {
|
|
$shouldDelete = $false
|
|
|
|
if ($cache.ref -match "refs/pull/(\d+)/merge") {
|
|
$prNumber = $matches[1]
|
|
Write-Host "PR #${prNumber}: " -NoNewline
|
|
|
|
try {
|
|
$prStatus = (gh pr view $prNumber --json state | ConvertFrom-Json).state
|
|
Write-Host "$prStatus" -NoNewline
|
|
$shouldDelete = $prStatus -in @("MERGED", "CLOSED")
|
|
}
|
|
catch {
|
|
Write-Host "NOT FOUND" -NoNewline
|
|
$shouldDelete = $true
|
|
}
|
|
}
|
|
elseif ($cache.ref -match "refs/heads/(.+)" -and $matches[1] -ne "dev-v2") {
|
|
$branchName = $matches[1]
|
|
$exists = $branchSet.ContainsKey($branchName)
|
|
|
|
Write-Host "Branch '$branchName': $(if ($exists) { 'EXISTS' } else { 'DELETED' })" -NoNewline
|
|
$shouldDelete = -not $exists
|
|
}
|
|
else {
|
|
continue
|
|
}
|
|
|
|
if ($shouldDelete) {
|
|
Write-Host " -> DELETING"
|
|
gh cache delete $cache.id
|
|
$totalClearedSize += $cache.sizeInBytes
|
|
}
|
|
else {
|
|
Write-Host ""
|
|
}
|
|
}
|
|
|
|
Write-Output "Cleared size: $("{0:N2}" -f ($totalClearedSize / 1MB)) MB"
|