Skip to content

Commit

Permalink
Adjusting line calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Feb 11, 2024
1 parent a17ac79 commit d15471b
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,27 @@ export async function run(): Promise<void> {
const lines = (diffData as unknown as string).split('\n')
let foundMatches = false
let currentFile = ''

Check failure on line 66 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'currentFile' is never reassigned. Use 'const' instead
let currentLineNumber = 0
let oldLineNumber = 0
let newLineNumber = 0

for (const line of lines) {
if (line.startsWith('+++ b/')) {
currentFile = line.substring('+++ b/'.length)
currentLineNumber = 0 // Reset line number for each new file
} else if (line.startsWith('+') || line.startsWith('-')) {
currentLineNumber++ // Count only added or removed lines
if (line.startsWith('@@')) {
// Parse and set the starting line numbers from the hunk header

Check failure on line 72 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
const match = line.match(/-(\d+),\d+ \+(\d+),\d+/)

Check failure on line 73 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
if (match) {

Check failure on line 74 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
oldLineNumber = parseInt(match[1], 10) - 1

Check failure on line 75 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `····`
newLineNumber = parseInt(match[2], 10) - 1

Check failure on line 76 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `··············` with `··········`
}

Check failure on line 77 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
} else {
// Increment the appropriate line number

Check failure on line 79 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
if (line.startsWith('-')) {

Check failure on line 80 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Delete `··`
oldLineNumber++

Check failure on line 81 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

Replace `··············` with `··········`
} else if (line.startsWith('+')) {
newLineNumber++
} else {
oldLineNumber++
newLineNumber++
}
}

if (
Expand Down Expand Up @@ -100,7 +113,7 @@ export async function run(): Promise<void> {
commit_id: context.payload.pull_request.head.sha,
path: currentFile,
side,
line: currentLineNumber
line: side === 'LEFT' ? oldLineNumber : newLineNumber
})
} else {
core.debug(`Match found but already commented`)
Expand Down

0 comments on commit d15471b

Please sign in to comment.