|
1 | 1 | require('dotenv').config() |
2 | 2 | const { Octokit } = require("@octokit/core") |
| 3 | +const { throttling } = require("@octokit/plugin-throttling") |
3 | 4 |
|
4 | 5 | module.exports = async function (filepath) { |
5 | 6 | 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 | + }, |
8 | 24 | }) |
9 | 25 | const { repository: { object: { history } } } = await octokit.graphql( |
10 | 26 | `query ($filepath: String!) { |
@@ -50,7 +66,7 @@ module.exports = async function (filepath) { |
50 | 66 |
|
51 | 67 | if (history.totalCount > 100) { |
52 | 68 | // 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) |
54 | 70 | } |
55 | 71 |
|
56 | 72 | const authors = history.nodes.flatMap(({ authors }) => { |
|
0 commit comments