-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5450d47
commit f1828f7
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require('fs/promises') | ||
|
||
function parseFilePath(filePathLine) { | ||
return filePathLine.split(' ')[2].split('/').slice(1).join('/') | ||
} | ||
|
||
function parseRange(rangeLine) { | ||
const [_fromRange, toRange] = rangeLine.split(' ').slice(1, 3) | ||
const [startLine, numLines] = toRange.slice(1).split(',').map(Number) | ||
const range = [startLine, startLine + numLines] | ||
return range | ||
} | ||
|
||
async function parseChanges(diffPath) { | ||
const diff = await fs.readFileSync(diffPath, 'utf8') | ||
const lines = diff.split('\n') | ||
let currentFile = null | ||
let currentRange = null | ||
let changes = [] | ||
|
||
for (const line of lines) { | ||
if (line.startsWith('diff')) { | ||
currentFile = parseFilePath(line) | ||
currentRange = null | ||
} | ||
if (line.startsWith('@@')) { | ||
currentRange = parseRange(line) | ||
changes.push({ file: currentFile, range: currentRange }) | ||
} | ||
} | ||
|
||
return changes | ||
} | ||
|
||
function formatChanges(changes) { | ||
return changes.map((change) => `${change.file}#L${change.range[0]}-L${change.range[1]}`).join('\n') | ||
} | ||
|
||
async function main() { | ||
const rawDiffPath = process.argv[2] | ||
console.log('Recieved diff path: %s', rawDiffPath) | ||
const changes = await parseChanges(rawDiffPath) | ||
const output = formatChanges(changes) | ||
|
||
await fs.writeFile('diff-parsed.txt', output) | ||
} | ||
|
||
void main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
async function main() {} | ||
|
||
void main() |