MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / proposeCommit

Function proposeCommit

src/tools/propose-commit.ts:99–135  ·  view source on GitHub ↗
(options: ProposeCommitOptions)

Source from the content-addressed store, hash-verified

97}
98
99export async function proposeCommit(options: ProposeCommitOptions): Promise<string> {
100 const fullPath = resolve(options.rootDir, options.filePath);
101 const ext = extname(fullPath);
102 const lines = options.newContent.split("\n");
103 const allErrors: ValidationError[] = [];
104
105 if (isSupportedFile(fullPath)) {
106 allErrors.push(...validateHeader(lines, ext));
107 allErrors.push(...validateNoInlineComments(lines, ext));
108 }
109 allErrors.push(...validateAbstraction(lines));
110
111 const commentErrors = allErrors.filter((e) => e.rule === "no-comments");
112 if (commentErrors.length > 5) {
113 return [
114 `REJECTED: ${allErrors.length} violations found.\n`,
115 ...allErrors.slice(0, 10).map((e) => ` ❌ [${e.rule}] ${e.message}`),
116 allErrors.length > 10 ? ` ... and ${allErrors.length - 10} more violations` : "",
117 "\nFix all violations and resubmit.",
118 ].join("\n");
119 }
120
121 const warnings = allErrors.filter((e) => e.rule !== "no-comments" || commentErrors.length <= 5);
122
123 await createRestorePoint(options.rootDir, [options.filePath], `Pre-commit: ${options.filePath}`);
124 await mkdir(dirname(fullPath), { recursive: true });
125 await writeFile(fullPath, options.newContent, "utf-8");
126
127 const result = [`✅ File saved: ${options.filePath}`];
128 if (warnings.length > 0) {
129 result.push(`\n⚠ ${warnings.length} warning(s):`);
130 for (const w of warnings) result.push(` ⚠ [${w.rule}] ${w.message}`);
131 }
132 result.push(`\nRestore point created. Use undo tools if needed.`);
133
134 return result.join("\n");
135}

Callers 3

index.tsFile · 0.85

Calls 5

isSupportedFileFunction · 0.85
validateHeaderFunction · 0.85
validateNoInlineCommentsFunction · 0.85
validateAbstractionFunction · 0.85
createRestorePointFunction · 0.85

Tested by

no test coverage detected