Merge pull request #1745 from github/koesie10/extract-remote-query-preparation
Extract remote query preparation to separate method
This commit is contained in:
@@ -187,6 +187,93 @@ async function getPackedBundlePath(queryPackDir: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PreparedRemoteQuery {
|
||||||
|
actionBranch: string;
|
||||||
|
base64Pack: string;
|
||||||
|
repoSelection: RepositorySelection;
|
||||||
|
queryFile: string;
|
||||||
|
queryMetadata: QueryMetadata | undefined;
|
||||||
|
controllerRepo: Repository;
|
||||||
|
queryStartTime: number;
|
||||||
|
language: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function prepareRemoteQueryRun(
|
||||||
|
cliServer: cli.CodeQLCliServer,
|
||||||
|
credentials: Credentials,
|
||||||
|
uri: Uri | undefined,
|
||||||
|
queryPackDir: string,
|
||||||
|
progress: ProgressCallback,
|
||||||
|
token: CancellationToken,
|
||||||
|
): Promise<PreparedRemoteQuery> {
|
||||||
|
if (!(await cliServer.cliConstraints.supportsRemoteQueries())) {
|
||||||
|
throw new Error(`Variant analysis is not supported by this version of CodeQL. Please upgrade to v${cli.CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES
|
||||||
|
} or later.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!uri?.fsPath.endsWith('.ql')) {
|
||||||
|
throw new UserCancellationException('Not a CodeQL query file.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryFile = uri.fsPath;
|
||||||
|
|
||||||
|
progress({
|
||||||
|
maxStep: 4,
|
||||||
|
step: 1,
|
||||||
|
message: 'Determining query target language'
|
||||||
|
});
|
||||||
|
|
||||||
|
const repoSelection = await getRepositorySelection();
|
||||||
|
if (!isValidSelection(repoSelection)) {
|
||||||
|
throw new UserCancellationException('No repositories to query.');
|
||||||
|
}
|
||||||
|
|
||||||
|
progress({
|
||||||
|
maxStep: 4,
|
||||||
|
step: 2,
|
||||||
|
message: 'Determining controller repo'
|
||||||
|
});
|
||||||
|
|
||||||
|
const controllerRepo = await getControllerRepo(credentials);
|
||||||
|
|
||||||
|
progress({
|
||||||
|
maxStep: 4,
|
||||||
|
step: 3,
|
||||||
|
message: 'Bundling the query pack'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (token.isCancellationRequested) {
|
||||||
|
throw new UserCancellationException('Cancelled');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { base64Pack, language } = await generateQueryPack(cliServer, queryFile, queryPackDir);
|
||||||
|
|
||||||
|
if (token.isCancellationRequested) {
|
||||||
|
throw new UserCancellationException('Cancelled');
|
||||||
|
}
|
||||||
|
|
||||||
|
progress({
|
||||||
|
maxStep: 4,
|
||||||
|
step: 4,
|
||||||
|
message: 'Sending request'
|
||||||
|
});
|
||||||
|
|
||||||
|
const actionBranch = getActionBranch();
|
||||||
|
const queryStartTime = Date.now();
|
||||||
|
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
|
||||||
|
|
||||||
|
return {
|
||||||
|
actionBranch,
|
||||||
|
base64Pack,
|
||||||
|
repoSelection,
|
||||||
|
queryFile,
|
||||||
|
queryMetadata,
|
||||||
|
controllerRepo,
|
||||||
|
queryStartTime,
|
||||||
|
language,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function runRemoteQuery(
|
export async function runRemoteQuery(
|
||||||
cliServer: cli.CodeQLCliServer,
|
cliServer: cli.CodeQLCliServer,
|
||||||
credentials: Credentials,
|
credentials: Credentials,
|
||||||
@@ -203,56 +290,16 @@ export async function runRemoteQuery(
|
|||||||
|
|
||||||
const { remoteQueryDir, queryPackDir } = await createRemoteQueriesTempDirectory();
|
const { remoteQueryDir, queryPackDir } = await createRemoteQueriesTempDirectory();
|
||||||
try {
|
try {
|
||||||
if (!uri?.fsPath.endsWith('.ql')) {
|
const {
|
||||||
throw new UserCancellationException('Not a CodeQL query file.');
|
actionBranch,
|
||||||
}
|
base64Pack,
|
||||||
|
repoSelection,
|
||||||
const queryFile = uri.fsPath;
|
queryFile,
|
||||||
|
queryMetadata,
|
||||||
progress({
|
controllerRepo,
|
||||||
maxStep: 4,
|
queryStartTime,
|
||||||
step: 1,
|
language,
|
||||||
message: 'Determining query target language'
|
} = await prepareRemoteQueryRun(cliServer, credentials, uri, queryPackDir, progress, token);
|
||||||
});
|
|
||||||
|
|
||||||
const repoSelection = await getRepositorySelection();
|
|
||||||
if (!isValidSelection(repoSelection)) {
|
|
||||||
throw new UserCancellationException('No repositories to query.');
|
|
||||||
}
|
|
||||||
|
|
||||||
progress({
|
|
||||||
maxStep: 4,
|
|
||||||
step: 2,
|
|
||||||
message: 'Determining controller repo'
|
|
||||||
});
|
|
||||||
|
|
||||||
const controllerRepo = await getControllerRepo(credentials);
|
|
||||||
|
|
||||||
progress({
|
|
||||||
maxStep: 4,
|
|
||||||
step: 3,
|
|
||||||
message: 'Bundling the query pack'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (token.isCancellationRequested) {
|
|
||||||
throw new UserCancellationException('Cancelled');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { base64Pack, language } = await generateQueryPack(cliServer, queryFile, queryPackDir);
|
|
||||||
|
|
||||||
if (token.isCancellationRequested) {
|
|
||||||
throw new UserCancellationException('Cancelled');
|
|
||||||
}
|
|
||||||
|
|
||||||
progress({
|
|
||||||
maxStep: 4,
|
|
||||||
step: 4,
|
|
||||||
message: 'Sending request'
|
|
||||||
});
|
|
||||||
|
|
||||||
const actionBranch = getActionBranch();
|
|
||||||
const queryStartTime = Date.now();
|
|
||||||
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
|
|
||||||
|
|
||||||
if (isVariantAnalysisLiveResultsEnabled()) {
|
if (isVariantAnalysisLiveResultsEnabled()) {
|
||||||
const queryName = getQueryName(queryMetadata, queryFile);
|
const queryName = getQueryName(queryMetadata, queryFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user