-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoctokit.js
49 lines (39 loc) · 1.6 KB
/
octokit.js
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
45
46
47
48
49
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
const core = require('@actions/core')
const { GitHub, getOctokitOptions } = require('@actions/github/lib/utils')
const { retry } = require('@octokit/plugin-retry')
const { throttling } = require('@octokit/plugin-throttling')
const rateLimitRetries = 5
const secondaryRateLimitRetries = 5
module.exports = function client (token) {
const Octokit = GitHub.plugin(throttling, retry)
const options = getOctokitOptions(token)
options.log = {
debug: core.debug,
info: core.info,
warning: core.warning,
error: core.error
}
options.throttle = {
onRateLimit (retryAfter, options) {
core.info(`Rate limit triggered for request ${options.method} ${options.url} (attempt ${options.request.retryCount}/${rateLimitRetries})`)
if (options.request.retryCount < rateLimitRetries) {
core.info(`Retrying after ${retryAfter} seconds`)
return true
}
core.warning(`Exhausted rate limit retry count (${rateLimitRetries}) for ${options.method} ${options.url}`)
},
onSecondaryRateLimit (retryAfter, options) {
core.info(`Secondary rate limit triggered for request ${options.method} ${options.url} (attempt ${options.request.retryCount}/${secondaryRateLimitRetries})`)
if (options.request.retryCount < secondaryRateLimitRetries) {
core.info(`Retrying after ${retryAfter} seconds`)
return true
}
core.warning(`Exhausted secondary rate limit retry count (${secondaryRateLimitRetries}) for ${options.method} ${options.url}`)
}
}
return new Octokit(options)
}