| 641 | } |
| 642 | |
| 643 | async function writeReport(target: string, results: SyncResult[]) { |
| 644 | await mkdir(".sync", { recursive: true }); |
| 645 | |
| 646 | const lines = [ |
| 647 | `Updates model TOMLs for the \`${target}\` sync target.`, |
| 648 | "", |
| 649 | "| Provider | Status | Created | Updated | Deleted |", |
| 650 | "| --- | --- | ---: | ---: | ---: |", |
| 651 | ]; |
| 652 | |
| 653 | for (const result of results) { |
| 654 | lines.push( |
| 655 | `| ${result.name} | ${result.status} | ${result.created} | ${result.updated} | ${result.deleted} |`, |
| 656 | ); |
| 657 | } |
| 658 | |
| 659 | for (const result of results.filter((item) => item.files.length > 0)) { |
| 660 | lines.push("", `<details><summary>${result.name} changed files</summary>`, ""); |
| 661 | for (const file of result.files) { |
| 662 | lines.push(`- ${file.status}: \`${file.path}\``); |
| 663 | } |
| 664 | lines.push("", "</details>"); |
| 665 | } |
| 666 | |
| 667 | const noticeResults = results.filter((item) => item.notices.length > 0); |
| 668 | if (noticeResults.length > 0) { |
| 669 | lines.push("", "## Notices"); |
| 670 | for (const result of noticeResults) { |
| 671 | lines.push("", `### ${result.name}`); |
| 672 | for (const notice of result.notices) { |
| 673 | lines.push(`- ${notice}`); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | lines.push("", "This PR was created automatically by the daily model sync workflow."); |
| 679 | await Bun.write(".sync/model-sync-report.md", `${lines.join("\n")}\n`); |
| 680 | } |
| 681 | |
| 682 | function quote(value: string) { |
| 683 | return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`; |