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 dfc89c1 commit b382378
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import {getInput} from "@actions/core";
import {promisify} from "util";
import {context} from "@actions/github";
import {Octokit} from "@octokit/action";
import {branchExists, createBranch, createInitialCommit, createOrUpdateFile, getRepoName, getRepoOwner} from "./github";
import {
branchExists,
createBranch,
createInitialCommit,
createOrUpdateFile,
createPRComment,
getRepoName,
getRepoOwner
} from "./github";
import {exec, getExecOutput} from "@actions/exec";
import {makeBadge} from "badge-maker";

Expand Down Expand Up @@ -140,8 +148,7 @@ async function main() {
await exec(filename, ['scan', '.']);
const totalsMarkdown = await getExecOutput(filename, ['report', '--totals', '--format', 'markdown']);
const unitsMarkdown = await getExecOutput(filename, ['report', '--full', '--format', 'markdown']);
console.log(totalsMarkdown.stdout);
console.log(unitsMarkdown.stdout);
const markdownReport = `${totalsMarkdown.stdout}\n${unitsMarkdown.stdout}`;
const doUpload = getInput('upload') || false;
const token = getInput('token');
const octokit = new Octokit({auth: token});
Expand All @@ -158,7 +165,13 @@ async function main() {
if (reportContent) {
await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', `${branch}/report.json`, reportContent);
}
await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', `${branch}/codelimit.md`, `${totalsMarkdown}\n${unitsMarkdown}`);
await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', `${branch}/codelimit.md`, markdownReport);
if (isPullRequest()) {
const prNumber = context.payload.pull_request?.number;
if (prNumber) {
await createPRComment(octokit, owner, repo, prNumber, markdownReport);
}
}
let exitCode = 0;
if (doUpload) {
console.log('Uploading results...');
Expand Down
9 changes: 9 additions & 0 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ export async function createOrUpdateFile(octokit: Octokit, owner: string, repo:
}
});
}

export async function createPRComment(octokit: Octokit, owner: string, repo: string, prNumber: number, comment: string) {
await octokit.issues.createComment({
owner: owner,
repo: repo,
issue_number: prNumber,
body: comment
});
}

0 comments on commit b382378

Please sign in to comment.