Skip to content

Commit

Permalink
chore: 🚧 Create PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Dec 3, 2024
1 parent b382378 commit c0667c0
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46749,6 +46749,7 @@ var require_github2 = __commonJS({
exports2.getRepoName = getRepoName;
exports2.getIdentity = getIdentity;
exports2.createOrUpdateFile = createOrUpdateFile;
exports2.createPRComment = createPRComment;
function branchExists(octokit, owner, repo, branchName) {
return __awaiter2(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -46849,6 +46850,16 @@ var require_github2 = __commonJS({
});
});
}
function createPRComment(octokit, owner, repo, prNumber, comment) {
return __awaiter2(this, void 0, void 0, function* () {
yield octokit.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: comment
});
});
}
}
});

Expand Down Expand Up @@ -48910,14 +48921,14 @@ function getBadgeContent(reportContent) {
}
function main() {
return __awaiter(this, void 0, void 0, function* () {
var _a;
var _a, _b;
const filename = yield downloadBinary();
console.log("Scanning codebase...");
yield (0, exec_1.exec)(filename, ["scan", "."]);
const totalsMarkdown = yield (0, exec_1.getExecOutput)(filename, ["report", "--totals", "--format", "markdown"]);
const unitsMarkdown = yield (0, exec_1.getExecOutput)(filename, ["report", "--full", "--format", "markdown"]);
console.log(totalsMarkdown.stdout);
console.log(unitsMarkdown.stdout);
const markdownReport = `${totalsMarkdown.stdout}
${unitsMarkdown.stdout}`;
const doUpload = (0, core_1.getInput)("upload") || false;
const token = (0, core_1.getInput)("token");
const octokit = new action_1.Octokit({ auth: token });
Expand All @@ -48934,16 +48945,21 @@ function main() {
if (reportContent) {
yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", `${branch}/report.json`, reportContent);
}
yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", `${branch}/codelimit.md`, `${totalsMarkdown}
${unitsMarkdown}`);
yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", `${branch}/codelimit.md`, markdownReport);
if (isPullRequest()) {
const prNumber = (_a = github_1.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.number;
if (prNumber) {
yield (0, github_2.createPRComment)(octokit, owner, repo, prNumber, markdownReport);
}
}
let exitCode = 0;
if (doUpload) {
console.log("Uploading results...");
if (!token) {
console.error("Token for upload not provided.");
exitCode = 1;
}
const slug = (_a = github_1.context.payload.repository) === null || _a === void 0 ? void 0 : _a.full_name;
const slug = (_b = github_1.context.payload.repository) === null || _b === void 0 ? void 0 : _b.full_name;
if (slug && branch) {
exitCode = yield (0, exec_1.exec)(filename, ["app", "upload", "--token", token, slug, branch]);
}
Expand Down

0 comments on commit c0667c0

Please sign in to comment.