Getting diff file using Github API

net project, for which I need to detect and analyze the changes made in a specific text file in the repository between various tensile requests.

I was able to successfully access the migration requests and commits using the Github API, but I don’t know how to get the lines that were changed in the last commit?

Is this possible using the API? What would be a better approach? If not, should I try to read the last two versions of the files and implement a local algorithm with different values? Thanks!

+6
source share
2 answers

The receive request contains a diff_url entry for example

 "diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff" 

You can do this for any commit. For example, to get diff from commit 7fd1a60b01f91b3 in octocat Hello-World, its https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d.diff .

This also works for branches. Here is the eighty-year-old Hello-World master. https://github.com/octocat/Hello-World/commit/master.diff .

General form:

 https://github.com/<owner>/<repo>/commit/<commit>.diff 
+5
source

See Also this answer to get the difference from the API (and not from the user's URL, as in the previous answer):

Github API v3 - getting specific commit differences

This is the link to this GH blog: https://developer.github.com/changes/2012-12-10-Diff-and-patch-media-types/

I found this useful because my tool is configured to interact with the API and not with user-oriented URLs.

0
source

Source: https://habr.com/ru/post/1259190/


All Articles