@@ -16,26 +16,51 @@ jobs:
1616 - name : Process comment
1717 shell : pwsh
1818 run : |
19- $payload = echo $env:PAYLOAD | ConvertFrom-Json -AsHashtable
19+ $payload = Write-Output $env:PAYLOAD | ConvertFrom-Json -AsHashtable
2020 if (!$payload.comment -or !$payload.comment.body) {
21- Write-Host "Empty comment, returning.. ."
21+ Write-Host "Skipping: empty comment ."
2222 return
2323 }
2424 $body = $payload.comment.body.Trim().ToLowerInvariant()
2525 $expected = '/pr requestmerge'
2626 if ($body -ne $expected) {
27- Write-Host "Comment did not equal '$expected', skipping.. ."
27+ Write-Host "Skipping: comment did not equal '$expected'."
2828 return
2929 }
3030 $label = 'MergeRequested'
31- Write-Host "gh pr edit $($payload.issue.number) --add-label `"$label`""
32- gh pr edit $payload.issue.html_url --add-label "$label"
33- if ($LASTEXITCODE) {
34- Write-Warning "Failed to add label"
35- exit $LASTEXITCODE
31+
32+ $retryCount = 0
33+ $maxRetries = 5
34+ $retryDelay = 5 # Initial retry delay in seconds
35+
36+ while ($retryCount -lt $maxRetries) {
37+
38+ Write-Host "Attempt $($retryCount+1) out of $($maxRetries): gh pr edit $($payload.issue.number) --add-label `"$label`""
39+ gh pr edit $payload.issue.html_url --add-label "$label"
40+
41+ if ($LASTEXITCODE -eq 0) {
42+ Write-Host "Label added successfully on attempt $($retryCount+1) out of $($maxRetries)."
43+ break
44+ } else {
45+ Write-Warning "Failed to add label on attempt $($retryCount+1) out of $($maxRetries)."
46+ $retryCount++
47+ if ($retryCount -lt $maxRetries) {
48+ # $retryDelay = 5 exponential backoff in seconds:
49+ # attempt 2: 5 = 1*5
50+ # attempt 3: 10 = 2*5
51+ # attempt 4: 20 = 4*5
52+ # attempt 5: 40 = 8*5
53+ Write-Host "Sleeping for $retryDelay seconds..."
54+ Start-Sleep -Seconds $retryDelay
55+ $retryDelay = $retryDelay * 2
56+ }
57+ }
58+ }
59+
60+ if ($retryCount -ge $maxRetries) {
61+ Write-Error "Max retry attempts of $maxRetries exhausted. Exiting with error ('exit 1')."
62+ exit 1
3663 }
3764 env :
3865 PAYLOAD : ${{ toJson(github.event) }}
3966 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
40-
41-
0 commit comments