Skip to content

Commit

Permalink
# This is a combination of 5 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

(wip)

# This is the commit message #2:

(wip)

# This is the commit message #3:

(wip)

# This is the commit message #4:

(wip)

# This is the commit message #5:

(wip)
  • Loading branch information
lucassabreu committed May 31, 2023
1 parent 35c9d88 commit c808469
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 36 deletions.
78 changes: 46 additions & 32 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89734,10 +89734,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, commentId, comments, i, c, e_1;
var _g, _h, _j;
return __generator(this, function (_k) {
switch (_k.label) {
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) {
case 0:
if (!["lines", "methods", "branches"].includes(tableWithTypeLimit)) {
coreExports.error("there is no coverage type ".concat(tableWithTypeLimit));
Expand All @@ -89754,7 +89754,7 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
_a = fromString;
return [4 /*yield*/, require$$6.promisify(require$$0$1.readFile)(file)];
case 1:
cStats = _a.apply(void 0, [(_k.sent()).toString()]);
cStats = _a.apply(void 0, [(_j.sent()).toString()]);
if (baseFile && !require$$0$1.existsSync(baseFile)) {
coreExports.error("base file \"".concat(baseFile, "\" ").concat(notFoundMessage));
baseFile = undefined;
Expand All @@ -89764,51 +89764,65 @@ 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, [(_k.sent()).toString()]);
_k.label = 3;
_b = _c.apply(void 0, [(_j.sent()).toString()]);
_j.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)];
case 4:
body = _e.apply(_d, [_k.sent(), "\n\n"]).concat(signature);
commentId = null;
_k.label = 5;
body = _e.apply(_d, [_j.sent(), "\n\n"]).concat(signature);
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:
_k.trys.push([5, 7, , 8]);
return [4 /*yield*/, github.rest.issues.listComments(__assign(__assign({}, context.repo), { issue_number: context.issue.number }))];
_j.trys.push([5, 7, , 8]);
return [4 /*yield*/, github.rest.users.getAuthenticated()];
case 6:
comments = (_k.sent()).data;
for (i = comments.length - 1; i >= 0; i--) {
c = comments[i];
if (((_h = c.user) === null || _h === void 0 ? void 0 : _h.type) !== "Bot")
continue;
if (!((_j = c.body) === null || _j === void 0 ? void 0 : _j.includes(signature)))
continue;
commentId = c.id;
}
u_1 = _j.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:
e_1 = _k.sent();
coreExports.error(e_1);
_j.sent();
return [3 /*break*/, 8];
case 8:
if (!commentId) return [3 /*break*/, 12];
_k.label = 9;
commentId = null;
_j.label = 9;
case 9:
_k.trys.push([9, 11, , 12]);
return [4 /*yield*/, github.rest.issues.updateComment(__assign(__assign({}, context.repo), { comment_id: commentId, body: body }))];
_j.trys.push([9, 11, , 12]);
return [4 /*yield*/, github.rest.issues.listComments(__assign(__assign({}, context.repo), { issue_number: context.issue.number }))];
case 10:
_k.sent();
return [2 /*return*/];
comments = (_j.sent()).data;
for (i = comments.length - 1; i >= 0; i--) {
c = comments[i];
if (!filter(c))
continue;
if (!((_h = c.body) === null || _h === void 0 ? void 0 : _h.includes(signature)))
continue;
commentId = c.id;
}
return [3 /*break*/, 12];
case 11:
_k.sent();
e_2 = _j.sent();
coreExports.error(e_2);
return [3 /*break*/, 12];
case 12: return [4 /*yield*/, github.rest.issues.createComment(__assign(__assign({}, context.repo), { issue_number: context.issue.number, body: body }))];
case 12:
if (!commentId) return [3 /*break*/, 16];
_j.label = 13;
case 13:
_k.sent();
_j.trys.push([13, 15, , 16]);
return [4 /*yield*/, github.rest.issues.updateComment(__assign(__assign({}, context.repo), { comment_id: commentId, body: body }))];
case 14:
_j.sent();
return [2 /*return*/];
case 15:
_j.sent();
return [3 /*break*/, 16];
case 16: return [4 /*yield*/, github.rest.issues.createComment(__assign(__assign({}, context.repo), { issue_number: context.issue.number, body: body }))];
case 17:
_j.sent();
return [2 /*return*/];
}
});
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js.map

Large diffs are not rendered by default.

21 changes: 18 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { error, getBooleanInput, getInput, setFailed } from "@actions/core";
import {
debug,
error,
getBooleanInput,
getInput,
setFailed,
} from "@actions/core";
import { getOctokit } from "@actions/github";
import { context } from "@actions/github/lib/utils";
import { context, GitHub } from "@actions/github/lib/utils";
import { existsSync, readFile } from "fs";
import { promisify } from "util";

Expand Down Expand Up @@ -219,6 +225,15 @@ ${await comment(cStats, oldStats, tableWithTypeLimit as keyof Metrics)}
${signature}`;

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

try {
const u = await github.rest.users.getAuthenticated();
filter = (c: any) => c?.user?.login === u.data.login;

debug("Using a PAT from " + u.data.login);
} catch (e) {}

let commentId = null;
try {
const comments = (
Expand All @@ -230,7 +245,7 @@ ${signature}`;

for (let i = comments.length - 1; i >= 0; i--) {
const c = comments[i];
if (c.user?.type !== "Bot") continue;
if (!filter(c)) continue;
if (!c.body?.includes(signature)) continue;
commentId = c.id;
}
Expand Down

0 comments on commit c808469

Please sign in to comment.