Reputation: 4413
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
Upvotes: 11
Views: 5340
Reputation: 4812
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.
Upvotes: 7
Reputation: 1049
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/
Upvotes: 3