Some restructuring around variant analysis mapper functions (#3412)

This commit is contained in:
Charis Kyriakou 2024-02-28 11:45:49 +00:00 коммит произвёл GitHub
Родитель 359ee76d52
Коммит b884cff14d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 34 добавлений и 22 удалений

Просмотреть файл

@ -45,7 +45,7 @@ import type {
} from "./variant-analysis-results-manager";
import { getQueryName, prepareRemoteQueryRun } from "./run-remote-query";
import {
mapVariantAnalysis,
mapVariantAnalysisFromSubmission,
mapVariantAnalysisRepositoryTask,
} from "./variant-analysis-mapper";
import PQueue from "p-queue";
@ -387,7 +387,7 @@ export class VariantAnalysisManager
throw e;
}
const mappedVariantAnalysis = mapVariantAnalysis(
const mappedVariantAnalysis = mapVariantAnalysisFromSubmission(
variantAnalysisSubmission,
variantAnalysisResponse,
);

Просмотреть файл

@ -23,11 +23,11 @@ import {
VariantAnalysisRepoStatus,
} from "./shared/variant-analysis";
export function mapVariantAnalysis(
export function mapVariantAnalysisFromSubmission(
submission: VariantAnalysisSubmission,
response: ApiVariantAnalysis,
apiVariantAnalysis: ApiVariantAnalysis,
): VariantAnalysis {
return mapUpdatedVariantAnalysis(
return mapVariantAnalysis(
{
language: submission.language,
query: {
@ -41,12 +41,23 @@ export function mapVariantAnalysis(
executionStartTime: submission.startTime,
},
undefined,
response,
apiVariantAnalysis,
);
}
export function mapUpdatedVariantAnalysis(
previousVariantAnalysis: Pick<
currentVariantAnalysis: VariantAnalysis,
apiVariantAnalysis: ApiVariantAnalysis,
): VariantAnalysis {
return mapVariantAnalysis(
currentVariantAnalysis,
currentVariantAnalysis.status,
apiVariantAnalysis,
);
}
function mapVariantAnalysis(
currentVariantAnalysis: Pick<
VariantAnalysis,
"language" | "query" | "queries" | "databases" | "executionStartTime"
>,
@ -82,11 +93,11 @@ export function mapUpdatedVariantAnalysis(
fullName: response.controller_repo.full_name,
private: response.controller_repo.private,
},
language: previousVariantAnalysis.language,
query: previousVariantAnalysis.query,
queries: previousVariantAnalysis.queries,
databases: previousVariantAnalysis.databases,
executionStartTime: previousVariantAnalysis.executionStartTime,
language: currentVariantAnalysis.language,
query: currentVariantAnalysis.query,
queries: currentVariantAnalysis.queries,
databases: currentVariantAnalysis.databases,
executionStartTime: currentVariantAnalysis.executionStartTime,
createdAt: response.created_at,
updatedAt: response.updated_at,
status,

Просмотреть файл

@ -128,8 +128,10 @@ export class VariantAnalysisMonitor extends DisposableObject {
// may not be aware of it yet.
const currentStatus = this.getVariantAnalysisStatus(variantAnalysis.id);
variantAnalysis = mapUpdatedVariantAnalysis(
variantAnalysis,
currentStatus,
{
...variantAnalysis,
status: currentStatus,
},
variantAnalysisSummary,
);

Просмотреть файл

@ -4,7 +4,7 @@ import type { VariantAnalysisScannedRepository } from "../../../src/variant-anal
import { VariantAnalysisRepoStatus } from "../../../src/variant-analysis/shared/variant-analysis";
import {
mapScannedRepository,
mapVariantAnalysis,
mapVariantAnalysisFromSubmission,
mapVariantAnalysisRepositoryTask,
} from "../../../src/variant-analysis/variant-analysis-mapper";
import {
@ -17,7 +17,7 @@ import { createMockSubmission } from "../../factories/variant-analysis/shared/va
import { createMockVariantAnalysisRepoTask } from "../../factories/variant-analysis/gh-api/variant-analysis-repo-task";
import { QueryLanguage } from "../../../src/common/query-language";
describe(mapVariantAnalysis.name, () => {
describe(mapVariantAnalysisFromSubmission.name, () => {
const scannedRepos = createMockScannedRepos();
const skippedRepos = createMockSkippedRepos();
const mockApiResponse = createMockApiResponse(
@ -28,7 +28,10 @@ describe(mapVariantAnalysis.name, () => {
const mockSubmission = createMockSubmission();
it("should map an API response and return a variant analysis", () => {
const result = mapVariantAnalysis(mockSubmission, mockApiResponse);
const result = mapVariantAnalysisFromSubmission(
mockSubmission,
mockApiResponse,
);
const {
access_mismatch_repos,

Просмотреть файл

@ -131,11 +131,7 @@ describe("Variant Analysis Monitor", () => {
index + 1,
"codeQL.autoDownloadVariantAnalysisResult",
mapScannedRepository(succeededRepo),
mapUpdatedVariantAnalysis(
variantAnalysis,
variantAnalysis.status,
mockApiResponse,
),
mapUpdatedVariantAnalysis(variantAnalysis, mockApiResponse),
);
});
});