Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 14, 2023
1 parent 350f73e commit ad40160
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);

// 删除老的
Expand Down Expand Up @@ -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,
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ export class CleaningUpOutdatedDataService {
},
},
});
console.log(coverageDeleteManyRes, 'coverageDeleteManyRes');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion packages/canyon-backend/src/utils/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand All @@ -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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/canyon-data/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit ad40160

Please sign in to comment.