({ reportRepo, reportPath }: LooseRecord)
| 398 | } |
| 399 | |
| 400 | function readReport({ reportRepo, reportPath }: LooseRecord): CommitFindingReportReadResult { |
| 401 | const local = args["report-file"] ?? args.report_file; |
| 402 | if (typeof local === "string") { |
| 403 | return { ok: true, markdown: fs.readFileSync(path.resolve(local), "utf8") }; |
| 404 | } |
| 405 | try { |
| 406 | const content = ghText([ |
| 407 | "api", |
| 408 | `repos/${reportRepo}/contents/${reportPath}`, |
| 409 | "--method", |
| 410 | "GET", |
| 411 | "-f", |
| 412 | "ref=main", |
| 413 | "--jq", |
| 414 | ".content", |
| 415 | ]); |
| 416 | return { |
| 417 | ok: true, |
| 418 | markdown: Buffer.from(content.replace(/\s+/g, ""), "base64").toString("utf8"), |
| 419 | }; |
| 420 | } catch (error) { |
| 421 | const message = ghErrorText(error) || `failed to fetch ${reportRepo}:${reportPath}`; |
| 422 | if (isMissingGithubContentError(message)) { |
| 423 | return missingCommitFindingReport(String(reportRepo), String(reportPath)); |
| 424 | } |
| 425 | die(message); |
| 426 | throw new Error(message); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | function parseCommitReport(markdown: string) { |
| 431 | const match = markdown.match(/^---\n([\s\S]*?)\n---\n?/); |
no test coverage detected