1

我正在尝试允许我的应用程序的用户使用 api 从他们的存储库中提取 git 差异。它工作得很好,除了一个感觉像错误的奇怪案例。

基本上,如果 repo 有多个提交,一切都会顺利进行。但是,如果只有一个初始提交,API 会返回 404 错误,这会降低我页面上的视图。这很奇怪,因为您可以在 github 页面上查看“差异”,或者至少在最近(第一次)提交中更改的文件。

此外,如果我不指定我接受的格式,我可以以另一种格式(不理想)获取差异。

以我朋友的 repo 为例(这是使用 Rails 的 RestClient 而不是 curl)。在她的 repo 中,只有一个提交,这个 404s:

# Replaced fake values (per request) with symbols. Don't feel comfortable sharing her GH info without asking.
RestClient.get("https://api.github.com/repos/:owner/:repo/commits/:sha", accept: 'application/vnd.github.diff')

但这(没有接受)返回提交,只是不是 diff 格式:

RestClient.get("https://api.github.com/repos/:ownder/:repo/commits/:sha")

如果我要从她的其他存储库中提取一个以上的差异,使用

RestClient.get("https://api.github.com/repos/:owner/:repo/commits/:sha", accept: 'application/vnd.github.diff') 

效果很好。难道我做错了什么?这是怎么回事?

4

0 回答 0