@@ -17,6 +17,7 @@ import {
1717import {
1818 showAndLogErrorMessage ,
1919 showAndLogInformationMessage ,
20+ showAndLogWarningMessage ,
2021} from "../../helpers" ;
2122import { DisposableObject } from "../../pure/disposable-object" ;
2223import {
@@ -38,6 +39,9 @@ import { DatabasePanelCommands } from "../../common/commands";
3839import { App } from "../../common/app" ;
3940import { getCodeSearchRepositories } from "../../variant-analysis/gh-api/gh-api-client" ;
4041import { QueryLanguage } from "../../common/query-language" ;
42+ import { retry } from "@octokit/plugin-retry" ;
43+ import { throttling } from "@octokit/plugin-throttling" ;
44+ import { Octokit } from "@octokit/rest" ;
4145
4246export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
4347 remoteDatabaseKind : string ;
@@ -402,10 +406,10 @@ export class DbPanel extends DisposableObject {
402406 progress . report ( { increment : 10 } ) ;
403407
404408 const repositories = await getCodeSearchRepositories (
405- this . app . credentials ,
406409 `${ codeSearchQuery } ${ languagePrompt } ` ,
407410 progress ,
408411 token ,
412+ await this . getOctokitForSearch ( ) ,
409413 ) ;
410414
411415 token . onCancellationRequested ( ( ) => {
@@ -499,4 +503,30 @@ export class DbPanel extends DisposableObject {
499503 ) ;
500504 }
501505 }
506+
507+ // since we don't have access to the extensions log methods we initialize octokit here
508+ private async getOctokitForSearch ( ) : Promise < Octokit > {
509+ const MyOctokit = Octokit . plugin ( throttling ) ;
510+ const auth = await this . app . credentials . getAccessToken ( ) ;
511+
512+ const octokit = new MyOctokit ( {
513+ auth,
514+ retry,
515+ throttle : {
516+ onRateLimit : ( retryAfter : number , options : any ) : boolean => {
517+ void showAndLogWarningMessage (
518+ `Request quota exhausted for request ${ options . method } ${ options . url } . Retrying after ${ retryAfter } seconds!` ,
519+ ) ;
520+
521+ return true ;
522+ } ,
523+ onSecondaryRateLimit : ( _retryAfter : number , options : any ) : void => {
524+ void showAndLogWarningMessage (
525+ `SecondaryRateLimit detected for request ${ options . method } ${ options . url } ` ,
526+ ) ;
527+ } ,
528+ } ,
529+ } ) ;
530+ return octokit ;
531+ }
502532}
0 commit comments