From ad401603fdac7a0b6dc28ad8afa0359ae8031793 Mon Sep 17 00:00:00 2001 From: Allen Zhang <37892968+zhangtao25@users.noreply.github.com> Date: Tue, 14 Nov 2023 19:30:56 +0800 Subject: [PATCH] feat: update --- .../services/trigger-agg-coverage.service.ts | 1 - .../services/aggregation-coverage.service.ts | 24 +++++++++++++++---- .../cleaning-up-outdated-data.service.ts | 1 - .../services/coverage-agg-task.service.ts | 9 +++++++ .../pull-change-code-and-insert-db.service.ts | 1 - packages/canyon-backend/src/utils/coverage.ts | 6 ++++- packages/canyon-data/src/index.ts | 2 +- 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/packages/canyon-backend/src/coverage/services/trigger-agg-coverage.service.ts b/packages/canyon-backend/src/coverage/services/trigger-agg-coverage.service.ts index a0aac68c..5eceff64 100644 --- a/packages/canyon-backend/src/coverage/services/trigger-agg-coverage.service.ts +++ b/packages/canyon-backend/src/coverage/services/trigger-agg-coverage.service.ts @@ -63,7 +63,6 @@ export class TriggerAggCoverageService { projectID: true, // 添加 projectID 到返回结果中 }, }); - console.log(commitsAssociatedWithReport,'commitsAssociatedWithReport') for (let i = 0; i < commitsAssociatedWithReport.length; i++) { const { commitSha, projectID } = commitsAssociatedWithReport[i]; await this.prisma.task.create({ diff --git a/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts b/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts index 525c1214..048437c0 100644 --- a/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts +++ b/packages/canyon-backend/src/tasks/services/aggregation-coverage.service.ts @@ -5,6 +5,8 @@ import { } from '../../adapter/coverage-data.adapter'; import { genSummaryMapByCoverageMap, mergeCoverage } from '@canyon/data'; import { getSummaryByPath } from '@canyon/data'; +import { calculateAllNewLineCoverageForProject } from '../../utils/coverage'; +import * as fs from 'fs'; function removeNullKeys(obj) { const newObj = {}; for (const key in obj) { @@ -28,12 +30,9 @@ export class AggregationCoverageService { let mainCov = {}; for (let i = 0; i < coverages.length; i++) { - console.log(coverages[i].relationID, 'coverages[i].relationID'); const singleCov = await getSpecificCoverageData(coverages[i].relationID); - console.log(singleCov, 'singleCov'); mainCov = mergeCoverage(mainCov, singleCov); } - console.log(mainCov, 'mainCov'); const mainCovCoverageData = await createNewCoverageData(mainCov); // 删除老的 @@ -80,7 +79,6 @@ export class AggregationCoverageService { for (const allSummaryKey in allSummary) { // 落库数据 const { total, skipped, covered } = allSummary[allSummaryKey] as any; - console.log(allSummaryKey, total, skipped, covered); await prisma.summary.create({ data: { reportID: reportID, @@ -92,6 +90,24 @@ export class AggregationCoverageService { }, }); } + // const codechanges = await prisma.codechange.findMany({ + // where: { projectID, commitSha, compareTarget }, + // }); + // // 新增行概览逻辑 + // const { total, skipped, covered } = calculateAllNewLineCoverageForProject( + // mainCov, + // codechanges, + // ); + // await prisma.summary.create({ + // data: { + // reportID: reportID, + // metricType: 'newlines', + // commitSha: commitSha, + // total, + // skipped, + // covered, + // }, + // }); } await prisma.coverage.create({ diff --git a/packages/canyon-backend/src/tasks/services/cleaning-up-outdated-data.service.ts b/packages/canyon-backend/src/tasks/services/cleaning-up-outdated-data.service.ts index b6069683..dc351cbc 100644 --- a/packages/canyon-backend/src/tasks/services/cleaning-up-outdated-data.service.ts +++ b/packages/canyon-backend/src/tasks/services/cleaning-up-outdated-data.service.ts @@ -16,6 +16,5 @@ export class CleaningUpOutdatedDataService { }, }, }); - console.log(coverageDeleteManyRes, 'coverageDeleteManyRes'); } } diff --git a/packages/canyon-backend/src/tasks/services/coverage-agg-task.service.ts b/packages/canyon-backend/src/tasks/services/coverage-agg-task.service.ts index d3c26951..fa5752e3 100644 --- a/packages/canyon-backend/src/tasks/services/coverage-agg-task.service.ts +++ b/packages/canyon-backend/src/tasks/services/coverage-agg-task.service.ts @@ -79,6 +79,15 @@ export class CoverageAggTaskService { createdAt: 'desc', }, }); + // 重要逻辑,当聚合任务触发时,先把base_commit_sha更新为最新的,然后再去拉取新的diffLine + await this.prisma.coverage.updateMany({ + where: { + commitSha, + }, + data: { + compareTarget, + }, + }); const { accessToken } = await this.prisma.user.findFirst({ where: { id: reporter, diff --git a/packages/canyon-backend/src/tasks/services/pull-change-code-and-insert-db.service.ts b/packages/canyon-backend/src/tasks/services/pull-change-code-and-insert-db.service.ts index 1f2920bf..c337015d 100644 --- a/packages/canyon-backend/src/tasks/services/pull-change-code-and-insert-db.service.ts +++ b/packages/canyon-backend/src/tasks/services/pull-change-code-and-insert-db.service.ts @@ -4,7 +4,6 @@ import { diffLine } from '../../utils/diffline'; export class PullChangeCodeAndInsertDbService { constructor(private readonly prisma: PrismaService) {} async invoke(projectID, commitSha, compareTarget, accessToken, prisma) { - console.log(projectID, commitSha, compareTarget, accessToken); const codechanges = await prisma.codechange.findMany({ where: { projectID, diff --git a/packages/canyon-backend/src/utils/coverage.ts b/packages/canyon-backend/src/utils/coverage.ts index 4dde5cba..de1d381c 100644 --- a/packages/canyon-backend/src/utils/coverage.ts +++ b/packages/canyon-backend/src/utils/coverage.ts @@ -16,6 +16,7 @@ function getLineCoverage(data: any) { } export function calculateNewLineCoverageForSingleFile(coverage, newLine) { + // console.log(newLine) const lineStats = getLineCoverage(coverage); const rows = []; Object.entries(lineStats).forEach(([lineNumber, count]) => { @@ -31,12 +32,15 @@ export function calculateNewLineCoverageForSingleFile(coverage, newLine) { } export function calculateAllNewLineCoverageForProject(coverages, new_lines) { + // console.log(new_lines) + // console.log(coverages) const rows = []; for (let i = 0; i < new_lines.length; i++) { const newLine = new_lines[i]; - const coverage = coverages.find((c) => c.path === newLine.path); + const coverage = coverages['~/' + newLine.path]; if (coverage) { + // console.log('~/'+newLine.path) rows.push(calculateNewLineCoverageForSingleFile(coverage, newLine)); } } diff --git a/packages/canyon-data/src/index.ts b/packages/canyon-data/src/index.ts index bcd6d399..42503390 100644 --- a/packages/canyon-data/src/index.ts +++ b/packages/canyon-data/src/index.ts @@ -96,7 +96,7 @@ export const genSummaryMapByCoverageMap = (coverageMapData: CoverageMapData,code s = fc.toSummary(); summaryMap[f] = { ...s.data, - newlines:calculateNewLineCoverageForSingleFile(fc.data,codeChanges?.find(c=>c.path===f)?.additions||[]) + newlines:calculateNewLineCoverageForSingleFile(fc.data,codeChanges?.find(c=>`~/${c.path}`===f)?.additions||[]) }; }); return JSON.parse(JSON.stringify(summaryMap));