Skip to content

Commit f4775a9

Browse files
use throttling plugin in get_contributors queries
1 parent 3f56459 commit f4775a9

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

scripts/get_contributors.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
require('dotenv').config()
22
const { Octokit } = require("@octokit/core")
3+
const { throttling } = require("@octokit/plugin-throttling")
34

45
module.exports = async function (filepath) {
56
const unixStyleFilepath = filepath.replace(/\\/g, "/")
6-
const octokit = new Octokit({
7-
auth: process.env.TOKEN
7+
const EnhancedOctokit = Octokit.plugin(throttling)
8+
const octokit = new EnhancedOctokit({
9+
auth: process.env.TOKEN,
10+
throttle: {
11+
onRateLimit: (retryAfter, options, octokit, retryCount) => {
12+
if (retryCount <= 1) {
13+
octokit.log.info(`Request quota reached for ${options.method} ${options.url}, retrying after ${retryAfter} seconds`)
14+
return true
15+
}
16+
octokit.log.warn(`Request quota exhausted for ${options.method} ${options.url}`)
17+
return false
18+
},
19+
onSecondaryRateLimit: (retryAfter, options, octokit) => {
20+
// does not retry, only logs a warning
21+
octokit.log.warn(`SecondaryRateLimit hit for request ${options.method} ${options.url}`)
22+
},
23+
},
824
})
925
const { repository: { object: { history } } } = await octokit.graphql(
1026
`query ($filepath: String!) {
@@ -50,7 +66,7 @@ module.exports = async function (filepath) {
5066

5167
if (history.totalCount > 100) {
5268
// Needs addressing properly, but deferring to avoid merge conflicts with https://github.com/InnerSourceCommons/InnerSourceLearningPath/pull/380
53-
console.warn('This script needs updating to handle >100 commits')
69+
console.warn('This script needs updating to handle >100 commits: ', unixStyleFilepath)
5470
}
5571

5672
const authors = history.nodes.flatMap(({ authors }) => {

0 commit comments

Comments
 (0)