Skip to content

Commit

Permalink
Add logging and more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos committed Jan 7, 2025
1 parent caf7d32 commit 96aeb61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/dependents.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ function GetDependentsForRepo {
$url = "https://github.com/$owner/$repo/network/dependents"
$content = Invoke-WebRequest -Uri $url -UseBasicParsing

# check for 404 status code
if ($response.StatusCode -eq 404) {
Write-Host "404 Not Found: The repository or owner does not exist."
return ""
}

# find the text where it says "10 repositories"
$regex = [regex]"\d{1,3}(,\d{1,3})*\s*\n\s*Repositories"
$myMatches = $regex.Matches($content.Content)
# check for regex matches
if ($myMatches.Count -eq 1) {
if ($myMatches.Count -eq 1) {
# replace all spaces with nothing
$found = $myMatches[0].Value.Replace(" ", "").Replace("`n", "").Replace("Repositories", "")
Write-Debug "Found match: $found"

return $found
}
else {
Expand All @@ -28,8 +34,12 @@ function GetDependentsForRepo {
}
}
catch {
Write-Host "Error loading dependents for owner [$owner] and repo [$repo]:"
Write-Host "$_"
if ($_.Exception.Response.StatusCode -eq 404) {
Write-Host "404 Not Found: The repository or owner does not exist for [$($owner)/$(repo)]."
} else {
Write-Host "Error loading dependents for owner [$($owner)/$($repo)]:"
Write-Host "$_"
}
return ""
}
}
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/library.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,20 @@ function ApiCall {

$rateLimitRemaining = $result.Headers["X-RateLimit-Remaining"]
$rateLimitReset = $result.Headers["X-RateLimit-Reset"]
$rateLimitUsed = $result.Headers["X-Ratelimit-Used"]
if ($rateLimitRemaining -And $rateLimitRemaining[0] -lt 100) {
# convert rateLimitReset from epoch to ms
$rateLimitResetInt = [int]$rateLimitReset[0]
$oUNIXDate=(Get-Date 01.01.1970)+([System.TimeSpan]::fromseconds($rateLimitResetInt))
$rateLimitReset = $oUNIXDate - [DateTime]::UtcNow
if ($rateLimitReset.TotalMilliseconds -gt 0) {
Write-Host ""
if ($rateLimitReset.TotalSeconds > 1200) {
$message = "Rate limit is low or hit [$rateLimitRemaining], and we need to wait for [$([math]::Round($rateLimitReset.TotalSeconds, 0))] seconds before continuing, which would mean continuing at [$oUNIXDate UTC]. This is longer then 20 minutes, so we are stopping the execution"
if ($rateLimitReset.TotalSeconds -gt 1200) {
$message = "Rate limit is low or hit (Remaining/Used) [$($rateLimitRemaining)/$($rateLimitUsed)], and we need to wait for [$([math]::Round($rateLimitReset.TotalSeconds, 0))] seconds before continuing, which would mean continuing at [$oUNIXDate UTC]. This is longer then 20 minutes, so we are stopping the execution"
Write-Message -message $message -logToSummary $true
throw $message
}
$message = "Rate limit is low or hit [$rateLimitRemaining], waiting for [$([math]::Round($rateLimitReset.TotalSeconds, 0))] seconds before continuing. Continuing at [$oUNIXDate UTC]"
$message = "Rate limit is low or hit (Remaining/Used) [$($rateLimitRemaining)/$($rateLimitUsed)], waiting for [$([math]::Round($rateLimitReset.TotalSeconds, 0))] seconds before continuing. Continuing at [$oUNIXDate UTC]"
Write-Message -message $message -logToSummary $true
Write-Host ""
Start-Sleep -Milliseconds $rateLimitReset.TotalMilliseconds
Expand Down Expand Up @@ -320,6 +321,7 @@ function SaveStatus {
$existingForks,
$failedForks
)
Write-Host "SaveStatus"
if ("" -ne "$($env:CI)") {
# We are running in CI, so let's pull before we overwrite the file
git pull --quiet | Out-Null
Expand Down Expand Up @@ -711,6 +713,8 @@ function GetFoundSecretCount {
[Parameter(Mandatory=$true)]
[string] $access_token_destination
)
Write-Message "Getting secret scanning alerts" -logToSummary $true

$url = "/orgs/$forkOrg/secret-scanning/alerts"

try {
Expand Down

0 comments on commit 96aeb61

Please sign in to comment.