Skip to content

Commit

Permalink
fix: agg bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang committed Dec 5, 2023
1 parent 4f968b2 commit 46357d5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `cov_type` to the `summary` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "summary" ADD COLUMN "cov_type" TEXT NOT NULL;
2 changes: 2 additions & 0 deletions packages/canyon-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ model Summary {
metricType String @map("metric_type")
covType String @map("cov_type")
reportID String @map("report_id")
commitSha String @map("commit_sha")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,34 @@ export class ProjectOverviewService {
newlines: calculateCoverageOverviewByConditionFilter(
summarys.filter(
(item) =>
item.commitSha === commitSha && item.reportID === report.reportID,
item.commitSha === commitSha &&
item.reportID === report.reportID &&
'agg' === item.covType,
),
).newlines.pct,
statements: calculateCoverageOverviewByConditionFilter(
summarys.filter(
(item) =>
item.commitSha === commitSha && item.reportID === report.reportID,
item.commitSha === commitSha &&
item.reportID === report.reportID &&
'agg' === item.covType,
),
).statements.pct,
};

if (!acc[commitSha]) {
acc[commitSha] = {
statements: calculateCoverageOverviewByConditionFilter(
summarys.filter((item) => item.commitSha === commitSha),
//❌
summarys.filter(
(item) => item.commitSha === commitSha && 'all' === item.covType,
),
).statements.pct,
newlines: calculateCoverageOverviewByConditionFilter(
summarys.filter((item) => item.commitSha === commitSha),
//❌
summarys.filter(
(item) => item.commitSha === commitSha && 'all' === item.covType,
),
).newlines.pct,
commitSha,
compareTarget: report.compareTarget,
Expand Down Expand Up @@ -143,7 +153,9 @@ export class ProjectOverviewService {
value: String(
calculateCoverageOverviewByConditionFilter(
summarys.filter(
(item) => item.reportID === aggCovTypeCoverages[0].reportID,
(item) =>
item.reportID === aggCovTypeCoverages[0].reportID &&
'agg' === item.covType,
),
).statements.pct,
),
Expand All @@ -154,15 +166,17 @@ export class ProjectOverviewService {
return {
commitSha: item.commitSha,
statements: calculateCoverageOverviewByConditionFilter(
//❌
summarys.filter(
({ commitSha: curCommitSha }) =>
curCommitSha === item.commitSha,
({ commitSha: curCommitSha, covType }) =>
curCommitSha === item.commitSha && 'all' === covType,
),
).statements.pct,
newlines: calculateCoverageOverviewByConditionFilter(
//❌
summarys.filter(
({ commitSha: curCommitSha }) =>
curCommitSha === item.commitSha,
({ commitSha: curCommitSha, covType }) =>
curCommitSha === item.commitSha && 'all' === covType,
),
).newlines.pct,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,33 @@ export class AggregationCoverageService {
},
});

// 只有是agg的时候要删除就的agg的summary
if (covType === 'agg') {
await prisma.summary.deleteMany({
where: {
// 删除老的
await prisma.summary.deleteMany({
where: removeNullKeys({
reportID: covType === 'agg' ? reportID : null,
commitSha,
covType: covType,
}),
});

// 生成覆盖率数据
const coverageSummaryMap = genSummaryMapByCoverageMap(mainCov, codechanges);

const allSummary = getSummaryByPath('~', coverageSummaryMap);
for (const allSummaryKey in allSummary) {
// 落库数据
const { total, skipped, covered } = allSummary[allSummaryKey] as any;
await prisma.summary.create({
data: {
reportID: reportID,
metricType: allSummaryKey,
commitSha: commitSha,
total,
skipped,
covered,
covType: covType,
},
});

const coverageSummaryMap = genSummaryMapByCoverageMap(
mainCov,
codechanges,
);

const allSummary = getSummaryByPath('~', coverageSummaryMap);
for (const allSummaryKey in allSummary) {
// 落库数据
const { total, skipped, covered } = allSummary[allSummaryKey] as any;
await prisma.summary.create({
data: {
reportID: reportID,
metricType: allSummaryKey,
commitSha: commitSha,
total,
skipped,
covered,
},
});
}
}

await prisma.coverage.create({
Expand Down

0 comments on commit 46357d5

Please sign in to comment.