From d1440e70858771bffe8cb28ae0b3a2812a9de3ab Mon Sep 17 00:00:00 2001 From: zhangtao25 Date: Tue, 19 Nov 2024 20:09:38 +0800 Subject: [PATCH] chore: repo overall update --- .../services/coverage-map-client.service.ts | 7 +---- packages/canyon-collect/src/utils/coverage.ts | 6 +++++ .../canyon-platform/app/api/cov/map/route.ts | 26 ++++++++++++++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/packages/canyon-collect/src/apps/collect/services/coverage-map-client.service.ts b/packages/canyon-collect/src/apps/collect/services/coverage-map-client.service.ts index 6bebc4f1..429b421b 100755 --- a/packages/canyon-collect/src/apps/collect/services/coverage-map-client.service.ts +++ b/packages/canyon-collect/src/apps/collect/services/coverage-map-client.service.ts @@ -4,7 +4,7 @@ import { // IstanbulHitMapSchema, IstanbulMapMapSchema, } from '../../../zod/istanbul.zod'; -import { compressedData } from '../../../utils/zstd'; +import { compressedData, decompressedData } from '../../../utils/zstd'; import { formatReportObject, regularData, @@ -17,8 +17,6 @@ import { coverageObj } from '../models/coverage.model'; export class CoverageMapClientService { constructor(private readonly prisma: PrismaService) {} async invoke({ sha, projectID, coverage, instrumentCwd, branch }) { - // const { sha, projectID } = invoke; - const coverageObject = typeof coverage === 'string' ? JSON.parse(coverage) : coverage; @@ -31,9 +29,7 @@ export class CoverageMapClientService { removeStartEndNull(formatedCoverage), ); - // coverage const formatCoverageStr = JSON.stringify(formatCoverageMap); - // const size = new TextEncoder().encode(formatCoverageStr).length const compressedFormatCoverageStr = await compressedData(formatCoverageStr); // ****************************************************** @@ -44,7 +40,6 @@ export class CoverageMapClientService { // ****************************************************** // ****************************************************** - // this.prisma.coverage.find({}) return this.prisma.coverage .create({ data: { diff --git a/packages/canyon-collect/src/utils/coverage.ts b/packages/canyon-collect/src/utils/coverage.ts index 5fb9fc97..2b5aecd4 100644 --- a/packages/canyon-collect/src/utils/coverage.ts +++ b/packages/canyon-collect/src/utils/coverage.ts @@ -111,10 +111,13 @@ export function regularData(data: any) { // TODO:在覆盖率map数据上来的时候,有必要做一次过滤,去掉start和end为空的情况。然后再交由zod进行校验,这里需要非常严格的校验。 export const removeStartEndNull = (coverage) => { + console.log(Object.keys(coverage), 'coverage'); const obj = {}; Object.keys(coverage).forEach((key) => { const item = coverage[key]; + console.log(key); + // 创建一个新的branchMap,用于存储处理后的结果 const newBranchMap = {}; @@ -149,8 +152,11 @@ export const removeStartEndNull = (coverage) => { ...item, branchMap: newBranchMap, }; + } else { + obj[key] = item; } }); // fs.writeFileSync('./coverage.json', JSON.stringify(obj)); + console.log(Object.keys(obj), 'obj'); return obj; }; diff --git a/packages/canyon-platform/app/api/cov/map/route.ts b/packages/canyon-platform/app/api/cov/map/route.ts index 14598567..2345640c 100644 --- a/packages/canyon-platform/app/api/cov/map/route.ts +++ b/packages/canyon-platform/app/api/cov/map/route.ts @@ -2,20 +2,24 @@ import prisma from "@/lib/prisma"; import { compressedData, decompressedData } from "@/utils/zstd"; import { formatReportObject, remapCoverage } from "@/utils/coverage"; +import { NextRequest } from "next/server"; // import { decompressedData } from "@/utils/zstd"; // import { compress, decompress } from "@mongodb-js/zstd"; -export async function GET() { +// localhost:3000/api/cov/map?sha=0cacb37b236c9507004505662a0d6bfb018aaec4&project_id=490316875 +export async function GET(request: NextRequest) { + const { searchParams } = request.nextUrl; + const projectID = searchParams.get("project_id"); + const sha = searchParams.get("sha"); + const filepath = searchParams.get("filepath"); const data = await prisma.coverage.findFirst({ where: { - projectID: "490316875", - sha: "0cacb37b236c9507004505662a0d6bfb018aaec4", + projectID: projectID, + sha: sha, }, }); - // console.log(data.instrumentCwd); - const d = await decompressedData(data.map) .then((r) => r.toString()) .then((r) => JSON.parse(r)); @@ -32,7 +36,6 @@ export async function GET() { path: key, }; } - // console.log(data,'') function addInstrumentCwd(cov) { const o = {}; for (const key in cov) { @@ -49,5 +52,14 @@ export async function GET() { instrumentCwd: data.instrumentCwd, }), ); - return Response.json(r.coverage); + return Response.json( + Object.entries(r.coverage) + .filter(([key, value]) => (filepath === null ? true : key === filepath)) + .reduce((acc, [key, value]) => { + return { + ...acc, + [key]: value, + }; + }, {}), + ); }