Skip to content

Commit

Permalink
feat: summary
Browse files Browse the repository at this point in the history
  • Loading branch information
lucassabreu committed Feb 2, 2024
1 parent ea8d2cc commit 8701c1b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 47 deletions.
97 changes: 53 additions & 44 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ function requireOidcUtils () {
.catch(error => {
throw new Error(`Failed to get ID Token. \n
Error Code : ${error.statusCode}\n
Error Message: ${error.result.message}`);
Error Message: ${error.message}`);
});
const id_token = (_a = res.result) === null || _a === void 0 ? void 0 : _a.value;
if (!id_token) {
Expand Down Expand Up @@ -89650,7 +89650,7 @@ var maxMethodCoverageDecrease = coreExports.getInput("max-method-coverage-decrea
var minLineCoverage = Number(coreExports.getInput("min-line-coverage"));
var minMethodCoverage = Number(coreExports.getInput("min-method-coverage"));
var showPercentageChangePerFile = coreExports.getBooleanInput("show-percentage-change-on-table");
var comment = function (cStats, oldStats, coverageType) { return __awaiter$1(void 0, void 0, void 0, function () {
var comment = function (cStats, oldStats, coverageType, withTable) { return __awaiter$1(void 0, void 0, void 0, function () {
var w;
return __generator(this, function (_a) {
w = workspace.endsWith("/") ? workspace : workspace.concat("/");
Expand Down Expand Up @@ -89753,10 +89753,10 @@ function checkThreshold(c, o) {
}
var notFoundMessage = "was not found, please check if the path is valid, or if it exists.";
var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
var commit, cStats, _a, oldStats, _b, _c, msgs, body, _d, _e, filter, u_1, commentId, comments, i, c, e_2;
var _g, _h;
return __generator(this, function (_j) {
switch (_j.label) {
var commit, cStats, _a, oldStats, _b, _c, msgs, body, _d, _e, _f, _g, _h, _j, filter, u_1, commentId, comments, i, c, e_2;
var _l, _m;
return __generator(this, function (_o) {
switch (_o.label) {
case 0:
if (!["lines", "methods", "branches"].includes(tableWithTypeLimit)) {
coreExports.error("there is no coverage type ".concat(tableWithTypeLimit));
Expand All @@ -89769,14 +89769,14 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
throw token
? "no Github token was informed !"
: "the Github token informed is not valid";
commit = (_g = utils$2.context.payload.pull_request) === null || _g === void 0 ? void 0 : _g.head.sha.substring(0, 7);
commit = (_l = utils$2.context.payload.pull_request) === null || _l === void 0 ? void 0 : _l.head.sha.substring(0, 7);
if (!require$$0$1.existsSync(file)) {
throw "file \"".concat(file, "\" ").concat(notFoundMessage);
}
_a = fromString;
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(file)];
case 1:
cStats = _a.apply(void 0, [(_j.sent()).toString()]);
cStats = _a.apply(void 0, [(_o.sent()).toString()]);
if (baseFile && !require$$0$1.existsSync(baseFile)) {
coreExports.error("base file \"".concat(baseFile, "\" ").concat(notFoundMessage));
baseFile = undefined;
Expand All @@ -89786,63 +89786,72 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
_c = fromString;
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(baseFile)];
case 2:
_b = _c.apply(void 0, [(_j.sent()).toString()]);
_j.label = 3;
_b = _c.apply(void 0, [(_o.sent()).toString()]);
_o.label = 3;
case 3:
oldStats = _b;
msgs = Array.from(checkThreshold(cStats, oldStats));
msgs.map(coreExports.setFailed);
_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;
return [4 /*yield*/, comment(cStats, oldStats, tableWithTypeLimit)];
return [4 /*yield*/, comment(cStats, oldStats, tableWithTypeLimit, withTable)];
case 4:
body = _e.apply(_d, [_j.sent(), "\n\n"]).concat(signature);
body = _e.apply(_d, [_o.sent(), "\n\n"]).concat(signature);
_g = (_f = coreExports.summary
.addHeading("Coverage Report"))
.addRaw;
_j = (_h = "".concat(msgs.map(function (m) { return "> :warning: ".concat(m); }).join("\n"), "\n\n ")).concat;
return [4 /*yield*/, comment(cStats, oldStats, tableWithTypeLimit, false)];
case 5: return [4 /*yield*/, _g.apply(_f, [_j.apply(_h, [_o.sent()])])
.write()];
case 6:
_o.sent();
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"; };
_j.label = 5;
case 5:
_j.trys.push([5, 7, , 8]);
_o.label = 7;
case 7:
_o.trys.push([7, 9, , 10]);
return [4 /*yield*/, github.rest.users.getAuthenticated()];
case 6:
u_1 = _j.sent();
case 8:
u_1 = _o.sent();
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; };
coreExports.debug("Using a PAT from " + u_1.data.login);
return [3 /*break*/, 8];
case 7:
_j.sent();
return [3 /*break*/, 8];
case 8:
commentId = null;
_j.label = 9;
return [3 /*break*/, 10];
case 9:
_j.trys.push([9, 11, , 12]);
return [4 /*yield*/, github.rest.issues.listComments(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number }))];
_o.sent();
return [3 /*break*/, 10];
case 10:
comments = (_j.sent()).data.filter(filter);
commentId = null;
_o.label = 11;
case 11:
_o.trys.push([11, 13, , 14]);
return [4 /*yield*/, github.rest.issues.listComments(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number }))];
case 12:
comments = (_o.sent()).data.filter(filter);
for (i = comments.length - 1; i >= 0; i--) {
c = comments[i];
if (!((_h = c.body) === null || _h === void 0 ? void 0 : _h.includes(signature)))
if (!((_m = c.body) === null || _m === void 0 ? void 0 : _m.includes(signature)))
continue;
commentId = c.id;
}
return [3 /*break*/, 12];
case 11:
e_2 = _j.sent();
coreExports.error(e_2);
return [3 /*break*/, 12];
case 12:
if (!commentId) return [3 /*break*/, 16];
_j.label = 13;
return [3 /*break*/, 14];
case 13:
_j.trys.push([13, 15, , 16]);
return [4 /*yield*/, github.rest.issues.updateComment(__assign(__assign({}, utils$2.context.repo), { comment_id: commentId, body: body }))];
e_2 = _o.sent();
coreExports.error(e_2);
return [3 /*break*/, 14];
case 14:
_j.sent();
return [2 /*return*/];
if (!commentId) return [3 /*break*/, 18];
_o.label = 15;
case 15:
_j.sent();
return [3 /*break*/, 16];
case 16: return [4 /*yield*/, github.rest.issues.createComment(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number, body: body }))];
_o.trys.push([15, 17, , 18]);
return [4 /*yield*/, github.rest.issues.updateComment(__assign(__assign({}, utils$2.context.repo), { comment_id: commentId, body: body }))];
case 16:
_o.sent();
return [2 /*return*/];
case 17:
_j.sent();
_o.sent();
return [3 /*break*/, 18];
case 18: return [4 /*yield*/, github.rest.issues.createComment(__assign(__assign({}, utils$2.context.repo), { issue_number: utils$2.context.issue.number, body: body }))];
case 19:
_o.sent();
return [2 /*return*/];
}
});
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js.map

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getBooleanInput,
getInput,
setFailed,
summary,
} from "@actions/core";
import { getOctokit } from "@actions/github";
import { context } from "@actions/github/lib/utils";
Expand Down Expand Up @@ -44,7 +45,8 @@ const showPercentageChangePerFile = getBooleanInput(
const comment = async (
cStats: Stats,
oldStats: null | Stats,
coverageType: keyof Metrics
coverageType: keyof Metrics,
withTable: boolean
) => {
const w = workspace.endsWith("/") ? workspace : workspace.concat("/");
cStats.folders.forEach((v, k) =>
Expand Down Expand Up @@ -228,10 +230,29 @@ File: \`${file}\`
${msgs.map((m) => `> :warning: ${m}`).join("\n")}
${await comment(cStats, oldStats, tableWithTypeLimit as keyof Metrics)}
${await comment(
cStats,
oldStats,
tableWithTypeLimit as keyof Metrics,
withTable
)}
${signature}`;

await summary
.addHeading("Coverage Report")
.addRaw(
`${msgs.map((m) => `> :warning: ${m}`).join("\n")}
${await comment(
cStats,
oldStats,
tableWithTypeLimit as keyof Metrics,
false
)}`
)
.write();

let filter = (c: any) => c?.user?.type === "Bot";

try {
Expand Down

0 comments on commit 8701c1b

Please sign in to comment.