diff --git a/packages/canyon-backend/src/cov/coverage.controller.ts b/packages/canyon-backend/src/cov/coverage.controller.ts index 8c9e447d..a149b32b 100755 --- a/packages/canyon-backend/src/cov/coverage.controller.ts +++ b/packages/canyon-backend/src/cov/coverage.controller.ts @@ -5,14 +5,29 @@ import { CoverageSummaryDataMap } from "canyon-data"; import { CoverageMapData } from "istanbul-lib-coverage"; import { CoverageMapDto } from "./dto/coverage-map.dto"; import { CoverageDataComputeService } from "./services/coverage-data-compute.service"; +import { CoverageService } from "./services/coverage.service"; @Controller() export class CoverageController { constructor( private readonly coveragePreStoreService: CoveragePreStoreService, private readonly coverageDataComputeService: CoverageDataComputeService, + private readonly coverageService: CoverageService, ) {} + + // TODO 马上要废弃的接口 @Get("api/coverage/summary/map") + async oldCoverageSummary(@Query() coverageSummaryDto: any): Promise { + const { projectID, sha, reportID } = coverageSummaryDto; + + return this.coverageService.coverageSummaryMap( + projectID, + sha, + reportID, + ); + } + + @Get("api/coverage/summary/v2/map") async coverageSummary( @Query() coverageSummaryDto: CoverageSummaryDto, ): Promise { diff --git a/packages/canyon-backend/src/cov/coverage.module.ts b/packages/canyon-backend/src/cov/coverage.module.ts index 7ea63ed9..773fb376 100755 --- a/packages/canyon-backend/src/cov/coverage.module.ts +++ b/packages/canyon-backend/src/cov/coverage.module.ts @@ -4,12 +4,14 @@ import { CoverageController } from "./coverage.controller"; import { CoveragePreStoreService } from "./services/coverage-pre-store.service"; import { TestExcludeService } from "./services/common/test-exclude.service"; import { CoverageDataComputeService } from "./services/coverage-data-compute.service"; +import { CoverageService } from "./services/coverage.service"; @Module({ controllers: [CoverageController], providers: [ PrismaService, CoveragePreStoreService, + CoverageService, CoverageDataComputeService, TestExcludeService, ], diff --git a/packages/canyon-backend/src/cov/services/coverage-data-compute.service.ts b/packages/canyon-backend/src/cov/services/coverage-data-compute.service.ts index 470e2115..67bc4830 100644 --- a/packages/canyon-backend/src/cov/services/coverage-data-compute.service.ts +++ b/packages/canyon-backend/src/cov/services/coverage-data-compute.service.ts @@ -53,6 +53,7 @@ export class CoverageDataComputeService { sha, reportID, }: CoverageSummaryDto): Promise { + // 直接调用同class下的coverageMap方法 const coverage = await this.coverageMap({ projectID, sha, @@ -121,6 +122,7 @@ export class CoverageDataComputeService { hit = mergeCoverageMap(hit, hits[i]); } + // TODO 这里的覆盖率实体生成方法重复了,期望能够提取出来 const coverageMaps = await this.prisma.coverageMap.findMany({ where: removeNullKeys({ sha, diff --git a/packages/canyon-backend/src/cov/services/coverage.service.ts b/packages/canyon-backend/src/cov/services/coverage.service.ts new file mode 100755 index 00000000..8d800657 --- /dev/null +++ b/packages/canyon-backend/src/cov/services/coverage.service.ts @@ -0,0 +1,41 @@ +import { HttpException, Injectable } from "@nestjs/common"; +import { PrismaService } from "src/prisma/prisma.service"; +import { CoverageSummaryDataMap } from "canyon-data"; +import { decompressedData } from "../../utils/zstd"; + +@Injectable() +export class CoverageService { + constructor(private readonly prisma: PrismaService) {} + + async coverageSummaryMap(projectID, sha: string, reportID: string) { + const coverage = await this.prisma.coverage.findFirst({ + where: { + sha, + projectID, + reportID: reportID, + covType: reportID ? "agg" : "all", + }, + }); + + if (coverage?.summary) { + return decompressedData( + coverage.summary, + ).then((data) => { + return Object.entries(data).map(([key, value]) => { + return { + ...value, + path: key, + }; + }); + }); + } + throw new HttpException( + { + statusCode: 404, + message: "summary data not found", + errorCode: "SUMMARY_DATA_NOT_FOUND", + }, + 404, + ); + } +} diff --git a/packages/canyon-platform/src/pages/index/projects/[id]/commits/helper/index.ts b/packages/canyon-platform/src/pages/index/projects/[id]/commits/helper/index.ts index f5210c54..cfd397e7 100755 --- a/packages/canyon-platform/src/pages/index/projects/[id]/commits/helper/index.ts +++ b/packages/canyon-platform/src/pages/index/projects/[id]/commits/helper/index.ts @@ -59,7 +59,7 @@ export function handleSelectFile({ // @ts-ignore export const getCoverageSummaryMapService = ({ projectID, sha, reportID }) => axios({ - url: "/api/coverage/summary/map", + url: "/api/coverage/summary/v2/map", method: "GET", params: { reportID: reportID,