使用GitHub API检索特定文件的所有版本 [英] Using GitHub API to retrieve all versions of a specific file

查看:53
本文介绍了使用GitHub API检索特定文件的所有版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试通读(GitHub API)[http://developer.github.com/v3/repos/contents/],以了解如何以编程方式在单个目录中检索特定文件的所有版本存储库.

I am currently trying to read through the (GitHub API)[http://developer.github.com/v3/repos/contents/] to figure out how I can programmatically retrieve all versions of a specific file in a single repository.

我看到一个人可以轻松获得提交列表和单个文件的当前版本.但是,有没有办法列出与特定文件相关的所有提交,然后遍历该文件的所有版本?

I see that one can get the list of commits, and the current version of a single file easily. But, is there a way to list all the commits relevant for a specific file and then iterate through all the versions of that file?

推荐答案

要获取与特定文件相关的提交列表,请使用

To get the list of commits relevant for a specific file, use this API endpoint and specify the path parameter:

GET https://api.github.com/repos/:owner/:repo/commits?path=FILE_PATH

您将获得一个提交对象数组,每个提交对象都有一个sha属性.

You'll get back an array of commit objects, each of which has a sha attribute.

现在您已经拥有所有提交SHA,可以使用此API端点,并指定ref查询参数以设置SHA.因此,对于每个提交SHA,都要求:

Now that you have all the commit SHAs, you can fetch all the different versions of the file using this API endpoint and by specifying the ref query parameter to set the SHA. So, for each commit SHA, make a request to:

GET https://api.github.com/repos/:owner/:repo/contents/:FILE_PATH?ref=SHA

并读取content属性.请注意,内容是Base64编码的,但是您也可以通过设置相关的Accept

and read the content attribute. Notice that the content is Base64 encoded, but you can also request a raw version by setting the relevant Accept HTTP header.

这篇关于使用GitHub API检索特定文件的所有版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆