-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Zhang
committed
Dec 27, 2023
1 parent
07873ea
commit f1157a8
Showing
4 changed files
with
177 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const emptyStatistics = { | ||
newlines: { | ||
total: 0, | ||
covered: 0, | ||
skipped: 0, | ||
pct: 0, | ||
}, | ||
lines: { | ||
total: 0, | ||
covered: 0, | ||
skipped: 0, | ||
pct: 0, | ||
}, | ||
functions: { | ||
total: 0, | ||
covered: 0, | ||
skipped: 0, | ||
pct: 0, | ||
}, | ||
branches: { | ||
total: 0, | ||
covered: 0, | ||
skipped: 0, | ||
pct: 0, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 50 additions & 14 deletions
64
packages/canyon-backend/src/coverage/services/retrieve-coverage-tree-summary.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,82 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from '../../prisma/prisma.service'; | ||
import { getProjectByID } from '../../adapter/gitlab.adapter'; | ||
import { calculateCoverageOverviewByConditionFilter } from '../../utils/summary'; | ||
import { removeNullKeys } from '../../utils/utils'; | ||
import { emptyStatistics } from '../../constant'; | ||
|
||
@Injectable() | ||
export class RetrieveCoverageTreeSummaryService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async invoke(params) { | ||
async invoke(params: { reportID?: string; sha?: string }) { | ||
const redirectUri = process.env.REDIRECT_URI; | ||
const { commitSha } = await this.prisma.summary.findFirst({ | ||
const summaryFindFirst = await this.prisma.summary.findFirst({ | ||
where: removeNullKeys({ | ||
reportID: params.reportID, | ||
commitSha: params.commitSha, | ||
covType: 'all', | ||
commitSha: params.sha, | ||
covType: 'agg', | ||
}), | ||
}); | ||
|
||
const cv = await this.prisma.coverage.findFirst({ | ||
const commitSha = summaryFindFirst?.commitSha; | ||
|
||
if (!commitSha) { | ||
const noCommitShaWithCoverage = await this.prisma.coverage.findFirst({ | ||
where: removeNullKeys({ | ||
reportID: params.reportID, | ||
commitSha: params.sha, | ||
}), | ||
}); | ||
return { | ||
status: 'pending', | ||
reportIDs: [], | ||
sha: noCommitShaWithCoverage?.commitSha || '', | ||
statistics: emptyStatistics, | ||
}; | ||
} | ||
|
||
const coverage = await this.prisma.coverage.findFirst({ | ||
where: { | ||
commitSha, | ||
}, | ||
}); | ||
const repoGitlabInfo = await getProjectByID( | ||
cv.projectID, | ||
'gdr7c7GAPjZ2JXWAZKXH', | ||
); | ||
|
||
const summarys = await this.prisma.summary.findMany({ | ||
where: { | ||
commitSha, | ||
covType: 'all', | ||
}, | ||
}); | ||
// 这边加一下状态,只能根据commit查,并且必须是所有关联的reportID都是success才返回 | ||
|
||
const tasks = await this.prisma.task.findMany({ | ||
where: { | ||
commitSha, | ||
projectID: coverage.projectID, | ||
}, | ||
}); | ||
function getStatus(tasks) { | ||
const state = tasks.every((task) => task.status === 'success'); | ||
if (state) { | ||
return 'success'; | ||
} else if ( | ||
tasks.some( | ||
(task) => task.status === 'running' || task.status === 'notstarted', | ||
) | ||
) { | ||
return 'pending'; | ||
} | ||
return 'fail'; | ||
} | ||
return { | ||
status: getStatus(tasks), | ||
reportIDs: tasks | ||
.filter(({ status }) => status) | ||
.map(({ reportID }) => reportID), | ||
reportUrl: `${(redirectUri || '').replace('/login', '')}/project/${ | ||
cv.projectID | ||
coverage.projectID | ||
}/commits/${commitSha}`, | ||
commitSha: commitSha, | ||
sha: commitSha, | ||
statistics: calculateCoverageOverviewByConditionFilter(summarys), | ||
repo: repoGitlabInfo, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters