Show progress information when sending search api request
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
ProgressLocation,
|
||||
QuickPickItem,
|
||||
TreeView,
|
||||
TreeViewExpansionEvent,
|
||||
@@ -13,7 +14,10 @@ import {
|
||||
getOwnerFromGitHubUrl,
|
||||
isValidGitHubOwner,
|
||||
} from "../../common/github-url-identifier-helper";
|
||||
import { showAndLogErrorMessage } from "../../helpers";
|
||||
import {
|
||||
showAndLogErrorMessage,
|
||||
showAndLogInformationMessage,
|
||||
} from "../../helpers";
|
||||
import { DisposableObject } from "../../pure/disposable-object";
|
||||
import {
|
||||
DbItem,
|
||||
@@ -343,6 +347,8 @@ export class DbPanel extends DisposableObject {
|
||||
throw new Error("Please select a valid list to add code search results.");
|
||||
}
|
||||
|
||||
const listName = treeViewItem.dbItem.listName;
|
||||
|
||||
const languageQuickPickItems: CodeSearchQuickPickItem[] = Object.values(
|
||||
QueryLanguage,
|
||||
).map((language) => ({
|
||||
@@ -375,18 +381,33 @@ export class DbPanel extends DisposableObject {
|
||||
return;
|
||||
}
|
||||
|
||||
void window.withProgress(
|
||||
{
|
||||
location: ProgressLocation.Notification,
|
||||
title: "Searching for repositories... This might take a while",
|
||||
cancellable: true,
|
||||
},
|
||||
async (progress, token) => {
|
||||
progress.report({ increment: 10 });
|
||||
|
||||
const repositories = await getCodeSearchRepositories(
|
||||
this.app.credentials,
|
||||
`${codeSearchQuery} language:${codeSearchLanguage.language}`,
|
||||
progress,
|
||||
token,
|
||||
);
|
||||
|
||||
const truncatedRepositories = await this.dbManager.addNewRemoteReposToList(
|
||||
repositories,
|
||||
treeViewItem.dbItem.listName,
|
||||
);
|
||||
this.truncatedReposNote(
|
||||
truncatedRepositories,
|
||||
treeViewItem.dbItem.listName,
|
||||
token.onCancellationRequested(() => {
|
||||
void showAndLogInformationMessage("Code search cancelled");
|
||||
return;
|
||||
});
|
||||
|
||||
progress.report({ increment: 10, message: "Processing results..." });
|
||||
|
||||
const truncatedRepositories =
|
||||
await this.dbManager.addNewRemoteReposToList(repositories, listName);
|
||||
this.truncatedReposNote(truncatedRepositories, listName);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,21 +7,36 @@ import {
|
||||
VariantAnalysisSubmissionRequest,
|
||||
} from "./variant-analysis";
|
||||
import { Repository } from "./repository";
|
||||
import { Progress } from "vscode";
|
||||
import { CancellationToken } from "vscode-jsonrpc";
|
||||
|
||||
export async function getCodeSearchRepositories(
|
||||
credentials: Credentials,
|
||||
query: string,
|
||||
progress: Progress<{
|
||||
message?: string | undefined;
|
||||
increment?: number | undefined;
|
||||
}>,
|
||||
token: CancellationToken,
|
||||
): Promise<string[]> {
|
||||
let nwos: string[] = [];
|
||||
const octokit = await credentials.getOctokit();
|
||||
|
||||
const nwos = await octokit.paginate(
|
||||
for await (const response of octokit.paginate.iterator(
|
||||
octokit.rest.search.repos,
|
||||
{
|
||||
q: query,
|
||||
per_page: 100,
|
||||
},
|
||||
(response) => response.data.map((item) => item.full_name),
|
||||
);
|
||||
)) {
|
||||
nwos.push(...response.data.map((item) => item.full_name));
|
||||
const numberOfRequests = Math.ceil(response.data.total_count / 99);
|
||||
const increment = numberOfRequests < 10 ? 80 / numberOfRequests : 8;
|
||||
progress.report({ increment });
|
||||
if (token.isCancellationRequested) {
|
||||
nwos = [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [...new Set(nwos)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user