Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang committed Dec 27, 2023
1 parent 5ef813d commit 07873ea
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 57 deletions.
4 changes: 3 additions & 1 deletion packages/canyon-backend/src/coverage/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type { Response } from 'express';
import { download } from '../utils/download';
import { PrismaService } from '../prisma/prisma.service';
import { getSpecificCoverageData } from '../adapter/coverage-data.adapter';
import { removeNullKeys } from '../utils/utils';
@Controller('')
export class CoverageController {
constructor(
Expand Down Expand Up @@ -56,10 +55,13 @@ export class CoverageController {
reportId?: string;
report_id?: string;
reportID?: string;
commitSha?: string;
commit_sha?: string;
},
) {
return this.triggerAggCoverageService.invoke({
reportID: params.reportId || params.report_id || params.reportID,
commitSha: params.commitSha || params.commit_sha || null,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class RetrieveCoverageTreeSummaryService {
covType: 'all',
},
});
// 这边加一下状态,只能根据commit查,并且必须是所有关联的reportID都是success才返回
return {
reportUrl: `${(redirectUri || '').replace('/login', '')}/project/${
cv.projectID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,100 @@ export class TriggerAggCoverageService {
constructor(private readonly prisma: PrismaService) {}

async invoke(params) {
const { reportID } = params;
const tasks = await this.prisma.task.findMany({
const { commitSha } = params;

const reportIDs = await this.prisma.coverage.findMany({
where: {
reportID,
commitSha,
},
});
const coverages = await this.prisma.coverage.findMany({
where: {
reportID: reportID,
distinct: ['reportID'],
select: {
reportID: true,
},
});
if (coverages.length === 0) {
return {
msg: '未查询到reportId',
data: [],
code: 0,
};
}

// 如果有聚合在跑,就提示在聚合
if (tasks.length > 0 && checkTasksStatus(tasks)) {
return {
msg: '报告聚合中',
data: [],
code: -1,
};
} else {
// 如果这个 reportID聚合完成了,就删除旧的聚合任务,创建新的聚合任务
for (let i = 0; i < tasks.length; i++) {
await this.prisma.task.deleteMany({
where: {
id: tasks[i].id,
},
});
console.log('删除旧的聚合任务' + tasks[i].id);
}
const arr = [];
for (let i = 0; i < reportIDs.length; i++) {
const s = await ffffffff.call(this, { reportID: reportIDs[i].reportID });
arr.push(s);
}

// ********** 重要 **********
// 关键
// ********** 重要 **********
return arr;

const commitsAssociatedWithReport = await this.prisma.coverage.findMany({
async function ffffffff() {
const { reportID } = params;
const tasks = await this.prisma.task.findMany({
where: {
reportID,
},
distinct: ['commitSha'], // 使用 distinct 来确保返回唯一的 commitSha
select: {
commitSha: true,
projectID: true, // 添加 projectID 到返回结果中
});
const coverages = await this.prisma.coverage.findMany({
where: {
reportID: reportID,
},
});
for (let i = 0; i < commitsAssociatedWithReport.length; i++) {
const { commitSha, projectID } = commitsAssociatedWithReport[i];
await this.prisma.task.create({
data: {
name: `Coverage Agg Task ${reportID},commitSha:${commitSha},projectID:${projectID}`,
status: 'notstarted',
reportID,
commitSha: commitSha,
projectID: projectID,
result: {},
},
});
if (coverages.length === 0) {
return {
msg: '未查询到reportId',
data: [],
code: 0,
};
}

return {
msg: '聚合中',
data: [],
code: 1,
};
// 如果有聚合在跑,就提示在聚合
if (tasks.length > 0 && checkTasksStatus(tasks)) {
return {
msg: '报告聚合中',
data: [],
code: -1,
};
} else {
// 如果这个 reportID聚合完成了,就删除旧的聚合任务,创建新的聚合任务
for (let i = 0; i < tasks.length; i++) {
await this.prisma.task.deleteMany({
where: {
id: tasks[i].id,
},
});
console.log('删除旧的聚合任务' + tasks[i].id);
}

// ********** 重要 **********
// 关键
// ********** 重要 **********

const commitsAssociatedWithReport = await this.prisma.coverage.findMany(
{
where: {
reportID,
},
distinct: ['commitSha'], // 使用 distinct 来确保返回唯一的 commitSha
select: {
commitSha: true,
projectID: true, // 添加 projectID 到返回结果中
},
},
);
for (let i = 0; i < commitsAssociatedWithReport.length; i++) {
const { commitSha, projectID } = commitsAssociatedWithReport[i];
await this.prisma.task.create({
data: {
name: `Coverage Agg Task ${reportID},commitSha:${commitSha},projectID:${projectID}`,
status: 'notstarted',
reportID,
commitSha: commitSha,
projectID: projectID,
result: {},
},
});
}

return {
msg: '聚合中',
data: [],
code: 1,
};
}
}
}
}

0 comments on commit 07873ea

Please sign in to comment.