11import { throttling } from "@octokit/plugin-throttling" ;
22import { Octokit } from "@octokit/rest" ;
3- import { Progress , CancellationToken } from "vscode" ;
3+ import { CancellationToken } from "vscode" ;
44import { Credentials } from "../common/authentication" ;
55import { BaseLogger } from "../common/logging" ;
66import { AppOctokit } from "../common/octokit" ;
7- import { UserCancellationException } from "../common/vscode/progress" ;
7+ import {
8+ ProgressCallback ,
9+ UserCancellationException ,
10+ } from "../common/vscode/progress" ;
811
912export async function getCodeSearchRepositories (
1013 query : string ,
11- progress : Progress < {
12- message ?: string | undefined ;
13- increment ?: number | undefined ;
14- } > ,
14+ progress : ProgressCallback ,
1515 token : CancellationToken ,
1616 credentials : Credentials ,
1717 logger : BaseLogger ,
1818) : Promise < string [ ] > {
1919 const nwos : string [ ] = [ ] ;
2020 const octokit = await provideOctokitWithThrottling ( credentials , logger ) ;
21+ let i = 0 ;
2122
2223 for await ( const response of octokit . paginate . iterator (
2324 octokit . rest . search . code ,
@@ -26,13 +27,16 @@ export async function getCodeSearchRepositories(
2627 per_page : 100 ,
2728 } ,
2829 ) ) {
30+ i ++ ;
2931 nwos . push ( ...response . data . map ( ( item ) => item . repository . full_name ) ) ;
30- // calculate progress bar: 80% of the progress bar is used for the code search
31- const totalNumberOfRequests = Math . ceil ( response . data . total_count / 100 ) ;
32- // Since we have a maximum of 1000 responses of the api, we can use a fixed increment whenever the totalNumberOfRequests would be greater than 10
33- const increment =
34- totalNumberOfRequests < 10 ? 80 / totalNumberOfRequests : 8 ;
35- progress . report ( { increment } ) ;
32+ const totalNumberOfResultPages = Math . ceil ( response . data . total_count / 100 ) ;
33+ const totalNumberOfRequests =
34+ totalNumberOfResultPages > 10 ? 10 : totalNumberOfResultPages ;
35+ progress ( {
36+ maxStep : totalNumberOfRequests ,
37+ step : i ,
38+ message : "Sending API requests to get Code Search results." ,
39+ } ) ;
3640
3741 if ( token . isCancellationRequested ) {
3842 throw new UserCancellationException ( "Code search cancelled." , true ) ;
0 commit comments