I searched through all the existing github API s found in here to get blame information of a certain line of code in a source file, but I couldn't find a way to achieve it, such API is not listed in the above site. Can anyone point me a way to get the blame information of a line of code of a source file, which is hosted in github repos without cloning it and running git blame
locally.
Thanks in advance
On GitHub.com, navigate to the main page of the repository. Click to open the file whose line history you want to view. In the upper-right corner of the file view, click Blame to open the blame view.
Summary. The git blame command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was.
You can use git blame <filename> . You will be shown the name of the author, timetag and commit of each code fragment of the file.
The GitHub API v4 has a working blame API. Here's an example of the proper query:
{
# repository name/owner
repository(name: "MidiPlayerJS", owner: "TimMensch") {
# branch name
ref(qualifiedName:"tim") {
target {
# cast Target to a Commit
... on Commit {
# full repo-relative path to blame file
blame(path:"package.json") {
ranges {
commit {
author {
name
}
}
startingLine
endingLine
age
}
}
}
}
}
}
}
This works in the explorer for me.
There's no Blame API in the GitHub REST API http://developer.github.com/v3/
But you can fetch blame information through the new GraphQL API which is in early access mode. see this doc https://developer.github.com/early-access/graphql/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With