@@ -133,31 +133,9 @@ export function getFilesPRs(forge, urlInfo, requestHeaders, prs) {
133133 } )
134134}
135135
136- // check the rate limit
137- async function checkRateLimit ( forge , requestHeaders ) {
138- // forges without a rate-limit endpoint skip this check
139- if ( ! forge . rateLimit ) {
140- return
141- }
142-
143- console . log ( "Check the rate limit" )
144-
145- // fetch the rate limit endpoint
146- const response = await fetch ( forge . rateLimit . url , { headers : requestHeaders } )
147- const data = await response . json ( )
148-
149- if ( ! response . ok ) {
150- throw new Error ( `Failed to get rate limits: [${ response . status } ] ${ response . statusText } : ${ data . message } ` )
151- }
152-
153- const remaining = forge . rateLimit . remaining ( data )
154- console . log ( "Rate limit remaining:" , remaining )
155- if ( remaining == 0 ) {
156- throw new Error ( "Rate limit reached!" )
157- }
158- }
159-
160- // check the rate limit comparing to PRs length (one files request each)
136+ // check the rate limit comparing to PRs length (one files request each); the
137+ // header rides on the list response, so the check costs no extra request (an
138+ // already-exhausted quota fails the list request itself)
161139function checkRateLimitFromPRs ( forge , prs , response ) {
162140 // get the rate limit header (forges without one skip the comparison)
163141 const remaining = forge . rateLimit ? response . headers . get ( forge . rateLimit . header ) : null
@@ -215,9 +193,8 @@ async function main(tab) {
215193 await clearTabResult ( tab . id )
216194
217195 try {
218- // load the stored API token, then check the forge rate limit
196+ // load the stored API token
219197 const requestHeaders = await loadAuthHeaders ( forge )
220- await checkRateLimit ( forge , requestHeaders )
221198
222199 // list pull requests (all pages), then keep those that touch the file
223200 const { items : prs , response } = await listAllPRs ( forge , urlInfo , requestHeaders )
0 commit comments