mirror of
https://dev.azure.com/effectory/Survey%20Software/_git/Cloud%20Engineering
synced 2026-02-27 10:45:02 +01:00
Merged PR 58470: Added scripts for listing blobs and storage tables
Added scripts for listing blobs and storage tables Related work items: #106533
This commit is contained in:
77
Powershell/Lists/Azure/AzureStorageBlobList.ps1
Normal file
77
Powershell/Lists/Azure/AzureStorageBlobList.ps1
Normal file
@@ -0,0 +1,77 @@
|
||||
param (
|
||||
[string] $subscriptionId = "",
|
||||
[string] $resourcegroupName = "",
|
||||
[string] $storageAccountName = ""
|
||||
)
|
||||
|
||||
if (("" -eq $subscriptionId) -or ("" -eq $resourcegroupName) -or ("" -eq $storageAccountName)) {
|
||||
throw "Parameter(s) missing."
|
||||
}
|
||||
else {
|
||||
Write-Host "Processing subscription [$subscriptionId], resource group [$resourcegroupName], storage account [$storageAccountName]"
|
||||
}
|
||||
|
||||
# .\AzureStoragebloblist.ps1 -subscriptionId "7feeb150-9ee0-4aea-992a-5f3a89d933e6" -resourcegroupName "results-activity" -storageAccountName "effactivity"
|
||||
# .\AzureStoragebloblist.ps1 -subscriptionId "7feeb150-9ee0-4aea-992a-5f3a89d933e6" -resourcegroupName "Results" -storageAccountName "myeffectoryresults"
|
||||
# .\AzureStoragebloblist.ps1 -subscriptionId "a134faf1-7a89-4f2c-8389-06d00bd5e2a7" -resourcegroupName "Default-Storage-WestEurope" -storageAccountName "ecestore"
|
||||
|
||||
class BlobCheck {
|
||||
[string] $SubscriptionId = ""
|
||||
[string] $SubscriptionName = ""
|
||||
[string] $ResourcegroupName = ""
|
||||
[string] $StorageAccountName = ""
|
||||
[string] $ContainerName = ""
|
||||
[string] $BlobName = ""
|
||||
[string] $LastModifiedDate = ""
|
||||
}
|
||||
|
||||
[int] $maxCount = 100000
|
||||
$containerToken = $null
|
||||
$blobToken = $null
|
||||
|
||||
[string] $date = Get-Date -Format "yyyy-MM-dd HHmm"
|
||||
$fileName = ".\$date - $storageAccountName - bloblist.csv"
|
||||
|
||||
$subscription = Set-AzContext -SubscriptionId $subscriptionId
|
||||
$storageAccount = Get-AzStorageAccount -ResourceGroupName $resourcegroupName -Name $storageAccountName
|
||||
|
||||
do {
|
||||
|
||||
$containers = Get-AzStorageContainer -Context $storageAccount.Context -MaxCount $maxCount -ContinuationToken $containerToken
|
||||
|
||||
foreach ($container in $containers) {
|
||||
|
||||
|
||||
|
||||
do {
|
||||
[BlobCheck[]]$Result = @()
|
||||
|
||||
$blobList = Get-AzStorageBlob -Container $Container.Name -Context $storageAccount.Context -MaxCount $maxCount -ContinuationToken $blobToken #-Prefix "projects"
|
||||
if ($blobList.Length -le 0) {
|
||||
Break;
|
||||
}
|
||||
|
||||
foreach($blob in $blobList) {
|
||||
[BlobCheck] $blobCheck = [BlobCheck]::new()
|
||||
$blobCheck.SubscriptionId = $subscription.Subscription.Id
|
||||
$blobCheck.SubscriptionName = $subscription.Subscription.Name
|
||||
$blobCheck.ResourcegroupName = $resourcegroupName
|
||||
$blobCheck.StorageAccountName = $storageAccountName
|
||||
$blobCheck.ContainerName = $container.Name
|
||||
$blobCheck.BlobName = $blob.Name
|
||||
$blobCheck.LastModifiedDate = $blob.LastModified
|
||||
$Result += $blobCheck
|
||||
}
|
||||
$Result | Export-Csv -Path $fileName -NoTypeInformation -Append
|
||||
$blobToken = $blobList[$blobList.Count -1].ContinuationToken;
|
||||
}
|
||||
while ($null -ne $blobToken)
|
||||
}
|
||||
|
||||
if ($containers.Length -le 0)
|
||||
{
|
||||
Break;
|
||||
}
|
||||
$containerToken = $containers[$containers.Count -1].ContinuationToken;
|
||||
}
|
||||
while ($null -ne $containerToken)
|
||||
8864
Powershell/Lists/Azure/AzureStorageTableQuery.ps1
Normal file
8864
Powershell/Lists/Azure/AzureStorageTableQuery.ps1
Normal file
File diff suppressed because it is too large
Load Diff
218
Powershell/Lists/DevOps/renovate-stats.ps1
Normal file
218
Powershell/Lists/DevOps/renovate-stats.ps1
Normal file
@@ -0,0 +1,218 @@
|
||||
# PowerShell script to analyze renovate PRs across repositories with detailed statistics
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$Organization = "effectory",
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$Project = "Survey Software",
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$PAT,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$OutputFile = "RenovatePRs_Stats_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
|
||||
)
|
||||
|
||||
|
||||
function Write-Output-Both {
|
||||
param (
|
||||
[string]$Message,
|
||||
[string]$ForegroundColor = "White",
|
||||
[switch]$ConsoleOnly
|
||||
)
|
||||
|
||||
Write-Host $Message -ForegroundColor $ForegroundColor
|
||||
if (-not $ConsoleOnly) {
|
||||
Add-Content -Path $OutputFile -Value $Message
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Set-Content -Path $OutputFile -Value "Renovate Pull Requests Statistics - $(Get-Date)`n"
|
||||
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$PAT"))
|
||||
$headers = @{
|
||||
Authorization = "Basic $base64AuthInfo"
|
||||
}
|
||||
|
||||
|
||||
$reposUrl = "https://dev.azure.com/$Organization/$Project/_apis/git/repositories?api-version=6.0"
|
||||
$repositories = Invoke-RestMethod -Uri $reposUrl -Method Get -Headers $headers
|
||||
|
||||
|
||||
$repoStats = @()
|
||||
$reposWithoutRenovate = @()
|
||||
$disabledRepos = @()
|
||||
|
||||
|
||||
foreach ($repo in $repositories.value) {
|
||||
$repoName = $repo.name
|
||||
$repoId = $repo.id
|
||||
Write-Output-Both "Analyzing repository: $repoName" -ForegroundColor Gray -ConsoleOnly
|
||||
|
||||
|
||||
$isDisabled = $repo.isDisabled -eq $true
|
||||
$repoDetailsUrl = "https://dev.azure.com/$Organization/$Project/_apis/git/repositories/$repoId`?api-version=6.0"
|
||||
try {
|
||||
$repoDetails = Invoke-RestMethod -Uri $repoDetailsUrl -Method Get -Headers $headers
|
||||
$isLocked = $repoDetails.isLocked -eq $true
|
||||
}
|
||||
catch {
|
||||
Write-Output-Both " Could not retrieve repository details. Assuming not locked." -ForegroundColor Yellow -ConsoleOnly
|
||||
$isLocked = $false
|
||||
}
|
||||
|
||||
if ($isDisabled -or $isLocked) {
|
||||
$status = if ($isDisabled) { "DISABLED" } elseif ($isLocked) { "LOCKED" } else { "UNKNOWN" }
|
||||
Write-Output-Both " Repository status: $status - Skipping analysis" -ForegroundColor Yellow -ConsoleOnly
|
||||
|
||||
$disabledRepo = [PSCustomObject]@{
|
||||
Repository = "$repoName ($status)"
|
||||
TotalRenovatePRs = "N/A"
|
||||
OpenPRs = "N/A"
|
||||
CompletedPRs = "N/A"
|
||||
AbandonedPRs = "N/A"
|
||||
LastCreatedDate = "N/A"
|
||||
LastCompletedDate = "N/A"
|
||||
LatestOpenBranch = "N/A"
|
||||
LatestCompletedBranch = "N/A"
|
||||
LastCompletedPRTitle = "N/A"
|
||||
RepoStatus = $status
|
||||
}
|
||||
$disabledRepos += $disabledRepo
|
||||
continue
|
||||
}
|
||||
|
||||
$prsUrl = "https://dev.azure.com/$Organization/$Project/_apis/git/repositories/$repoId/pullrequests`?api-version=6.0&searchCriteria.status=all"
|
||||
try {
|
||||
$pullRequests = Invoke-RestMethod -Uri $prsUrl -Method Get -Headers $headers
|
||||
$renovatePRs = $pullRequests.value | Where-Object { $_.sourceRefName -like "refs/heads/renovate/*" }
|
||||
|
||||
if ($renovatePRs.Count -gt 0) {
|
||||
$openPRs = $renovatePRs | Where-Object { $_.status -eq "active" }
|
||||
$completedPRs = $renovatePRs | Where-Object { $_.status -eq "completed" }
|
||||
$abandonedPRs = $renovatePRs | Where-Object { $_.status -eq "abandoned" }
|
||||
|
||||
$openCount = $openPRs.Count
|
||||
$completedCount = $completedPRs.Count
|
||||
$abandonedCount = $abandonedPRs.Count
|
||||
|
||||
$latestOpen = $openPRs | Sort-Object creationDate -Descending | Select-Object -First 1
|
||||
$latestCompleted = $completedPRs | Sort-Object closedDate -Descending | Select-Object -First 1
|
||||
$latestCreated = $renovatePRs | Sort-Object creationDate -Descending | Select-Object -First 1
|
||||
$lastCreatedDate = if ($latestCreated) { $latestCreated.creationDate } else { "N/A" }
|
||||
$lastCompletedDate = if ($latestCompleted) { $latestCompleted.closedDate } else { "N/A" }
|
||||
$lastCompletedPRTitle = if ($latestCompleted) { $latestCompleted.title } else { "N/A" }
|
||||
$latestOpenBranch = if ($latestOpen) { ($latestOpen.sourceRefName -replace "refs/heads/", "") } else { "N/A" }
|
||||
$latestCompletedBranch = if ($latestCompleted) { ($latestCompleted.sourceRefName -replace "refs/heads/", "") } else { "N/A" }
|
||||
|
||||
$repoStat = [PSCustomObject]@{
|
||||
Repository = $repoName
|
||||
TotalRenovatePRs = $renovatePRs.Count
|
||||
OpenPRs = $openCount
|
||||
CompletedPRs = $completedCount
|
||||
AbandonedPRs = $abandonedCount
|
||||
LastCreatedDate = $lastCreatedDate
|
||||
LastCompletedDate = $lastCompletedDate
|
||||
LatestOpenBranch = $latestOpenBranch
|
||||
LatestCompletedBranch = $latestCompletedBranch
|
||||
LastCompletedPRTitle = $lastCompletedPRTitle
|
||||
RepoStatus = "ACTIVE"
|
||||
SortDate = if ($lastCreatedDate -eq "N/A") { [DateTime]::MinValue } else { [DateTime]::Parse($lastCreatedDate) }
|
||||
}
|
||||
|
||||
$repoStats += $repoStat
|
||||
} else {
|
||||
$reposWithoutRenovate += $repoName
|
||||
$repoStat = [PSCustomObject]@{
|
||||
Repository = $repoName
|
||||
TotalRenovatePRs = 0
|
||||
OpenPRs = 0
|
||||
CompletedPRs = 0
|
||||
AbandonedPRs = 0
|
||||
LastCreatedDate = "N/A"
|
||||
LastCompletedDate = "N/A"
|
||||
LatestOpenBranch = "N/A"
|
||||
LatestCompletedBranch = "N/A"
|
||||
LastCompletedPRTitle = "N/A"
|
||||
RepoStatus = "ACTIVE"
|
||||
SortDate = [DateTime]::MinValue
|
||||
}
|
||||
$repoStats += $repoStat
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Output-Both " Error accessing pull requests for repository: $_" -ForegroundColor Red -ConsoleOnly
|
||||
$disabledRepo = [PSCustomObject]@{
|
||||
Repository = "$repoName (ERROR)"
|
||||
TotalRenovatePRs = "Error"
|
||||
OpenPRs = "Error"
|
||||
CompletedPRs = "Error"
|
||||
AbandonedPRs = "Error"
|
||||
LastCreatedDate = "Error"
|
||||
LastCompletedDate = "Error"
|
||||
LatestOpenBranch = "Error"
|
||||
LatestCompletedBranch = "Error"
|
||||
LastCompletedPRTitle = "Error"
|
||||
RepoStatus = "ERROR"
|
||||
}
|
||||
$disabledRepos += $disabledRepo
|
||||
}
|
||||
}
|
||||
|
||||
Write-Output-Both "`n===== RENOVATE PULL REQUEST STATISTICS BY REPOSITORY (SORTED BY LAST CREATED DATE) =====" -ForegroundColor Green
|
||||
if ($repoStats.Count -gt 0) {
|
||||
$sortedStats = $repoStats | Sort-Object -Property SortDate -Descending
|
||||
$displayStats = $sortedStats | Select-Object Repository, TotalRenovatePRs, OpenPRs, CompletedPRs, AbandonedPRs,
|
||||
@{Name="LastCreated"; Expression={
|
||||
if ($_.LastCreatedDate -eq "N/A" -or $_.LastCreatedDate -eq "Error") { $_.LastCreatedDate }
|
||||
else { [DateTime]::Parse($_.LastCreatedDate).ToString("yyyy-MM-dd") }
|
||||
}},
|
||||
@{Name="LastCompleted"; Expression={
|
||||
if ($_.LastCompletedDate -eq "N/A" -or $_.LastCompletedDate -eq "Error") { $_.LastCompletedDate }
|
||||
else { [DateTime]::Parse($_.LastCompletedDate).ToString("yyyy-MM-dd") }
|
||||
}},
|
||||
LatestOpenBranch, LatestCompletedBranch, LastCompletedPRTitle
|
||||
|
||||
$displayStats | Export-Csv -Path "$($OutputFile).csv" -NoTypeInformation
|
||||
# Add a note to the original output file
|
||||
Add-Content -Path $OutputFile -Value "Full data available in: $($OutputFile).csv"
|
||||
|
||||
$statsTable = $displayStats | Format-Table -Property Repository, TotalRenovatePRs, OpenPRs, CompletedPRs, AbandonedPRs, LastCreated, LastCompleted, LatestCompletedBranch, LastCompletedPRTitle | Out-String
|
||||
Add-Content -Path $OutputFile -Value $statsTable.Trim() # Trim to remove extra whitespace
|
||||
$displayStats | Format-Table -AutoSize
|
||||
|
||||
|
||||
$totalRepos = $repositories.value.Count
|
||||
$reposWithRenovate = ($repoStats | Where-Object { $_.TotalRenovatePRs -gt 0 }).Count
|
||||
$reposDisabledOrLocked = $disabledRepos.Count
|
||||
$activeRepos = $totalRepos - $reposDisabledOrLocked
|
||||
|
||||
$percentWithRenovate = if ($activeRepos -gt 0) { [math]::Round(($reposWithRenovate / $activeRepos) * 100, 2) } else { 0 }
|
||||
|
||||
$totalPRs = ($repoStats | Measure-Object -Property TotalRenovatePRs -Sum).Sum
|
||||
$totalOpenPRs = ($repoStats | Measure-Object -Property OpenPRs -Sum).Sum
|
||||
$totalCompletedPRs = ($repoStats | Measure-Object -Property CompletedPRs -Sum).Sum
|
||||
$totalAbandonedPRs = ($repoStats | Measure-Object -Property AbandonedPRs -Sum).Sum
|
||||
|
||||
Write-Output-Both "`n===== SUMMARY STATISTICS =====" -ForegroundColor Cyan
|
||||
Write-Output-Both "Total repositories: $totalRepos"
|
||||
Write-Output-Both "Disabled, locked, or error repositories: $reposDisabledOrLocked"
|
||||
Write-Output-Both "Active repositories: $activeRepos"
|
||||
Write-Output-Both "Active repositories with renovate PRs: $reposWithRenovate ($percentWithRenovate%)"
|
||||
Write-Output-Both "Active repositories without renovate PRs: $($activeRepos - $reposWithRenovate) ($(100 - $percentWithRenovate)%)"
|
||||
Write-Output-Both "`nTotal renovate PRs: $totalPRs"
|
||||
Write-Output-Both "Total open renovate PRs: $totalOpenPRs"
|
||||
Write-Output-Both "Total completed renovate PRs: $totalCompletedPRs"
|
||||
Write-Output-Both "Total abandoned renovate PRs: $totalAbandonedPRs"
|
||||
|
||||
if ($disabledRepos.Count -gt 0) {
|
||||
Write-Output-Both "`n===== DISABLED/LOCKED/ERROR REPOSITORIES (NOT INCLUDED IN MAIN REPORT) =====" -ForegroundColor Yellow
|
||||
$disabledList = $disabledRepos | ForEach-Object { $_.Repository }
|
||||
Write-Output-Both ($disabledList -join "`n")
|
||||
}
|
||||
} else {
|
||||
Write-Output-Both "No active repositories found." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Output-Both "`nReport saved to: $OutputFile" -ForegroundColor Cyan
|
||||
Reference in New Issue
Block a user