Skip to content

Commit 7063624

Browse files
authored
Merge pull request #52 from lucassabreu/sum
feat: summary
2 parents ea8d2cc + d2656e3 commit 7063624

File tree

4 files changed

+111
-48
lines changed

4 files changed

+111
-48
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- create job step summary
12+
913
## [0.11.0] - 2024-01-29
1014

1115
### Changed

bin/index.js

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ function requireOidcUtils () {
19981998
.catch(error => {
19991999
throw new Error(`Failed to get ID Token. \n
20002000
Error Code : ${error.statusCode}\n
2001-
Error Message: ${error.result.message}`);
2001+
Error Message: ${error.message}`);
20022002
});
20032003
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
20042004
if (!id_token) {
@@ -89650,7 +89650,7 @@ var maxMethodCoverageDecrease = coreExports.getInput("max-method-coverage-decrea
8965089650
var minLineCoverage = Number(coreExports.getInput("min-line-coverage"));
8965189651
var minMethodCoverage = Number(coreExports.getInput("min-method-coverage"));
8965289652
var showPercentageChangePerFile = coreExports.getBooleanInput("show-percentage-change-on-table");
89653-
var comment = function (cStats, oldStats, coverageType) { return __awaiter$1(void 0, void 0, void 0, function () {
89653+
var comment = function (cStats, oldStats, coverageType, withChart, withTable) { return __awaiter$1(void 0, void 0, void 0, function () {
8965489654
var w;
8965589655
return __generator(this, function (_a) {
8965689656
w = workspace.endsWith("/") ? workspace : workspace.concat("/");
@@ -89753,10 +89753,10 @@ function checkThreshold(c, o) {
8975389753
}
8975489754
var notFoundMessage = "was not found, please check if the path is valid, or if it exists.";
8975589755
var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
89756-
var commit, cStats, _a, oldStats, _b, _c, msgs, body, _d, _e, filter, u_1, commentId, comments, i, c, e_2;
89757-
var _g, _h;
89758-
return __generator(this, function (_j) {
89759-
switch (_j.label) {
89756+
var commit, cStats, _a, oldStats, _b, _c, msgs, body, _d, _e, _f, _g, filter, u_1, commentId, comments, i, c, e_2;
89757+
var _j, _k;
89758+
return __generator(this, function (_l) {
89759+
switch (_l.label) {
8976089760
case 0:
8976189761
if (!["lines", "methods", "branches"].includes(tableWithTypeLimit)) {
8976289762
coreExports.error("there is no coverage type ".concat(tableWithTypeLimit));
@@ -89769,14 +89769,14 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
8976989769
throw token
8977089770
? "no Github token was informed !"
8977189771
: "the Github token informed is not valid";
89772-
commit = (_g = utils$2.context.payload.pull_request) === null || _g === void 0 ? void 0 : _g.head.sha.substring(0, 7);
89772+
commit = (_j = utils$2.context.payload.pull_request) === null || _j === void 0 ? void 0 : _j.head.sha.substring(0, 7);
8977389773
if (!require$$0$1.existsSync(file)) {
8977489774
throw "file \"".concat(file, "\" ").concat(notFoundMessage);
8977589775
}
8977689776
_a = fromString;
8977789777
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(file)];
8977889778
case 1:
89779-
cStats = _a.apply(void 0, [(_j.sent()).toString()]);
89779+
cStats = _a.apply(void 0, [(_l.sent()).toString()]);
8978089780
if (baseFile && !require$$0$1.existsSync(baseFile)) {
8978189781
coreExports.error("base file \"".concat(baseFile, "\" ").concat(notFoundMessage));
8978289782
baseFile = undefined;
@@ -89786,63 +89786,87 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
8978689786
_c = fromString;
8978789787
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(baseFile)];
8978889788
case 2:
89789-
_b = _c.apply(void 0, [(_j.sent()).toString()]);
89790-
_j.label = 3;
89789+
_b = _c.apply(void 0, [(_l.sent()).toString()]);
89790+
_l.label = 3;
8979189791
case 3:
8979289792
oldStats = _b;
8979389793
msgs = Array.from(checkThreshold(cStats, oldStats));
8979489794
msgs.map(coreExports.setFailed);
8979589795
_e = (_d = "\nCoverage report for commit: ".concat(commit, "\nFile: `").concat(file, "`\n\n").concat(msgs.map(function (m) { return "> :warning: ".concat(m); }).join("\n"), "\n\n")).concat;
89796-
return [4 /*yield*/, comment(cStats, oldStats, tableWithTypeLimit)];
89796+
return [4 /*yield*/, comment(cStats, oldStats, tableWithTypeLimit, withChart, withTable)];
8979789797
case 4:
89798-
body = _e.apply(_d, [_j.sent(), "\n\n"]).concat(signature);
89799-
filter = function (c) { var _a; return ((_a = c === null || c === void 0 ? void 0 : c.user) === null || _a === void 0 ? void 0 : _a.type) === "Bot"; };
89800-
_j.label = 5;
89798+
body = _e.apply(_d, [_l.sent(), "\n\n"]).concat(signature);
89799+
return [4 /*yield*/, coreExports.summary
89800+
.addHeading("Coverage Report")
89801+
.addRaw("File: <code>".concat(file, "</code>"), true)
89802+
.addBreak()
89803+
.write()];
8980189804
case 5:
89802-
_j.trys.push([5, 7, , 8]);
89803-
return [4 /*yield*/, github.rest.users.getAuthenticated()];
89805+
_l.sent();
89806+
if (!msgs.length) return [3 /*break*/, 7];
89807+
return [4 /*yield*/, coreExports.summary
89808+
.addBreak()
89809+
.addQuote(msgs.map(function (m) { return ":warning: ".concat(m); }).join("\n"))
89810+
.write()];
8980489811
case 6:
89805-
u_1 = _j.sent();
89812+
_l.sent();
89813+
_l.label = 7;
89814+
case 7:
89815+
_g = (_f = coreExports.summary
89816+
.addBreak())
89817+
.addRaw;
89818+
return [4 /*yield*/, comment(cStats, oldStats, tableWithTypeLimit, true, false)];
89819+
case 8: return [4 /*yield*/, _g.apply(_f, [_l.sent(), true])
89820+
.write()];
89821+
case 9:
89822+
_l.sent();
89823+
filter = function (c) { var _a; return ((_a = c === null || c === void 0 ? void 0 : c.user) === null || _a === void 0 ? void 0 : _a.type) === "Bot"; };
89824+
_l.label = 10;
89825+
case 10:
89826+
_l.trys.push([10, 12, , 13]);
89827+
return [4 /*yield*/, github.rest.users.getAuthenticated()];
89828+
case 11:
89829+
u_1 = _l.sent();
8980689830
filter = function (c) { var _a; return ((_a = c === null || c === void 0 ? void 0 : c.user) === null || _a === void 0 ? void 0 : _a.login) === u_1.data.login; };
8980789831
coreExports.debug("Using a PAT from " + u_1.data.login);
89808-
return [3 /*break*/, 8];
89809-
case 7:
89810-
_j.sent();
89811-
return [3 /*break*/, 8];
89812-
case 8:
89832+
return [3 /*break*/, 13];
89833+
case 12:
89834+
_l.sent();
89835+
return [3 /*break*/, 13];
89836+
case 13:
8981389837
commentId = null;
89814-
_j.label = 9;
89815-
case 9:
89816-
_j.trys.push([9, 11, , 12]);
89838+
_l.label = 14;
89839+
case 14:
89840+
_l.trys.push([14, 16, , 17]);
8981789841
return [4 /*yield*/, github.rest.issues.listComments(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number }))];
89818-
case 10:
89819-
comments = (_j.sent()).data.filter(filter);
89842+
case 15:
89843+
comments = (_l.sent()).data.filter(filter);
8982089844
for (i = comments.length - 1; i >= 0; i--) {
8982189845
c = comments[i];
89822-
if (!((_h = c.body) === null || _h === void 0 ? void 0 : _h.includes(signature)))
89846+
if (!((_k = c.body) === null || _k === void 0 ? void 0 : _k.includes(signature)))
8982389847
continue;
8982489848
commentId = c.id;
8982589849
}
89826-
return [3 /*break*/, 12];
89827-
case 11:
89828-
e_2 = _j.sent();
89850+
return [3 /*break*/, 17];
89851+
case 16:
89852+
e_2 = _l.sent();
8982989853
coreExports.error(e_2);
89830-
return [3 /*break*/, 12];
89831-
case 12:
89832-
if (!commentId) return [3 /*break*/, 16];
89833-
_j.label = 13;
89834-
case 13:
89835-
_j.trys.push([13, 15, , 16]);
89854+
return [3 /*break*/, 17];
89855+
case 17:
89856+
if (!commentId) return [3 /*break*/, 21];
89857+
_l.label = 18;
89858+
case 18:
89859+
_l.trys.push([18, 20, , 21]);
8983689860
return [4 /*yield*/, github.rest.issues.updateComment(__assign(__assign({}, utils$2.context.repo), { comment_id: commentId, body: body }))];
89837-
case 14:
89838-
_j.sent();
89861+
case 19:
89862+
_l.sent();
8983989863
return [2 /*return*/];
89840-
case 15:
89841-
_j.sent();
89842-
return [3 /*break*/, 16];
89843-
case 16: return [4 /*yield*/, github.rest.issues.createComment(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number, body: body }))];
89844-
case 17:
89845-
_j.sent();
89864+
case 20:
89865+
_l.sent();
89866+
return [3 /*break*/, 21];
89867+
case 21: return [4 /*yield*/, github.rest.issues.createComment(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number, body: body }))];
89868+
case 22:
89869+
_l.sent();
8984689870
return [2 /*return*/];
8984789871
}
8984889872
});

bin/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getBooleanInput,
55
getInput,
66
setFailed,
7+
summary,
78
} from "@actions/core";
89
import { getOctokit } from "@actions/github";
910
import { context } from "@actions/github/lib/utils";
@@ -44,7 +45,9 @@ const showPercentageChangePerFile = getBooleanInput(
4445
const comment = async (
4546
cStats: Stats,
4647
oldStats: null | Stats,
47-
coverageType: keyof Metrics
48+
coverageType: keyof Metrics,
49+
withChart: boolean,
50+
withTable: boolean
4851
) => {
4952
const w = workspace.endsWith("/") ? workspace : workspace.concat("/");
5053
cStats.folders.forEach((v, k) =>
@@ -228,10 +231,42 @@ File: \`${file}\`
228231
229232
${msgs.map((m) => `> :warning: ${m}`).join("\n")}
230233
231-
${await comment(cStats, oldStats, tableWithTypeLimit as keyof Metrics)}
234+
${await comment(
235+
cStats,
236+
oldStats,
237+
tableWithTypeLimit as keyof Metrics,
238+
withChart,
239+
withTable
240+
)}
232241
233242
${signature}`;
234243

244+
await summary
245+
.addHeading(`Coverage Report`)
246+
.addRaw(`File: <code>${file}</code>`, true)
247+
.addBreak()
248+
.write();
249+
250+
if (msgs.length)
251+
await summary
252+
.addBreak()
253+
.addQuote(msgs.map((m) => `:warning: ${m}`).join("\n"))
254+
.write();
255+
256+
await summary
257+
.addBreak()
258+
.addRaw(
259+
await comment(
260+
cStats,
261+
oldStats,
262+
tableWithTypeLimit as keyof Metrics,
263+
true,
264+
false
265+
),
266+
true
267+
)
268+
.write();
269+
235270
let filter = (c: any) => c?.user?.type === "Bot";
236271

237272
try {

0 commit comments

Comments
 (0)