|
1 |
| -import keyBy from 'lodash/keyBy' |
2 |
| -import mapValues from 'lodash/mapValues' |
3 |
| - |
4 | 1 | import { PathContentsRepositorySchema } from './constants'
|
5 | 2 |
|
6 | 3 | export function extractCoverageFromResponse(
|
7 | 4 | repository: PathContentsRepositorySchema | undefined | null
|
8 | 5 | ) {
|
9 | 6 | if (!repository) return null
|
10 |
| - const commit = repository?.commit |
11 |
| - const branch = repository?.branch?.head |
12 |
| - const coverageSource = (commit || branch)?.coverageAnalytics |
| 7 | + |
| 8 | + const commit = repository.commit |
| 9 | + const branch = repository.branch?.head |
| 10 | + const coverageSource = commit?.coverageAnalytics || branch?.coverageAnalytics |
13 | 11 | const coverageFile = coverageSource?.coverageFile
|
| 12 | + |
14 | 13 | if (!coverageFile) return null
|
15 |
| - const lineWithCoverage = keyBy(coverageFile?.coverage, 'line') |
16 |
| - const fileCoverage = mapValues(lineWithCoverage, 'coverage') |
| 14 | + |
| 15 | + const fileCoverage = Object.fromEntries( |
| 16 | + coverageFile.coverage?.map((item) => [item?.line, item?.coverage]) || [] |
| 17 | + ) |
17 | 18 | const coverageTotal = coverageFile?.totals?.percentCovered
|
18 | 19 | const hashedPath = coverageFile?.hashedPath
|
19 | 20 |
|
20 | 21 | return {
|
21 | 22 | content: coverageFile?.content,
|
22 | 23 | coverage: fileCoverage,
|
23 |
| - totals: |
24 |
| - typeof coverageTotal !== 'number' || isNaN(coverageTotal) |
25 |
| - ? 0 |
26 |
| - : coverageTotal, |
| 24 | + totals: coverageTotal && !Number.isNaN(coverageTotal) ? coverageTotal : 0, |
27 | 25 | flagNames: coverageSource?.flagNames ?? [],
|
28 | 26 | componentNames: coverageSource?.components?.map(({ name }) => name) ?? [],
|
29 | 27 | ...(hashedPath && { hashedPath }),
|
|
0 commit comments