Skip to content

Commit 52f993f

Browse files
Implement submitting a variant analysis
1 parent 7d721d9 commit 52f993f

1 file changed

Lines changed: 57 additions & 23 deletions

File tree

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

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
import { Credentials } from '../authentication';
1818
import * as cli from '../cli';
1919
import { logger } from '../logging';
20-
import { getActionBranch, getRemoteControllerRepo, setRemoteControllerRepo } from '../config';
20+
import { getActionBranch, getRemoteControllerRepo, isVariantAnalysisLiveResultsEnabled, setRemoteControllerRepo } from '../config';
2121
import { ProgressCallback, UserCancellationException } from '../commandRunner';
2222
import { OctokitResponse, RequestError } from '@octokit/types/dist-types';
2323
import { RemoteQuery } from './remote-query';
@@ -26,6 +26,7 @@ import { QueryMetadata } from '../pure/interface-types';
2626
import { getErrorMessage, REPO_REGEX } from '../pure/helpers-pure';
2727
import * as ghApiClient from './gh-api/gh-api-client';
2828
import { getRepositorySelection, isValidSelection, RepositorySelection } from './repository-selection';
29+
import { VariantAnalysisQueryLanguage, VariantAnalysisSubmission } from './shared/variant-analysis';
2930

3031
export interface QlPack {
3132
name: string;
@@ -262,31 +263,61 @@ export async function runRemoteQuery(
262263
});
263264

264265
const actionBranch = getActionBranch();
265-
const apiResponse = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, owner, repo, base64Pack, dryRun);
266266
const queryStartTime = Date.now();
267267
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
268268

269-
if (dryRun) {
270-
return { queryDirPath: remoteQueryDir.path };
269+
if (isVariantAnalysisLiveResultsEnabled()) {
270+
const queryName = getQueryName(queryMetadata, queryFile);
271+
const variantAnalysisSubmission: VariantAnalysisSubmission = {
272+
startTime: queryStartTime,
273+
actionRepoRef: actionBranch,
274+
controllerRepoId: controllerRepoId,
275+
query: {
276+
name: queryName,
277+
filePath: queryFile,
278+
pack: base64Pack,
279+
language: language as VariantAnalysisQueryLanguage,
280+
},
281+
databases: {
282+
repositories: repoSelection.repositories,
283+
repositoryLists: repoSelection.repositoryLists,
284+
repositoryOwners: repoSelection.owners
285+
}
286+
};
287+
288+
const variantAnalysisResponse = await ghApiClient.submitVariantAnalysis(
289+
credentials,
290+
variantAnalysisSubmission
291+
);
292+
await showAndLogInformationMessage('Variant analysis submitted for processing');
293+
void logger.log(`Variant analysis result:\n${JSON.stringify(variantAnalysisResponse)}`);
294+
return;
295+
271296
} else {
272-
if (!apiResponse) {
273-
return;
274-
}
297+
const apiResponse = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, owner, repo, base64Pack, dryRun);
275298

276-
const workflowRunId = apiResponse.workflow_run_id;
277-
const repositoryCount = apiResponse.repositories_queried.length;
278-
const remoteQuery = await buildRemoteQueryEntity(
279-
queryFile,
280-
queryMetadata,
281-
owner,
282-
repo,
283-
queryStartTime,
284-
workflowRunId,
285-
language,
286-
repositoryCount);
299+
if (dryRun) {
300+
return { queryDirPath: remoteQueryDir.path };
301+
} else {
302+
if (!apiResponse) {
303+
return;
304+
}
287305

288-
// don't return the path because it has been deleted
289-
return { query: remoteQuery };
306+
const workflowRunId = apiResponse.workflow_run_id;
307+
const repositoryCount = apiResponse.repositories_queried.length;
308+
const remoteQuery = await buildRemoteQueryEntity(
309+
queryFile,
310+
queryMetadata,
311+
owner,
312+
repo,
313+
queryStartTime,
314+
workflowRunId,
315+
language,
316+
repositoryCount);
317+
318+
// don't return the path because it has been deleted
319+
return { query: remoteQuery };
320+
}
290321
}
291322

292323
} finally {
@@ -435,9 +466,7 @@ async function buildRemoteQueryEntity(
435466
language: string,
436467
repositoryCount: number
437468
): Promise<RemoteQuery> {
438-
// The query name is either the name as specified in the query metadata, or the file name.
439-
const queryName = queryMetadata?.name ?? path.basename(queryFilePath);
440-
469+
const queryName = getQueryName(queryMetadata, queryFilePath);
441470
const queryText = await fs.readFile(queryFilePath, 'utf8');
442471

443472
return {
@@ -455,6 +484,11 @@ async function buildRemoteQueryEntity(
455484
};
456485
}
457486

487+
function getQueryName(queryMetadata: QueryMetadata | undefined, queryFilePath: string): string {
488+
// The query name is either the name as specified in the query metadata, or the file name.
489+
return queryMetadata?.name ?? path.basename(queryFilePath);
490+
}
491+
458492
async function getControllerRepoId(credentials: Credentials, owner: string, repo: string): Promise<number> {
459493
try {
460494
return await ghApiClient.getRepositoryIdFromNwo(credentials, owner, repo);

0 commit comments

Comments
 (0)