MCPcopy
hub / github.com/openclaw/clawsweeper / prepare

Function prepare

src/repair/commit-finding-intake.ts:32–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30else die(`unknown command: ${command}`);
31
32function prepare() {
33 const enabled = stringArg("enabled", "true");
34 const targetRepo = stringArg("target-repo", stringArg("target_repo", "openclaw/openclaw"));
35 const reportRepo = stringArg("report-repo", stringArg("report_repo", "openclaw/clawsweeper"));
36 const sha = assertSha(stringArg("commit-sha", stringArg("commit_sha", "")));
37 const reportPath = stringArg(
38 "report-path",
39 stringArg("report_path", `records/${repoSlug(targetRepo)}/commits/${sha}.md`),
40 );
41 const defaultReportUrl = `https://github.com/${reportRepo}/blob/main/${reportPath}`;
42 const dispatchReportUrl = stringArg("report-url", stringArg("report_url", ""));
43 const reportUrl = isGithubUrl(dispatchReportUrl) ? dispatchReportUrl : defaultReportUrl;
44 const active = truthy(enabled);
45 const reportRead: CommitFindingReportReadResult = active
46 ? readReport({ reportRepo, reportPath })
47 : ({ ok: true, markdown: "" } satisfies CommitFindingReportReadResult);
48 const reportMarkdown = reportRead.ok ? reportRead.markdown : "";
49 const report = parseCommitReport(reportMarkdown);
50 const clusterId = slug(`clawsweeper-commit-${repoSlug(targetRepo)}-${sha.slice(0, 12)}`);
51 const owner = targetRepo.split("/")[0];
52 const jobPath = path.join(repoRoot(), "jobs", owner, "inbox", `${clusterId}.md`);
53 const auditPath = path.join(
54 repoRoot(),
55 "results",
56 "commit-findings",
57 repoSlug(targetRepo),
58 `${sha}.md`,
59 );
60 const branch = `clawsweeper/${clusterId}`;
61 const latestMain = fetchLatestMain(targetRepo);
62 const decision = reportRead.ok
63 ? intakeDecision({ enabled, report, reportMarkdown })
64 : { status: "report_missing", shouldRepair: false, reason: reportRead.reason };
65 const preparedAt = new Date().toISOString();
66 const runDir = decision.shouldRepair
67 ? makeRunDir({ path: jobPath, frontmatter: { mode: "autonomous" } }, "commit-finding")
68 : "";
69
70 const context = {
71 targetRepo,
72 reportRepo,
73 sha,
74 reportPath,
75 reportUrl,
76 report,
77 decision,
78 clusterId,
79 branch,
80 jobPath,
81 auditPath,
82 latestMain,
83 preparedAt,
84 runDir,
85 };
86
87 if (decision.shouldRepair) {
88 writeJob(context, reportMarkdown);
89 writeSyntheticRun(context);

Callers 1

Calls 15

slugFunction · 0.90
isGithubUrlFunction · 0.85
parseCommitReportFunction · 0.85
fetchLatestMainFunction · 0.85
makeRunDirFunction · 0.85
writeSyntheticRunFunction · 0.85
stringArgFunction · 0.70
assertShaFunction · 0.70
repoSlugFunction · 0.70
truthyFunction · 0.70
readReportFunction · 0.70
repoRootFunction · 0.70

Tested by

no test coverage detected