|
2 | 2 | import Table from "markdown-table"; |
3 | 3 | import { CoverageData } from "../getCoverage"; |
4 | 4 | import "colors"; |
5 | | -import * as core from "@actions/core"; |
6 | 5 |
|
7 | 6 | const coverageTableArray: Array<Array<string>> = []; |
8 | 7 |
|
9 | 8 | const calculatePercantage = (correct: number, total: number): number => { |
10 | | - if (total === 0) { |
11 | | - return 100; |
12 | | - } |
| 9 | + if (total === 0) { |
| 10 | + return 100; |
| 11 | + } |
13 | 12 |
|
14 | | - return (correct * 100) / total; |
| 13 | + return (correct * 100) / total; |
15 | 14 | }; |
16 | 15 |
|
17 | 16 | const calculatePercantageWithString = ( |
18 | | - correct: number, |
19 | | - total: number |
| 17 | + correct: number, |
| 18 | + total: number |
20 | 19 | ): string => { |
21 | | - return `${calculatePercantage(correct, total).toFixed(2)}%`; |
| 20 | + return `${calculatePercantage(correct, total).toFixed(2)}%`; |
22 | 21 | }; |
23 | 22 |
|
24 | 23 | export const generate = ( |
25 | | - { fileCounts, percentage, total, covered, uncovered }: CoverageData, |
26 | | - threshold: number, |
27 | | - baseURL: string |
| 24 | + { fileCounts, percentage, total, covered, uncovered }: CoverageData, |
| 25 | + threshold: number, |
| 26 | + baseURL: string |
28 | 27 | ): string => { |
29 | | - let row = 1; |
30 | | - const headers = [ |
31 | | - "status", |
32 | | - "filenames" + ` (${fileCounts.size})`.gray, |
33 | | - "percent" + ` (${percentage.toFixed(2)}%)`.gray, |
34 | | - "total" + ` (${total})`.gray, |
35 | | - "covered" + ` (${covered})`.gray, |
36 | | - "uncovered" + ` (${uncovered})`.gray |
37 | | - ]; |
| 28 | + let row = 1; |
| 29 | + const headers = [ |
| 30 | + "status", |
| 31 | + "filenames" + ` (${fileCounts.size})`.gray, |
| 32 | + "percent" + ` (${percentage.toFixed(2)}%)`.gray, |
| 33 | + "total" + ` (${total})`.gray, |
| 34 | + "covered" + ` (${covered})`.gray, |
| 35 | + "uncovered" + ` (${uncovered})`.gray |
| 36 | + ]; |
38 | 37 |
|
39 | | - coverageTableArray.push( |
40 | | - headers |
41 | | - // headers.map(() => "---".gray) |
42 | | - ); |
| 38 | + coverageTableArray.push( |
| 39 | + headers |
| 40 | + // headers.map(() => "---".gray) |
| 41 | + ); |
43 | 42 |
|
44 | | - // coverageTable.attrRange( |
45 | | - // { column: [1, 5] }, |
46 | | - // { |
47 | | - // align: "right" |
48 | | - // } |
49 | | - // ); |
| 43 | + // coverageTable.attrRange( |
| 44 | + // { column: [1, 5] }, |
| 45 | + // { |
| 46 | + // align: "right" |
| 47 | + // } |
| 48 | + // ); |
50 | 49 |
|
51 | | - fileCounts.forEach( |
52 | | - ( |
53 | | - { |
54 | | - totalCount, |
55 | | - correctCount |
56 | | - }: { totalCount: number; correctCount: number }, |
57 | | - filename: string |
58 | | - ) => { |
59 | | - row++; |
| 50 | + fileCounts.forEach( |
| 51 | + ( |
| 52 | + { |
| 53 | + totalCount, |
| 54 | + correctCount |
| 55 | + }: { totalCount: number; correctCount: number }, |
| 56 | + filename: string |
| 57 | + ) => { |
| 58 | + row++; |
60 | 59 |
|
61 | | - const fileTypePercentage = Math.floor( |
62 | | - calculatePercantage(correctCount, totalCount) |
63 | | - ); |
| 60 | + const fileTypePercentage = Math.floor( |
| 61 | + calculatePercantage(correctCount, totalCount) |
| 62 | + ); |
64 | 63 |
|
65 | | - const thresholdPassed = fileTypePercentage >= threshold; |
| 64 | + const thresholdPassed = fileTypePercentage >= threshold; |
66 | 65 |
|
67 | | - const hyperlinedFileName = `[\`${filename}\`](${baseURL}/${filename})`; |
| 66 | + const hyperlinedFileName = `[\`${filename}\`](${baseURL}/${filename})`; |
68 | 67 |
|
69 | | - /** |
70 | | - * Insert a 🟥 to indicate that this file has failed the threshold |
71 | | - * or insert a 🟩 |
72 | | - */ |
73 | | - coverageTableArray.push([ |
74 | | - thresholdPassed ? "🟩" : "🟥", |
75 | | - hyperlinedFileName, |
76 | | - calculatePercantageWithString(correctCount, totalCount), |
77 | | - totalCount.toString(), |
78 | | - correctCount.toString(), |
79 | | - (totalCount - correctCount).toString() |
80 | | - ]); |
| 68 | + /** |
| 69 | + * Insert a 🟥 to indicate that this file has failed the threshold |
| 70 | + * or insert a 🟩 |
| 71 | + */ |
| 72 | + coverageTableArray.push([ |
| 73 | + thresholdPassed ? "🟩" : "🟥", |
| 74 | + hyperlinedFileName, |
| 75 | + calculatePercantageWithString(correctCount, totalCount), |
| 76 | + totalCount.toString(), |
| 77 | + correctCount.toString(), |
| 78 | + (totalCount - correctCount).toString() |
| 79 | + ]); |
81 | 80 |
|
82 | | - // coverageTableArray.attrRange( |
83 | | - // { row: [row] }, |
84 | | - // { |
85 | | - // color: |
86 | | - // Math.floor(calculatePercantage(correctCount, totalCount)) >= |
87 | | - // threshold |
88 | | - // ? "green" |
89 | | - // : "red" |
90 | | - // } |
91 | | - // ); |
92 | | - } |
93 | | - ); |
| 81 | + // coverageTableArray.attrRange( |
| 82 | + // { row: [row] }, |
| 83 | + // { |
| 84 | + // color: |
| 85 | + // Math.floor(calculatePercantage(correctCount, totalCount)) >= |
| 86 | + // threshold |
| 87 | + // ? "green" |
| 88 | + // : "red" |
| 89 | + // } |
| 90 | + // ); |
| 91 | + } |
| 92 | + ); |
94 | 93 |
|
95 | | - return Table(coverageTableArray); |
| 94 | + return Table(coverageTableArray); |
96 | 95 | }; |
0 commit comments