@@ -16,26 +16,51 @@ jobs:
16
16
- name : Process comment
17
17
shell : pwsh
18
18
run : |
19
- $payload = echo $env:PAYLOAD | ConvertFrom-Json -AsHashtable
19
+ $payload = Write-Output $env:PAYLOAD | ConvertFrom-Json -AsHashtable
20
20
if (!$payload.comment -or !$payload.comment.body) {
21
- Write-Host "Empty comment, returning.. ."
21
+ Write-Host "Skipping: empty comment ."
22
22
return
23
23
}
24
24
$body = $payload.comment.body.Trim().ToLowerInvariant()
25
25
$expected = '/pr requestmerge'
26
26
if ($body -ne $expected) {
27
- Write-Host "Comment did not equal '$expected', skipping.. ."
27
+ Write-Host "Skipping: comment did not equal '$expected'."
28
28
return
29
29
}
30
30
$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
36
63
}
37
64
env :
38
65
PAYLOAD : ${{ toJson(github.event) }}
39
66
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
40
-
41
-
0 commit comments