Skip to content

Commit 27ecb45

Browse files
Add ShowRateLimit option to display API rate limits before and after script execution
1 parent 8649c46 commit 27ecb45

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ inputs:
5353
description: Show the output of the script.
5454
required: false
5555
default: 'false'
56+
ShowRateLimit:
57+
description: Show GitHub API rate limit information before and after script execution.
58+
required: false
59+
default: 'false'
5660
ErrorView:
5761
description: Configure the PowerShell `$ErrorView` variable. You can use full names ('NormalView', 'CategoryView', 'ConciseView', 'DetailedView'). It matches on partials.
5862
required: false
@@ -91,6 +95,7 @@ runs:
9195
PSMODULE_GITHUB_SCRIPT_INPUT_ShowInfo: ${{ inputs.ShowInfo }}
9296
PSMODULE_GITHUB_SCRIPT_INPUT_ShowOutput: ${{ inputs.ShowOutput }}
9397
PSMODULE_GITHUB_SCRIPT_INPUT_Prerelease: ${{ inputs.Prerelease }}
98+
PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit: ${{ inputs.ShowRateLimit }}
9499
PSMODULE_GITHUB_SCRIPT_INPUT_ErrorView: ${{ inputs.ErrorView }}
95100
PSMODULE_GITHUB_SCRIPT_INPUT_PreserveCredentials: ${{ inputs.PreserveCredentials }}
96101
run: |
@@ -101,8 +106,12 @@ runs:
101106
try {
102107
${{ github.action_path }}/src/init.ps1
103108
${{ github.action_path }}/src/info.ps1
109+
$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Pre'
110+
${{ github.action_path }}/src/ratelimit.ps1
104111
${{ inputs.Script }}
105112
${{ github.action_path }}/src/outputs.ps1
113+
$env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL = 'Post'
114+
${{ github.action_path }}/src/ratelimit.ps1
106115
}
107116
finally {
108117
${{ github.action_path }}/src/clean.ps1

src/ratelimit.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Requires -Modules GitHub
2+
3+
[CmdletBinding()]
4+
param()
5+
6+
$scriptName = $MyInvocation.MyCommand.Name
7+
Write-Debug "[$scriptName] - Start"
8+
9+
try {
10+
if ($env:PSMODULE_GITHUB_SCRIPT_INPUT_ShowRateLimit -ne 'true') {
11+
return
12+
}
13+
14+
$fenceTitle = $env:PSMODULE_GITHUB_SCRIPT_INPUT_Name
15+
$label = $env:PSMODULE_GITHUB_SCRIPT_RATELIMIT_LABEL
16+
17+
$fenceStart = "┏━━┫ $fenceTitle - Rate Limit ($label) ┣━━━━━━━━┓"
18+
Write-Output $fenceStart
19+
20+
LogGroup " - Rate Limit ($label)" {
21+
Get-GitHubRateLimit | Format-Table -AutoSize | Out-String
22+
}
23+
24+
$fenceEnd = '' + ('' * ($fenceStart.Length - 2)) + ''
25+
Write-Output $fenceEnd
26+
} catch {
27+
throw $_
28+
}
29+
30+
Write-Debug "[$scriptName] - End"

0 commit comments

Comments
 (0)