GitHub REST API - To get only highlight lines from List pull requests files

Talking about this endpoint -

Where we can get file changes information belong to target pull request. Currently the response give me filename and patch (line number that had been modified in the pull request). But patch doesn’t only include updated line (updated line refer to line that has been modified), it also include other lines near updated line too.

For example, I got this patch as a response from calling an API
@@ -20,4 +20,9 @@

As you can see from the picture above, the actual lines that had been modified are from line 23 to 27. But patch gave me line 20,21,22,28 as well.

My goal is to have only updated line for the file that has been updated in pull request. So in the example above, I want it to return only line 23 to 27. Basically I just want to see line number of the line that has highlight color green or red on it. Any suggestion?

You can definitely do something like while there is no API call specific to that what you need :-

Make a function which will →

  • get last commit hash.
  • get second last commit hash.
  • check both files and get changes. (Removed or added)
  • return the difference.

I hope this helps you out which you are looking for.
~ Jainam