Change fetch queries to use shared methods.
This commit is contained in:
@@ -26,12 +26,8 @@ import { runFlowModelQueries } from "./flow-model-queries";
|
|||||||
import { promptImportGithubDatabase } from "../databases/database-fetcher";
|
import { promptImportGithubDatabase } from "../databases/database-fetcher";
|
||||||
import { App } from "../common/app";
|
import { App } from "../common/app";
|
||||||
import { showResolvableLocation } from "../databases/local-databases/locations";
|
import { showResolvableLocation } from "../databases/local-databases/locations";
|
||||||
import { decodeBqrsToExternalApiUsages } from "./bqrs";
|
|
||||||
import { redactableError } from "../common/errors";
|
import { redactableError } from "../common/errors";
|
||||||
import {
|
import { runExternalApiQueries } from "./external-api-usage-queries";
|
||||||
readQueryResults,
|
|
||||||
runExternalApiQueries,
|
|
||||||
} from "./external-api-usage-queries";
|
|
||||||
import { ExternalApiUsage, Usage } from "./external-api-usage";
|
import { ExternalApiUsage, Usage } from "./external-api-usage";
|
||||||
import { ModeledMethod } from "./modeled-method";
|
import { ModeledMethod } from "./modeled-method";
|
||||||
import { ExtensionPack } from "./shared/extension-pack";
|
import { ExtensionPack } from "./shared/extension-pack";
|
||||||
@@ -319,28 +315,7 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
|||||||
if (!queryResult) {
|
if (!queryResult) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.externalApiUsages = queryResult;
|
||||||
progress({
|
|
||||||
message: "Decoding results",
|
|
||||||
step: 1100,
|
|
||||||
maxStep: 1500,
|
|
||||||
});
|
|
||||||
|
|
||||||
const bqrsChunk = await readQueryResults({
|
|
||||||
cliServer: this.cliServer,
|
|
||||||
bqrsPath: queryResult.outputDir.bqrsPath,
|
|
||||||
});
|
|
||||||
if (!bqrsChunk) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
progress({
|
|
||||||
message: "Finalizing results",
|
|
||||||
step: 1450,
|
|
||||||
maxStep: 1500,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.externalApiUsages = decodeBqrsToExternalApiUsages(bqrsChunk);
|
|
||||||
|
|
||||||
await this.postMessage({
|
await this.postMessage({
|
||||||
t: "setExternalApiUsages",
|
t: "setExternalApiUsages",
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { CoreCompletedQuery, QueryRunner } from "../query-server";
|
import { QueryRunner } from "../query-server";
|
||||||
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
|
||||||
import { extLogger } from "../common/logging/vscode";
|
import { extLogger } from "../common/logging/vscode";
|
||||||
import { showAndLogExceptionWithTelemetry, TeeLogger } from "../common/logging";
|
import { showAndLogExceptionWithTelemetry } from "../common/logging";
|
||||||
import { CancellationToken } from "vscode";
|
import { CancellationToken } from "vscode";
|
||||||
import { CodeQLCliServer } from "../codeql-cli/cli";
|
import { CodeQLCliServer } from "../codeql-cli/cli";
|
||||||
import { DatabaseItem } from "../databases/local-databases";
|
import { DatabaseItem } from "../databases/local-databases";
|
||||||
import { ProgressCallback } from "../common/vscode/progress";
|
import { ProgressCallback } from "../common/vscode/progress";
|
||||||
import { QueryResultType } from "../query-server/new-messages";
|
|
||||||
import { redactableError } from "../common/errors";
|
import { redactableError } from "../common/errors";
|
||||||
import { telemetryListener } from "../common/vscode/telemetry";
|
import { telemetryListener } from "../common/vscode/telemetry";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
@@ -14,11 +13,14 @@ import { Mode } from "./shared/mode";
|
|||||||
import { writeFile } from "fs-extra";
|
import { writeFile } from "fs-extra";
|
||||||
import { QueryLanguage } from "../common/query-language";
|
import { QueryLanguage } from "../common/query-language";
|
||||||
import { fetchExternalApiQueries } from "./queries";
|
import { fetchExternalApiQueries } from "./queries";
|
||||||
|
import { ExternalApiUsage } from "./external-api-usage";
|
||||||
|
import { runQuery } from "../local-queries/run-query";
|
||||||
|
import { decodeBqrsToExternalApiUsages } from "./bqrs";
|
||||||
|
|
||||||
type RunQueryOptions = {
|
type RunQueryOptions = {
|
||||||
cliServer: Pick<CodeQLCliServer, "resolveQlpacks">;
|
cliServer: CodeQLCliServer;
|
||||||
queryRunner: Pick<QueryRunner, "createQueryRun" | "logger">;
|
queryRunner: QueryRunner;
|
||||||
databaseItem: Pick<DatabaseItem, "contents" | "databaseUri" | "language">;
|
databaseItem: DatabaseItem;
|
||||||
queryStorageDir: string;
|
queryStorageDir: string;
|
||||||
queryDir: string;
|
queryDir: string;
|
||||||
|
|
||||||
@@ -67,7 +69,7 @@ export async function runExternalApiQueries(
|
|||||||
progress,
|
progress,
|
||||||
token,
|
token,
|
||||||
}: RunQueryOptions,
|
}: RunQueryOptions,
|
||||||
): Promise<CoreCompletedQuery | undefined> {
|
): Promise<ExternalApiUsage[] | undefined> {
|
||||||
// The below code is temporary to allow for rapid prototyping of the queries. Once the queries are stabilized, we will
|
// The below code is temporary to allow for rapid prototyping of the queries. Once the queries are stabilized, we will
|
||||||
// move these queries into the `github/codeql` repository and use them like any other contextual (e.g. AST) queries.
|
// move these queries into the `github/codeql` repository and use them like any other contextual (e.g. AST) queries.
|
||||||
// This is intentionally not pretty code, as it will be removed soon.
|
// This is intentionally not pretty code, as it will be removed soon.
|
||||||
@@ -79,44 +81,47 @@ export async function runExternalApiQueries(
|
|||||||
await cliServer.resolveQlpacks(additionalPacks, true),
|
await cliServer.resolveQlpacks(additionalPacks, true),
|
||||||
);
|
);
|
||||||
|
|
||||||
const queryFile = join(
|
const queryPath = join(queryDir, queryNameFromMode(mode));
|
||||||
queryDir,
|
|
||||||
`FetchExternalApis${mode.charAt(0).toUpperCase() + mode.slice(1)}Mode.ql`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const queryRun = queryRunner.createQueryRun(
|
// Run the actual query
|
||||||
databaseItem.databaseUri.fsPath,
|
const completedQuery = await runQuery({
|
||||||
{
|
cliServer,
|
||||||
queryPath: queryFile,
|
queryRunner,
|
||||||
quickEvalPosition: undefined,
|
databaseItem,
|
||||||
quickEvalCountOnly: false,
|
queryPath,
|
||||||
},
|
|
||||||
false,
|
|
||||||
getOnDiskWorkspaceFolders(),
|
|
||||||
extensionPacks,
|
|
||||||
queryStorageDir,
|
queryStorageDir,
|
||||||
undefined,
|
additionalPacks,
|
||||||
undefined,
|
extensionPacks,
|
||||||
);
|
|
||||||
|
|
||||||
const completedQuery = await queryRun.evaluate(
|
|
||||||
progress,
|
progress,
|
||||||
token,
|
token,
|
||||||
new TeeLogger(queryRunner.logger, queryRun.outputDir.logPath),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
if (completedQuery.resultType !== QueryResultType.SUCCESS) {
|
if (!completedQuery) {
|
||||||
void showAndLogExceptionWithTelemetry(
|
|
||||||
extLogger,
|
|
||||||
telemetryListener,
|
|
||||||
redactableError`External API usage query failed: ${
|
|
||||||
completedQuery.message ?? "No message"
|
|
||||||
}`,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return completedQuery;
|
// Read the results and covert to internal representation
|
||||||
|
progress({
|
||||||
|
message: "Decoding results",
|
||||||
|
step: 1100,
|
||||||
|
maxStep: 1500,
|
||||||
|
});
|
||||||
|
|
||||||
|
const bqrsChunk = await readQueryResults({
|
||||||
|
cliServer,
|
||||||
|
bqrsPath: completedQuery.outputDir.bqrsPath,
|
||||||
|
});
|
||||||
|
if (!bqrsChunk) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
progress({
|
||||||
|
message: "Finalizing results",
|
||||||
|
step: 1450,
|
||||||
|
maxStep: 1500,
|
||||||
|
});
|
||||||
|
|
||||||
|
return decodeBqrsToExternalApiUsages(bqrsChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetResultsOptions = {
|
type GetResultsOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user