如何获取GitHub存储库的描述?

8

每个 GitHub 代码库 都有一个 描述 字段 和一个可选的 网站 字段。如何使用 AJAX 访问这些字段(任何 GitHub 代码库的字段)?

2个回答

11

Github提供API来获取有关存储库的详细信息:

https://api.github.com/repos/<organization>/<project>

例如:https://api.github.com/repos/ruby/ruby

您可以使用简单的jQuery获取所需的信息:

$.ajax('https://api.github.com/repos/ruby/ruby').done(function(json) { 
   // You can access the description as json.description
   console.log(json.description);       
});

很高兴能帮到你 @wolfram77 - tejasbubane
我在我的公共代码库中遇到了问题,我收到了404错误。https://api.github.com/repos/Limraj/dicegame/; https://github.com/Limraj/dicegame - Kamil Tomasz Jarmusik
@KamilTomaszJarmusik 看起来你在链接后面使用了一个尾随斜杠:这个链接对我来说是有效的 https://api.github.com/repos/Limraj/dicegame,但是在 dicegame 后面加上斜杠会导致 404 错误。 - tejasbubane

2
在这个页面上,Select2插件利用github的api搜索存储库并将结果作为json检索出来。完整的github api可以在这里找到。

1
谢谢!我通过这个搜索查询 https://api.github.com/search/repositories?q=<repo>+user:<username> 得到了一个仓库描述。 - wolfram77

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接