11import type { Finding } from "./types.d.js" ;
22import process from "node:process" ;
33import core from "@actions/core" ;
4- import { Octokit } from '@octokit/core' ;
4+ import { Octokit } from "@octokit/core" ;
5+ import { throttling } from "@octokit/plugin-throttling" ;
56import { toFindingsMap } from "./toFindingsMap.js"
67import { closeIssueForFinding } from "./closeIssueForFinding.js" ;
78import { openIssueForFinding } from "./openIssueForFinding.js" ;
9+ const OctokitWithThrottling = Octokit . plugin ( throttling ) ;
810
911export default async function ( ) {
1012 core . info ( "Started 'file' action" ) ;
@@ -19,7 +21,25 @@ export default async function () {
1921 const findingsMap = toFindingsMap ( findings ) ;
2022 const cachedFindingsMap = toFindingsMap ( cachedFindings ) ;
2123
22- const octokit = new Octokit ( { auth : token } ) ;
24+ const octokit = new OctokitWithThrottling ( {
25+ auth : token ,
26+ throttle : {
27+ onRateLimit : ( retryAfter , options , octokit , retryCount ) => {
28+ octokit . log . warn ( `Request quota exhausted for request ${ options . method } ${ options . url } ` ) ;
29+ if ( retryCount < 3 ) {
30+ octokit . log . info ( `Retrying after ${ retryAfter } seconds!` ) ;
31+ return true ;
32+ }
33+ } ,
34+ onSecondaryRateLimit : ( retryAfter , options , octokit , retryCount ) => {
35+ octokit . log . warn ( `Secondary rate limit hit for request ${ options . method } ${ options . url } ` ) ;
36+ if ( retryCount < 3 ) {
37+ octokit . log . info ( `Retrying after ${ retryAfter } seconds!` ) ;
38+ return true ;
39+ }
40+ } ,
41+ }
42+ } ) ;
2343 const closedIssueUrls = [ ] ;
2444 const openedIssueUrls = [ ] ;
2545 const repeatIssueUrls = [ ] ;
0 commit comments