Skip to content

Commit 21eabc2

Browse files
authored
Merge pull request #1745 from github/koesie10/extract-remote-query-preparation
Extract remote query preparation to separate method
2 parents 93b6abe + 00905a9 commit 21eabc2

File tree

1 file changed

+92
-45
lines changed

1 file changed

+92
-45
lines changed

extensions/ql-vscode/src/remote-queries/run-remote-query.ts

Lines changed: 92 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -187,72 +187,119 @@ async function getPackedBundlePath(queryPackDir: string) {
187187
});
188188
}
189189

190-
export async function runRemoteQuery(
190+
export interface PreparedRemoteQuery {
191+
actionBranch: string;
192+
base64Pack: string;
193+
repoSelection: RepositorySelection;
194+
queryFile: string;
195+
queryMetadata: QueryMetadata | undefined;
196+
controllerRepo: Repository;
197+
queryStartTime: number;
198+
language: string;
199+
}
200+
201+
export async function prepareRemoteQueryRun(
191202
cliServer: cli.CodeQLCliServer,
192203
credentials: Credentials,
193204
uri: Uri | undefined,
194-
dryRun: boolean,
205+
queryPackDir: string,
195206
progress: ProgressCallback,
196207
token: CancellationToken,
197-
variantAnalysisManager: VariantAnalysisManager
198-
): Promise<void | RemoteQuerySubmissionResult> {
208+
): Promise<PreparedRemoteQuery> {
199209
if (!(await cliServer.cliConstraints.supportsRemoteQueries())) {
200210
throw new Error(`Variant analysis is not supported by this version of CodeQL. Please upgrade to v${cli.CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES
201211
} or later.`);
202212
}
203213

204-
const { remoteQueryDir, queryPackDir } = await createRemoteQueriesTempDirectory();
205-
try {
206-
if (!uri?.fsPath.endsWith('.ql')) {
207-
throw new UserCancellationException('Not a CodeQL query file.');
208-
}
214+
if (!uri?.fsPath.endsWith('.ql')) {
215+
throw new UserCancellationException('Not a CodeQL query file.');
216+
}
209217

210-
const queryFile = uri.fsPath;
218+
const queryFile = uri.fsPath;
211219

212-
progress({
213-
maxStep: 4,
214-
step: 1,
215-
message: 'Determining query target language'
216-
});
220+
progress({
221+
maxStep: 4,
222+
step: 1,
223+
message: 'Determining query target language'
224+
});
217225

218-
const repoSelection = await getRepositorySelection();
219-
if (!isValidSelection(repoSelection)) {
220-
throw new UserCancellationException('No repositories to query.');
221-
}
226+
const repoSelection = await getRepositorySelection();
227+
if (!isValidSelection(repoSelection)) {
228+
throw new UserCancellationException('No repositories to query.');
229+
}
222230

223-
progress({
224-
maxStep: 4,
225-
step: 2,
226-
message: 'Determining controller repo'
227-
});
231+
progress({
232+
maxStep: 4,
233+
step: 2,
234+
message: 'Determining controller repo'
235+
});
228236

229-
const controllerRepo = await getControllerRepo(credentials);
237+
const controllerRepo = await getControllerRepo(credentials);
230238

231-
progress({
232-
maxStep: 4,
233-
step: 3,
234-
message: 'Bundling the query pack'
235-
});
239+
progress({
240+
maxStep: 4,
241+
step: 3,
242+
message: 'Bundling the query pack'
243+
});
236244

237-
if (token.isCancellationRequested) {
238-
throw new UserCancellationException('Cancelled');
239-
}
245+
if (token.isCancellationRequested) {
246+
throw new UserCancellationException('Cancelled');
247+
}
240248

241-
const { base64Pack, language } = await generateQueryPack(cliServer, queryFile, queryPackDir);
249+
const { base64Pack, language } = await generateQueryPack(cliServer, queryFile, queryPackDir);
242250

243-
if (token.isCancellationRequested) {
244-
throw new UserCancellationException('Cancelled');
245-
}
251+
if (token.isCancellationRequested) {
252+
throw new UserCancellationException('Cancelled');
253+
}
246254

247-
progress({
248-
maxStep: 4,
249-
step: 4,
250-
message: 'Sending request'
251-
});
255+
progress({
256+
maxStep: 4,
257+
step: 4,
258+
message: 'Sending request'
259+
});
252260

253-
const actionBranch = getActionBranch();
254-
const queryStartTime = Date.now();
255-
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
261+
const actionBranch = getActionBranch();
262+
const queryStartTime = Date.now();
263+
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
264+
265+
return {
266+
actionBranch,
267+
base64Pack,
268+
repoSelection,
269+
queryFile,
270+
queryMetadata,
271+
controllerRepo,
272+
queryStartTime,
273+
language,
274+
};
275+
}
276+
277+
export async function runRemoteQuery(
278+
cliServer: cli.CodeQLCliServer,
279+
credentials: Credentials,
280+
uri: Uri | undefined,
281+
dryRun: boolean,
282+
progress: ProgressCallback,
283+
token: CancellationToken,
284+
variantAnalysisManager: VariantAnalysisManager
285+
): Promise<void | RemoteQuerySubmissionResult> {
286+
if (!(await cliServer.cliConstraints.supportsRemoteQueries())) {
287+
throw new Error(`Variant analysis is not supported by this version of CodeQL. Please upgrade to v${cli.CliVersionConstraint.CLI_VERSION_REMOTE_QUERIES
288+
} or later.`);
289+
}
290+
291+
const { remoteQueryDir, queryPackDir } = await createRemoteQueriesTempDirectory();
292+
try {
293+
const {
294+
actionBranch,
295+
base64Pack,
296+
repoSelection,
297+
queryFile,
298+
queryMetadata,
299+
controllerRepo,
300+
queryStartTime,
301+
language,
302+
} = await prepareRemoteQueryRun(cliServer, credentials, uri, queryPackDir, progress, token);
256303

257304
if (isVariantAnalysisLiveResultsEnabled()) {
258305
const queryName = getQueryName(queryMetadata, queryFile);

0 commit comments

Comments
 (0)