I have found a solution. I did not add it here because it includes a simple loop and nothing special. But in any case, answering now to help others.
I opened a transfer request in order to create a similar situation, as shown on the question https://github.com/harryi3t/5134/pull/7/files

Using the Github API, you can get diff data. I wrote a small JS wrapper for it https://github.com/harryi3t/github-adapter/blob/master/src/Adapter.js#L223
diff --git a/test.js b/test.js index 2aa9a08..066fc99 100644 --- a/test.js +++ b/test.js @@ -2,14 +2,7 @@ var hello = require('./hello.js'); -var names = [ - 'harry', - 'barry', - 'garry', - 'harry', - 'barry', - 'marry', -]; +var names = ['harry', 'barry', 'garry', 'harry', 'barry', 'marry']; var names2 = [ 'harry', @@ -23,9 +16,7 @@ var names2 = [ // after this line new chunk will be created var names3 = [ 'harry', - 'barry', - 'garry', 'harry', 'barry', - 'marry', + 'marry', 'garry', ];
Now just pass this data to the diff-parse module and do the calculations.
var parsedFiles = parseDiff(data);
It will print
type (ln1) old line (ln2) new line (ln) added/deleted line relative line normal 2 2 - 1 normal 3 3 - 2 normal 4 4 - 3 del - - 5 4 del - - 6 5 del - - 7 6 del - - 8 7 del - - 9 8 del - - 10 9 del - - 11 10 del - - 12 11 add - - 5 12 normal 13 6 - 13 normal 14 7 - 14 normal 15 8 - 15 normal 23 16 - 17 normal 24 17 - 18 normal 25 18 - 19 del - - 26 20 del - - 27 21 normal 28 19 - 22 normal 29 20 - 23 del - - 30 24 add - - 21 25 normal 31 22 - 26
Now you can use the relative line number to post a comment using the github api.
For my purpose, I only need relative line numbers for newly added lines, but using the table above, you can also get it for deleted lines.
Here is a link to the linting project in which I used this. https://github.com/harryi3t/lint-github-pr