Skip to content

Commit

Permalink
feat: ✨ Store full findings
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Dec 24, 2024
1 parent 77e9013 commit c977354
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
22 changes: 12 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};
}
Expand Down Expand Up @@ -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)();
Expand All @@ -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}`);
});
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
20 changes: 11 additions & 9 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit c977354

Please sign in to comment.