Skip to content

Commit 3647d51

Browse files
committed
fix parser for gitagent commands
1 parent 7ebd8fa commit 3647d51

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ async function fetchFileContent(owner, repo, filePath, ref) {
1515
}
1616

1717
function parseComment(body) {
18-
const lineMatch = body.match(/([^\s#]+)(?:#L(\d+)(?:-L?(\d+))?)?/);
19-
const filePath = lineMatch?.[1]?.replace(/@gitagent\s+(explain|test)\s*/i, "").trim() || null;
20-
const startLine = lineMatch?.[2] ? parseInt(lineMatch[2]) : null;
21-
const endLine = lineMatch?.[3] ? parseInt(lineMatch[3]) : startLine;
18+
const match = body.match(
19+
/@gitagent\s+(?:explain|test)\s+([^\s#]+)(?:#L(\d+)(?:-L?(\d+))?)?/i
20+
);
21+
22+
const filePath = match?.[1] || null;
23+
const startLine = match?.[2] ? parseInt(match[2]) : null;
24+
const endLine = match?.[3] ? parseInt(match[3]) : startLine;
25+
2226
return { filePath, startLine, endLine };
2327
}
2428

0 commit comments

Comments
 (0)