MCPcopy Create free account
hub / github.com/microsoft/Webwright / extractPythonFromPatch

Function extractPythonFromPatch

assets/compare_trajectory/app.js:567–612  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

565}
566
567function extractPythonFromPatch(text) {
568 const lines = String(text || '').split(/\r?\n/);
569 const blocks = [];
570 let active = null;
571 const flush = () => {
572 if (!active) {
573 return;
574 }
575 const body = active.lines.join('\n').replace(/^\n+|\n+$/g, '');
576 if (body && looksLikePython(body)) {
577 blocks.push({
578 title: active.path,
579 text: body,
580 sourceLabel: active.action.toLowerCase() + ' patch'
581 });
582 }
583 active = null;
584 };
585 lines.forEach((line) => {
586 const fileMatch = line.match(/^\*\*\*\s+(Add|Update|Delete) File:\s+(.+)$/);
587 if (fileMatch) {
588 flush();
589 const action = fileMatch[1];
590 const path = fileMatch[2].trim();
591 active = path.endsWith('.py') && action !== 'Delete' ? { action, path, lines: [] } : null;
592 return;
593 }
594 if (!active) {
595 return;
596 }
597 if (/^\*\*\* End Patch$/.test(line)) {
598 flush();
599 return;
600 }
601 if (line.startsWith('@@') || line.startsWith('-')) {
602 return;
603 }
604 if (line.startsWith('+')) {
605 active.lines.push(line.slice(1));
606 return;
607 }
608 active.lines.push(line);
609 });
610 flush();
611 return blocks;
612}
613
614function extractPythonBlocks(text) {
615 const blocks = [];

Callers 1

extractPythonBlocksFunction · 0.85

Calls 1

flushFunction · 0.85

Tested by

no test coverage detected