Skip to content

Commit 047cee6

Browse files
authored
Try again to fix inline comments in documentation-style-review-enhanced.yml
1 parent 63466f0 commit 047cee6

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

.github/workflows/documentation-style-review-enhanced.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,33 +306,46 @@ jobs:
306306
}
307307
}
308308
309-
// Helper function to calculate diff position
309+
// Helper function to calculate diff position according to GitHub API
310310
this.calculateDiffPosition = function(patch, targetLine) {
311311
const lines = patch.split('\n');
312312
let position = 0;
313-
let currentLine = 0;
313+
let currentNewLine = 0;
314+
let inHunk = false;
314315
315316
for (const line of lines) {
316-
position++;
317+
// Skip file headers (---, +++)
318+
if (line.startsWith('---') || line.startsWith('+++')) {
319+
continue;
320+
}
317321
318322
if (line.startsWith('@@')) {
319323
// Parse hunk header: @@ -oldStart,oldCount +newStart,newCount @@
320324
const match = line.match(/@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/);
321325
if (match) {
322-
currentLine = parseInt(match[1]) - 1; // Start one before the first line
326+
currentNewLine = parseInt(match[1]) - 1; // Start one before the first line
327+
inHunk = true;
328+
position = 0; // Reset position counter for this hunk
323329
}
324330
continue;
325331
}
326332
333+
if (!inHunk) continue;
334+
335+
// Increment position for every line in the hunk
336+
position++;
337+
327338
if (line.startsWith('+')) {
328-
currentLine++;
329-
if (currentLine === targetLine) {
339+
// This is an added line
340+
currentNewLine++;
341+
if (currentNewLine === targetLine) {
330342
return position;
331343
}
332344
} else if (line.startsWith(' ')) {
333-
currentLine++;
345+
// This is a context line (unchanged)
346+
currentNewLine++;
334347
}
335-
// Lines starting with '-' don't increment currentLine (they're deleted)
348+
// Lines starting with '-' don't increment currentNewLine (they're deleted)
336349
}
337350
338351
return -1; // Line not found in diff

0 commit comments

Comments
 (0)