fix: position calculations

This commit is contained in:
Tomasz Stefaniak 2025-08-14 10:18:39 -07:00
parent d6ff7dae2d
commit bb6f936414
2 changed files with 21 additions and 3 deletions

View file

@ -61,6 +61,11 @@ jobs:
# Annotate diff with GitHub API positions
node ${{ github.workspace }}/pr-review-action/scripts/annotate-diff.js pr_diff.txt > pr_diff_annotated.txt
# Debug: Show sample of annotated diff
echo "=== SAMPLE OF ANNOTATED DIFF ==="
head -100 pr_diff_annotated.txt | grep -E "^\[POS:|^@@|^diff --git" || head -50 pr_diff_annotated.txt
echo "=== END SAMPLE ==="
# Create review prompt for inline comments
cat > inline_review_prompt.txt << 'EOF'
@ -225,6 +230,12 @@ jobs:
body: comment.body
}));
// Debug: Log the positions we're trying to use
console.log('Attempting to post comments with positions:');
comments.forEach(c => {
console.log(` ${c.path}: position ${c.position}`);
});
// Create the review
if (comments.length > 0) {
try {

View file

@ -16,9 +16,16 @@ function annotateDiff(diffContent) {
let inHunk = false;
for (const line of lines) {
// Pass through git headers unchanged
if (line.startsWith('diff --git') ||
line.startsWith('index ') ||
// Handle new file - reset position counter
if (line.startsWith('diff --git')) {
githubPos = 0;
inHunk = false;
output.push(line);
continue;
}
// Pass through other git headers unchanged
if (line.startsWith('index ') ||
line.startsWith('---') ||
line.startsWith('+++') ||
line.startsWith('rename ') ||