Implement submitting a variant analysis
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
import { Credentials } from '../authentication';
|
import { Credentials } from '../authentication';
|
||||||
import * as cli from '../cli';
|
import * as cli from '../cli';
|
||||||
import { logger } from '../logging';
|
import { logger } from '../logging';
|
||||||
import { getActionBranch, getRemoteControllerRepo, setRemoteControllerRepo } from '../config';
|
import { getActionBranch, getRemoteControllerRepo, isVariantAnalysisLiveResultsEnabled, setRemoteControllerRepo } from '../config';
|
||||||
import { ProgressCallback, UserCancellationException } from '../commandRunner';
|
import { ProgressCallback, UserCancellationException } from '../commandRunner';
|
||||||
import { OctokitResponse, RequestError } from '@octokit/types/dist-types';
|
import { OctokitResponse, RequestError } from '@octokit/types/dist-types';
|
||||||
import { RemoteQuery } from './remote-query';
|
import { RemoteQuery } from './remote-query';
|
||||||
@@ -26,6 +26,7 @@ import { QueryMetadata } from '../pure/interface-types';
|
|||||||
import { getErrorMessage, REPO_REGEX } from '../pure/helpers-pure';
|
import { getErrorMessage, REPO_REGEX } from '../pure/helpers-pure';
|
||||||
import * as ghApiClient from './gh-api/gh-api-client';
|
import * as ghApiClient from './gh-api/gh-api-client';
|
||||||
import { getRepositorySelection, isValidSelection, RepositorySelection } from './repository-selection';
|
import { getRepositorySelection, isValidSelection, RepositorySelection } from './repository-selection';
|
||||||
|
import { VariantAnalysisQueryLanguage, VariantAnalysisSubmission } from './shared/variant-analysis';
|
||||||
|
|
||||||
export interface QlPack {
|
export interface QlPack {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -262,31 +263,61 @@ export async function runRemoteQuery(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const actionBranch = getActionBranch();
|
const actionBranch = getActionBranch();
|
||||||
const apiResponse = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, owner, repo, base64Pack, dryRun);
|
|
||||||
const queryStartTime = Date.now();
|
const queryStartTime = Date.now();
|
||||||
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
|
const queryMetadata = await tryGetQueryMetadata(cliServer, queryFile);
|
||||||
|
|
||||||
if (dryRun) {
|
if (isVariantAnalysisLiveResultsEnabled()) {
|
||||||
return { queryDirPath: remoteQueryDir.path };
|
const queryName = getQueryName(queryMetadata, queryFile);
|
||||||
|
const variantAnalysisSubmission: VariantAnalysisSubmission = {
|
||||||
|
startTime: queryStartTime,
|
||||||
|
actionRepoRef: actionBranch,
|
||||||
|
controllerRepoId: controllerRepoId,
|
||||||
|
query: {
|
||||||
|
name: queryName,
|
||||||
|
filePath: queryFile,
|
||||||
|
pack: base64Pack,
|
||||||
|
language: language as VariantAnalysisQueryLanguage,
|
||||||
|
},
|
||||||
|
databases: {
|
||||||
|
repositories: repoSelection.repositories,
|
||||||
|
repositoryLists: repoSelection.repositoryLists,
|
||||||
|
repositoryOwners: repoSelection.owners
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const variantAnalysisResponse = await ghApiClient.submitVariantAnalysis(
|
||||||
|
credentials,
|
||||||
|
variantAnalysisSubmission
|
||||||
|
);
|
||||||
|
await showAndLogInformationMessage('Variant analysis submitted for processing');
|
||||||
|
void logger.log(`Variant analysis result:\n${JSON.stringify(variantAnalysisResponse)}`);
|
||||||
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!apiResponse) {
|
const apiResponse = await runRemoteQueriesApiRequest(credentials, actionBranch, language, repoSelection, owner, repo, base64Pack, dryRun);
|
||||||
return;
|
|
||||||
|
if (dryRun) {
|
||||||
|
return { queryDirPath: remoteQueryDir.path };
|
||||||
|
} else {
|
||||||
|
if (!apiResponse) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const workflowRunId = apiResponse.workflow_run_id;
|
||||||
|
const repositoryCount = apiResponse.repositories_queried.length;
|
||||||
|
const remoteQuery = await buildRemoteQueryEntity(
|
||||||
|
queryFile,
|
||||||
|
queryMetadata,
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
queryStartTime,
|
||||||
|
workflowRunId,
|
||||||
|
language,
|
||||||
|
repositoryCount);
|
||||||
|
|
||||||
|
// don't return the path because it has been deleted
|
||||||
|
return { query: remoteQuery };
|
||||||
}
|
}
|
||||||
|
|
||||||
const workflowRunId = apiResponse.workflow_run_id;
|
|
||||||
const repositoryCount = apiResponse.repositories_queried.length;
|
|
||||||
const remoteQuery = await buildRemoteQueryEntity(
|
|
||||||
queryFile,
|
|
||||||
queryMetadata,
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
queryStartTime,
|
|
||||||
workflowRunId,
|
|
||||||
language,
|
|
||||||
repositoryCount);
|
|
||||||
|
|
||||||
// don't return the path because it has been deleted
|
|
||||||
return { query: remoteQuery };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@@ -435,9 +466,7 @@ async function buildRemoteQueryEntity(
|
|||||||
language: string,
|
language: string,
|
||||||
repositoryCount: number
|
repositoryCount: number
|
||||||
): Promise<RemoteQuery> {
|
): Promise<RemoteQuery> {
|
||||||
// The query name is either the name as specified in the query metadata, or the file name.
|
const queryName = getQueryName(queryMetadata, queryFilePath);
|
||||||
const queryName = queryMetadata?.name ?? path.basename(queryFilePath);
|
|
||||||
|
|
||||||
const queryText = await fs.readFile(queryFilePath, 'utf8');
|
const queryText = await fs.readFile(queryFilePath, 'utf8');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -455,6 +484,11 @@ async function buildRemoteQueryEntity(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getQueryName(queryMetadata: QueryMetadata | undefined, queryFilePath: string): string {
|
||||||
|
// The query name is either the name as specified in the query metadata, or the file name.
|
||||||
|
return queryMetadata?.name ?? path.basename(queryFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
async function getControllerRepoId(credentials: Credentials, owner: string, repo: string): Promise<number> {
|
async function getControllerRepoId(credentials: Credentials, owner: string, repo: string): Promise<number> {
|
||||||
try {
|
try {
|
||||||
return await ghApiClient.getRepositoryIdFromNwo(credentials, owner, repo);
|
return await ghApiClient.getRepositoryIdFromNwo(credentials, owner, repo);
|
||||||
|
|||||||
Reference in New Issue
Block a user