Skip to content

Commit

Permalink
Add divide by zero safety
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr authored and azure-sdk committed Nov 7, 2024
1 parent 38fc808 commit effc6eb
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ steps:
foreach ($property in $response.resources.PSObject.Properties)
{
$labels = @{ user= $env:GITHUB_USER; resource= $property.Name }
$remaining = $property.Value.remaining
$limit = $property.Value.limit
$used = $property.Value.used
$percent = $used / $limit * 100
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_remaining_total"; value= $remaining; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)"
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_limit_total"; value= $limit; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)"
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_used_total"; value= $used; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)"
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_used_percent"; value= $percent; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)"
if ($limit -ne 0) {
$percent = $used / $limit * 100
Write-Host "logmetric: $( [ordered]@{ name= "github_ratelimit_used_percent"; value= $percent; timestamp= $timestamp; labels= $labels } | ConvertTo-Json -Compress)"
}
}
displayName: Check GitHub Rate Limit
env:
Expand Down

0 comments on commit effc6eb

Please sign in to comment.