From c97735422d19216cf55ebc6f3d4f41e1a7bed0dd Mon Sep 17 00:00:00 2001 From: Rob van der Leek <5324924+robvanderleek@users.noreply.github.com> Date: Tue, 24 Dec 2024 15:54:17 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Store=20full=20findings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/index.js | 22 ++++++++++++---------- src/action.ts | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/dist/index.js b/dist/index.js index fb7c119..aa22b8d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -52486,7 +52486,7 @@ var require_version = __commonJS({ Object.defineProperty(exports2, "__esModule", { value: true }); exports2.version = void 0; exports2.version = { - "revision": "d27204a", + "revision": "61e09ec", "year": "2024" }; } @@ -52574,22 +52574,20 @@ var signale_1 = __importStar(require_signale2()); signale_1.default.config({ displayTimestamp: true }); -function generateMarkdownReport(clBinary) { +function generateMarkdownReport(reportMarkdown, findingsMarkdown) { return __awaiter(this, void 0, void 0, function* () { - const totalsMarkdown = yield (0, exec_1.getExecOutput)(clBinary, ["report", "--format", "markdown"]); - const unitsMarkdown = yield (0, exec_1.getExecOutput)(clBinary, ["findings", "--format", "markdown"]); let result = ""; result += "## CodeLimit Report\n"; result += "\n"; - result += totalsMarkdown.stdout; + result += reportMarkdown; result += "### Findings\n"; - result += unitsMarkdown.stdout; + result += findingsMarkdown; result += "\n"; result += "Generated by [CodeLimit](https://getcodelimit.github.io)\n"; return result; }); } -function updateReportsBranch(octokit, owner, repo, branch, markdownReport) { +function updateReportsBranch(octokit, owner, repo, branch, markdown) { return __awaiter(this, void 0, void 0, function* () { yield (0, github_2.createBranchIfNotExists)(octokit, owner, repo, "_codelimit_reports"); const reportContent = (0, codelimit_1.getReportContent)(); @@ -52606,7 +52604,7 @@ function updateReportsBranch(octokit, owner, repo, branch, markdownReport) { yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", `${branch}/report.json`, reportContent); (0, signale_1.success)(`Updated JSON report in branch _codelimit_reports/${branch}`); } - yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", `${branch}/codelimit.md`, markdownReport); + yield (0, github_2.createOrUpdateFile)(octokit, owner, repo, "_codelimit_reports", `${branch}/codelimit.md`, markdown); (0, signale_1.success)(`Updated markdown report in branch _codelimit_reports/${branch}`); }); } @@ -52652,7 +52650,11 @@ function main() { const clBinary = yield (0, codelimit_1.downloadCodeLimitBinary)(); (0, signale_1.info)("Scanning codebase..."); yield (0, exec_1.exec)(clBinary, ["scan", "."]); - const markdownReport = yield generateMarkdownReport(clBinary); + const reportMarkdown = (yield (0, exec_1.getExecOutput)(clBinary, ["report", "--format", "markdown"])).stdout; + const findingsMarkdown = (yield (0, exec_1.getExecOutput)(clBinary, ["findings", "--format", "markdown"])).stdout; + const findingsFullMarkdown = (yield (0, exec_1.getExecOutput)(clBinary, ["findings", "--full", "--format", "markdown"])).stdout; + const markdownReport = yield generateMarkdownReport(reportMarkdown, findingsMarkdown); + const markdownFullFindingsReport = yield generateMarkdownReport(reportMarkdown, findingsFullMarkdown); const octokit = new action_1.Octokit({ auth: (0, core_1.getInput)("token") }); const doCheck = (0, core_1.getInput)("check") || true; if (doCheck) { @@ -52666,7 +52668,7 @@ function main() { process.exit(1); } try { - yield updateReportsBranch(octokit, owner, repo, branch, markdownReport); + yield updateReportsBranch(octokit, owner, repo, branch, markdownFullFindingsReport); } catch (e) { (0, signale_1.error)("Failed to update reports branch"); if (e instanceof Error) { diff --git a/src/action.ts b/src/action.ts index 568db09..f29f9a9 100644 --- a/src/action.ts +++ b/src/action.ts @@ -23,21 +23,19 @@ signale.config({ displayTimestamp: true }); -async function generateMarkdownReport(clBinary: string) { - const totalsMarkdown = await getExecOutput(clBinary, ['report', '--format', 'markdown']); - const unitsMarkdown = await getExecOutput(clBinary, ['findings', '--format', 'markdown']); +async function generateMarkdownReport(reportMarkdown: string, findingsMarkdown: string) { let result = ''; result += '## CodeLimit Report\n'; result += '\n'; - result += totalsMarkdown.stdout; + result += reportMarkdown; result += '### Findings\n'; - result += unitsMarkdown.stdout; + result += findingsMarkdown; result += '\n'; result += 'Generated by [CodeLimit](https://getcodelimit.github.io)\n'; return result; } -async function updateReportsBranch(octokit: Octokit, owner: string, repo: string, branch: string, markdownReport: string) { +async function updateReportsBranch(octokit: Octokit, owner: string, repo: string, branch: string, markdown: string) { await createBranchIfNotExists(octokit, owner, repo, '_codelimit_reports'); const reportContent = getReportContent(); let badgeContent; @@ -53,7 +51,7 @@ async function updateReportsBranch(octokit: Octokit, owner: string, repo: string await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', `${branch}/report.json`, reportContent); success(`Updated JSON report in branch _codelimit_reports/${branch}`); } - await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', `${branch}/codelimit.md`, markdownReport); + await createOrUpdateFile(octokit, owner, repo, '_codelimit_reports', `${branch}/codelimit.md`, markdown); success(`Updated markdown report in branch _codelimit_reports/${branch}`); } @@ -95,7 +93,11 @@ async function main() { const clBinary = await downloadCodeLimitBinary(); info('Scanning codebase...'); await exec(clBinary, ['scan', '.']); - const markdownReport = await generateMarkdownReport(clBinary); + const reportMarkdown = (await getExecOutput(clBinary, ['report', '--format', 'markdown'])).stdout; + const findingsMarkdown = (await getExecOutput(clBinary, ['findings', '--format', 'markdown'])).stdout; + const findingsFullMarkdown = (await getExecOutput(clBinary, ['findings', '--full', '--format', 'markdown'])).stdout; + const markdownReport = await generateMarkdownReport(reportMarkdown, findingsMarkdown); + const markdownFullFindingsReport = await generateMarkdownReport(reportMarkdown, findingsFullMarkdown); const octokit = new Octokit({auth: getInput('token')}); const doCheck = getInput('check') || true; if (doCheck) { @@ -109,7 +111,7 @@ async function main() { process.exit(1); } try { - await updateReportsBranch(octokit, owner, repo, branch, markdownReport); + await updateReportsBranch(octokit, owner, repo, branch, markdownFullFindingsReport); } catch (e: unknown) { error('Failed to update reports branch'); if (e instanceof Error) {