title: How to comment on a specific line number on a PR on github
body: <p>I am trying to write a small script that can comment on github PRs using eslint output.</p>
  
  <p>The problem is eslint gives me the absolute line numbers for each error.
  But github API wants the line number relative to the diff.</p>
  
  <p>From the github API docs: <a href="https://developer.github.com/v3/pulls/comments/#create-a-comment" rel="noreferrer">https://developer.github.com/v3/pulls/comments/#create-a-comment</a></p>
  
  <blockquote>
    <p>To comment on a specific line in a file, you will need to first
    determine the position in the diff. GitHub offers a
    application/vnd.github.v3.diff media type which you can use in a
    preceding request to view the pull request's diff. The diff needs to
    be interpreted to translate from the line in the file to a position in
    the diff. The position value is the number of lines down from the
    first "@@" hunk header in the file you would like to comment on.  </p>
    
    <p><strong>The line just below the "@@" line is position 1, the next line is 
    position 2, and so on. The position in the file's diff continues to 
    increase through lines of whitespace and additional hunks until a new 
    file is reached.</strong></p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/t37he.png" rel="noreferrer"><img src="https://i.stack.imgur.com/t37he.png" alt="enter image description here"></a></p>
  
  <p>So if I want to add a comment on new line number 5 in the above image, then I would need to pass 12 to the API</p>
  
  <p>My question is how can I easily map between the new line numbers which the eslint will give in it's error messages to the relative line numbers required by the github API</p>
  
  <h3>What I have tried so far</h3>
  
  <p>I am using <a href="https://github.com/sergeyt/parse-diff" rel="noreferrer">parse-diff</a> to convert the diff provided by github API into json object</p>
  
  <pre><code>[{
    "chunks": [{
      "content": "@@ -,OLD_TOTAL_LINES +NEW_STARTING_LINE_NUMBER,NEW_TOTAL_LINES @@",
      "changes": [
      {
        "type": STRING("normal"|"add"|"del"),
        "normal": BOOLEAN,
        "add": BOOLEAN,
        "del": BOOLEAN,
        "ln1": OLD_LINE_NUMBER,
        "ln2": NEW_LINE_NUMBER,
        "content": STRING,
        "oldStart": NUMBER,
        "oldLines": NUMBER,
        "newStart": NUMBER,
        "newLines": NUMBER
      }
    }]
  }]
  </code></pre>
  
  <p>I am thinking of the following algorithm</p>
  
  <ul>
  <li>make an array of new line numbers starting from <code>NEW_STARTING_LINE_NUMBER</code> to 
  <code>NEW_STARTING_LINE_NUMBER+NEW_TOTAL_LINES</code>for each file </li>
  <li>subtract <code>newStart</code> from each number and make it another array <code>relativeLineNumbers</code></li>
  <li>traverse through the array and for each deleted line (<code>type==='del'</code>) increment the corresponding remaining <code>relativeLineNumbers</code></li>
  <li>for another hunk (line having <code>@@</code>) decrement the corresponding remaining <code>relativeLineNumbers</code></li>
  </ul>