Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 20, 2024
1 parent aeb411c commit 854b776
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { compressedData, decompressedData } from '../../../utils/zstd';
import {
formatReportObject,
regularData,
remapCoverage,
} from '../../../utils/coverage';
import { mergeCoverageMap } from 'canyon-data';
import { genSummaryMapByCoverageMap, mergeCoverageMap } from 'canyon-data';

@Injectable()
export class CoverageClientService {
Expand All @@ -29,9 +30,9 @@ export class CoverageClientService {
const coverageObject =
typeof coverage === 'string' ? JSON.parse(coverage) : coverage;

// const coverageDbMap = await decompressedData(coverageDb.map)
// .then((r) => r.toString())
// .then((r) => JSON.parse(r));
const coverageDbMap = await decompressedData(coverageDb.map)
.then((r) => r.toString())
.then((r) => JSON.parse(r));

const coverageDbHit = await decompressedData(coverageDb.hit)
.then((r) => r.toString())
Expand Down Expand Up @@ -61,16 +62,59 @@ export class CoverageClientService {

// update
// mergeCoveHit
const sss = await compressedData(JSON.stringify(mergeCoveHit));
const hitBuffer = await compressedData(JSON.stringify(mergeCoveHit));

// ********* 生成summary
// 生成summary
// ********* 生成summary

const obj = {};

for (const key in coverageDbMap) {
obj[key] = {
...coverageDbMap[key],
...mergeCoveHit[key],
path: key,
};
}
function addInstrumentCwd(cov) {
const o = {};
for (const key in cov) {
o[coverageDb.instrumentCwd + '/' + key] = {
...cov[key],
path: coverageDb.instrumentCwd + '/' + key,
};
}
return o;
}
const { coverage: mapAndHitCoverage } = await remapCoverage(
addInstrumentCwd(obj),
).then((r) =>
formatReportObject({
coverage: r,
instrumentCwd: coverageDb.instrumentCwd,
}),
);

// 直接存summary,数组形式
const summary = Object.entries(
genSummaryMapByCoverageMap(mapAndHitCoverage, []),
).map(([key, value]) => ({
path: key,
...value,
}));

const summaryBuffer = await compressedData(JSON.stringify(summary));

return this.prisma.coverage.updateMany({
where: {
projectID: projectID,
sha: sha,
covType: 'all',
},
data: {
hit: sss,
// summary: summary,
hit: hitBuffer,
summary: summaryBuffer,
},
});
}
Expand Down
11 changes: 3 additions & 8 deletions packages/canyon-platform/app/api/cov/summary/map/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ export async function GET(request: NextRequest) {
// coverage.summary
const summary = await decompressedData(coverage.summary)
.then((r) => r.toString())
.then((r) => JSON.parse(r))
.then((r) =>
Object.entries(r).map(([key, value]) => ({
...value,
path: key,
})),
);
return summary;
.then((r) => JSON.parse(r));
// return summary;
return Response.json(summary);
}
10 changes: 6 additions & 4 deletions packages/canyon-platform/app/api/sourcecode/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ const headers = {

export async function GET() {
console.log(url, "url");
const res = await axios.get(url, { headers }).then((response) => {
return response.data;
// const res = await axios.get(url, { headers }).then((response) => {
// return response.data;
// });
// console.log(res, "res");
return Response.json({
content: "nihao",
});
console.log(res, "res");
return Response.json(res);
}
// bb5adc06534d19947e6bfc97e3eeecfd55564bed
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use client";
import { useParams } from "next/navigation";
import React, { useMemo } from "react";
import React, { useMemo, useState } from "react";
import useSWR from "swr";
import axios from "axios";
import MainBox from "@/components/main-box";
import { Report } from "canyon-report";
import { Report } from "../../../../../../../canyon-report/src/components";
import { theme } from "antd";
import { genSummaryMapByCoverageMap, getSummaryByPath } from "canyon-data";
const { useToken } = theme;
Expand Down Expand Up @@ -32,6 +32,8 @@ export default function Page() {
const filePath = filepath ? filepath.join("/") : "";
const { token } = useToken();

// const [value, setValue] = useState(window.location.hash.slice(1));

const { data: fileCoverage } = useSWR(
{
url: "/api/cov/map",
Expand Down Expand Up @@ -71,8 +73,8 @@ export default function Page() {
const onSelect = (val) => {
return new Promise((resolve) => {
resolve({
fileContent: "aa",
fileCoverage: {},
fileContent: fileContent.content,
fileCoverage: fileCoverage["src/App.tsx"],
});
});
};
Expand All @@ -87,12 +89,14 @@ export default function Page() {
boxShadow: `${token.boxShadowTertiary}`,
}}
>
<Report
reportName={"reportName"}
dataSource={summary || []}
onSelect={onSelect}
value={""}
/>
{summary?.length && fileContent && fileCoverage && (
<Report
reportName={"reportName"}
dataSource={summary || []}
onSelect={onSelect}
value={"src/App.tsx"}
/>
)}
</div>
</MainBox>
);
Expand Down

0 comments on commit 854b776

Please sign in to comment.