I am trying to see, if GitHub API's are available to see contents of repository at a specific commit id level.
Example: I am able to see an output from the below endpoint, where output is provided in JSON. But, this output if from master/main and shows content from the last commit.
Repo URL = https://github.com/kubernetes/kubernetes
URL: https://api.github.com/repos/kubernetes/kubernetes/git/trees/master?recursive=1
Output: Reduced content
{
"sha": "4916b6cd7486e2e0dd6ce5417ae4e6842356954a",
"url": "https://api.github.com/repos/kubernetes/kubernetes/git/trees/4916b6cd7486e2e0dd6ce5417ae4e6842356954a",
"tree": [
{
"path": ".generated_files",
"mode": "100644",
"type": "blob",
"sha": "4e417ab3d2552386cf373e7d41dbdedd7dc5854c",
"size": 766,
"url": "https://api.github.com/repos/kubernetes/kubernetes/git/blobs/4e417ab3d2552386cf373e7d41dbdedd7dc5854c"
},
{
"path": ".gitattributes",
"mode": "100644",
"type": "blob",
"sha": "022e4cde51e5618685b8c946df693c2f04a23fcb",
"size": 381,
"url": "https://api.github.com/repos/kubernetes/kubernetes/git/blobs/022e4cde51e5618685b8c946df693c2f04a23fcb"
},
Question is - How can retrieve a similar output for a specific commit id by using GitHub APIs?
Example: https://github.com/kubernetes/kubernetes/commit/4916b6cd7486e2e0dd6ce5417ae4e6842356954a
CodePudding user response:
You can do this by replacing the branch name (master
) with the commit id.
Additionally if you want information about the commit, you can replace trees
with commits
.