Skip to content

Commit

Permalink
chore: daily development
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Dec 26, 2024
1 parent 8b88304 commit 8493e24
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/canyon-backend/src/cov/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
const { projectID, sha, reportID } = coverageSummaryDto;

return this.coverageService.coverageSummaryMap(
projectID,
sha,
reportID,
);
}

@Get("api/coverage/summary/v2/map")
async coverageSummary(
@Query() coverageSummaryDto: CoverageSummaryDto,
): Promise<CoverageSummaryDataMap> {
Expand Down
2 changes: 2 additions & 0 deletions packages/canyon-backend/src/cov/coverage.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class CoverageDataComputeService {
sha,
reportID,
}: CoverageSummaryDto): Promise<CoverageSummaryDataMap> {
// 直接调用同class下的coverageMap方法
const coverage = await this.coverageMap({
projectID,
sha,
Expand Down Expand Up @@ -121,6 +122,7 @@ export class CoverageDataComputeService {
hit = mergeCoverageMap(hit, hits[i]);
}

// TODO 这里的覆盖率实体生成方法重复了,期望能够提取出来
const coverageMaps = await this.prisma.coverageMap.findMany({
where: removeNullKeys({
sha,
Expand Down
41 changes: 41 additions & 0 deletions packages/canyon-backend/src/cov/services/coverage.service.ts
Original file line number Diff line number Diff line change
@@ -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<CoverageSummaryDataMap>(
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,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8493e24

Please sign in to comment.