forked from coderabbitai/ai-pr-reviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoctokit.ts
44 lines (41 loc) · 1.29 KB
/
octokit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {getInput, warning} from '@actions/core'
import {Octokit} from '@octokit/action'
import {retry} from '@octokit/plugin-retry'
import {throttling} from '@octokit/plugin-throttling'
const token = getInput('token') || process.env.GITHUB_TOKEN
const RetryAndThrottlingOctokit = Octokit.plugin(throttling, retry)
export const octokit = new RetryAndThrottlingOctokit({
auth: `token ${token}`,
throttle: {
onRateLimit: (
retryAfter: number,
options: any,
_o: any,
retryCount: number
) => {
warning(
`Request quota exhausted for request ${options.method} ${options.url}
Retry after: ${retryAfter} seconds
Retry count: ${retryCount}
`
)
if (retryCount <= 3) {
warning(`Retrying after ${retryAfter} seconds!`)
return true
}
},
onSecondaryRateLimit: (retryAfter: number, options: any) => {
warning(
`SecondaryRateLimit detected for request ${options.method} ${options.url} ; retry after ${retryAfter} seconds`
)
// if we are doing a POST method on /repos/{owner}/{repo}/pulls/{pull_number}/reviews then we shouldn't retry
if (
options.method === 'POST' &&
options.url.match(/\/repos\/.*\/.*\/pulls\/.*\/reviews/)
) {
return false
}
return true
}
}
})