From 63b846c45dc85449f80319be1811597a107669e2 Mon Sep 17 00:00:00 2001 From: zhangtao25 Date: Wed, 20 Nov 2024 22:43:00 +0800 Subject: [PATCH] chore: repo overall update --- packages/canyon-collect/src/app.controller.ts | 137 +----------------- .../services/coverage-client.service.ts | 4 +- 2 files changed, 4 insertions(+), 137 deletions(-) diff --git a/packages/canyon-collect/src/app.controller.ts b/packages/canyon-collect/src/app.controller.ts index ce30d1e0..cce879ee 100644 --- a/packages/canyon-collect/src/app.controller.ts +++ b/packages/canyon-collect/src/app.controller.ts @@ -1,144 +1,9 @@ import { Controller, Get } from '@nestjs/common'; import { AppService } from './app.service'; -import { PrismaService } from './prisma/prisma.service'; -// import { zstdDecompressedData } from './utils/zstd2'; -// import { coverageObj } from './apps/collect/models/coverage.model'; -// import { IstanbulHitMapSchema, IstanbulMapMapSchema } from './zod/istanbul.zod'; -// import { removeStartEndNull } from './utils/coverage'; -// import { compressedData } from './utils/zstd'; -// import { genSummaryMapByCoverageMap, mergeCoverageMap } from 'canyon-data'; -// import fs from 'node:fs'; @Controller() export class AppController { - constructor( - private readonly appService: AppService, - private readonly prisma: PrismaService, - ) { - // (async () => { - // const queueDataToBeConsumed = { - // projectID: 'tripgl-61889-auto', - // sha: 'c35964171aa900bcb99fcda97d91c31414aea6ab', - // }; - // const co = await this.prisma.coverageOld - // .findFirst({ - // where: { - // ...queueDataToBeConsumed, - // covType: 'all', - // }, - // }) - // .then((r) => { - // // const map = r.hit; - // return zstdDecompressedData(r.hit); - // }); - // - // const hit1 = JSON.parse(co); - // - // const coverageMaps = await this.prisma.coverageMap.findMany({ - // where: { - // sha: queueDataToBeConsumed.sha, - // projectID: queueDataToBeConsumed.projectID, - // }, - // }); - // - // const coverageJsonMaps = await Promise.all( - // coverageMaps.map((coverageMap) => { - // return zstdDecompressedData(coverageMap.map).then((map) => { - // return { - // ...coverageMap, - // ...JSON.parse(map), - // }; - // }); - // }), - // ); - // const obj = {}; - // coverageJsonMaps.forEach((item) => { - // if (hit1[item.path]) { - // const o = { - // ...hit1[item.path], - // ...item, - // path: item.path, - // }; - // obj[item.path] = { - // path: o.path, - // b: o.b || {}, - // f: o.f || {}, - // s: o.s || {}, - // branchMap: o.branchMap || {}, - // fnMap: o.fnMap || {}, - // statementMap: o.statementMap || {}, - // }; - // } - // }); - // - // // const { sha, projectID } = coverageMaps; - // - // const branch = 'master'; - // const sha = 'c35964171aa900bcb99fcda97d91c31414aea6ab'; - // const projectID = 'tripgl-61889-auto'; - // - // // const compressedFormatCoverageStr = await - // - // const formatCoverageMap = IstanbulMapMapSchema.parse( - // removeStartEndNull(obj), - // ); - // - // const formatCoverageStr = JSON.stringify(formatCoverageMap); - // const compressedFormatCoverageStr = - // await compressedData(formatCoverageStr); - // - // // hit - // const formatCoverageHit = IstanbulHitMapSchema.parse(obj); - // - // // console.log(coverageMapCount111, formatCoverage); - // - // // ********* 合并 - // // const mergeCoveHit = mergeCoverageMap(coverageDbHit, formatCoverageHit); - // // ********* - // - // // update - // // mergeCoveHit - // const hitBuffer = await compressedData(JSON.stringify(formatCoverageHit)); - // - // // 直接存summary,数组形式 - // const summary = Object.entries(genSummaryMapByCoverageMap(obj, [])).map( - // ([key, value]) => ({ - // path: key, - // ...value, - // }), - // ); - // - // const summaryBuffer = await compressedData(JSON.stringify(summary)); - // - // const rs1 = await this.prisma.coverage.create({ - // data: { - // ...coverageObj, - // branch: branch || '-', - // compareTarget: sha, - // provider: 'github', - // buildProvider: 'github', - // buildID: '', - // projectID: projectID, - // sha: sha, - // reporter: 'canyon', - // reportID: sha, - // covType: 'all', //map都是all - // statementsTotal: 0, - // statementsCovered: 0, - // //空bytes - // summary: summaryBuffer, - // hit: hitBuffer, - // map: compressedFormatCoverageStr, - // instrumentCwd: '', - // }, - // }); - // - // console.log(rs1); - // - // // console.log(obj) - // // fs.writeFileSync('./coverage.json', JSON.stringify(obj)); - // })(); - } + constructor(private readonly appService: AppService) {} @Get() getHello(): string { diff --git a/packages/canyon-collect/src/apps/collect/services/coverage-client.service.ts b/packages/canyon-collect/src/apps/collect/services/coverage-client.service.ts index 043677ab..7b813a87 100755 --- a/packages/canyon-collect/src/apps/collect/services/coverage-client.service.ts +++ b/packages/canyon-collect/src/apps/collect/services/coverage-client.service.ts @@ -32,7 +32,9 @@ export class CoverageClientService { const coverageDbMap = await decompressedData(coverageDb.map); - const coverageDbHit = await decompressedData(coverageDb.hit); + // 初始的hit是空的 + const coverageDbHit = + coverageDb.hit.length > 0 ? await decompressedData(coverageDb.hit) : {}; // 流程需要改一下 // 1. 不反map // 2. 在消费的时候再反map