获取Github个人文件贡献者 [英] Getting Github individual file contributors
问题描述
我计划为Sphinx文档系统插件构建一个插件,该插件显示贡献给文档页面的人员的姓名和Github配置文件链接。
Github内部具有此功能
-
是否可以通过Github API获取文件撰稿人的Github配置文件链接?请注意,提交者电子邮件是不够的,必须能够将它们映射到Github用户配置文件链接。另外请注意,我不希望所有的存储库贡献者 - 只是单个文件的贡献者。如果这是不可能的,那么什么样的替代方法(私有API,你可以建议从Github提取这些信息吗?
,您可以显示提交对于给定的文件:
https://api.github.com/repos/:owner/:repo / commitits?path = PATH_TO_FILE
例如:
https://api.github.com/repos/git / git / commits?path = README
其次,JSON响应在作者部分包含一个名为' html_url
'到GitHub配置文件:
au thor:{
login:gitster,
id:54884,
avatar_url:https://0.gravatar.com/avatar/750680c9dcc7d0be3ca83464a0da49d8?d = https%3A%2F%2Fidenticons.github.com%2Ff8e73a1fe6b3a5565851969c2cb234a7.png,
gravatar_id:750680c9dcc7d0be3ca83464a0da49d8,
url:https://api.github.com/users / gitster,
html_url:https://github.com/gitster,< ==========
followers_url:https:// api .github.com / users / gitster / followers,
following_url:https://api.github.com/users/gitster/following{/other_user},
gists_url: https://api.github.com/users/gitster/gists{/gist_id},
starred_url:https://api.github.com/users/gitster/starred{/owner} {/ repo},
subscriptions_url:https://api.github.com/users/gitster/subscriptions,
organizations_url:https://api.github.com / users / gitster / orgs,
repos_url:https://api.github.com/users/gitster/repos,
events_url:https://api.github.com/users/gitster/events{/privacy},
received_events_url:https://api.github.com/users / gitster / received_events,
type:User
},
<所以你不需要在这里刮任何网页。
这是一个非常简单的jsfiddle 来说明,基于javascript解压缩:
var url =https://api.github.com/repos/git/git/commits?path=+文件名
$ .getJSON(url,function(data ){
var twitterList = $(< ul />);
$ .each(data,function(index,item){
if(item.author){
$(< li />,{
text :item.author.html_url
})。appendTo(twitterList);
}
});
I am planning to build a plug-in for Sphinx documentation system plug-in which shows the names and Github profile links of the persons who have contributed to the documentation page.
Github has this feature internally
Is it possible to get Github profile links of the file contributors through Github API? Note that commiter emails are not enough, one must be able to map them to a Github user profile link. Also note that I don't want all repository contributors - just individual file contributors.
If this is not possible then what kind of alternative methods (private API, scraping) you could suggest to extract this information from Github?
First, you can show the commits for a given file:
https://api.github.com/repos/:owner/:repo/commits?path=PATH_TO_FILE
For instance:
https://api.github.com/repos/git/git/commits?path=README
Second, that JSON response does, in the author section, contain an url filed named 'html_url
' to the GitHub profile:
"author": {
"login": "gitster",
"id": 54884,
"avatar_url": "https://0.gravatar.com/avatar/750680c9dcc7d0be3ca83464a0da49d8?d=https%3A%2F%2Fidenticons.github.com%2Ff8e73a1fe6b3a5565851969c2cb234a7.png",
"gravatar_id": "750680c9dcc7d0be3ca83464a0da49d8",
"url": "https://api.github.com/users/gitster",
"html_url": "https://github.com/gitster", <==========
"followers_url": "https://api.github.com/users/gitster/followers",
"following_url": "https://api.github.com/users/gitster/following{/other_user}",
"gists_url": "https://api.github.com/users/gitster/gists{/gist_id}",
"starred_url": "https://api.github.com/users/gitster/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/gitster/subscriptions",
"organizations_url": "https://api.github.com/users/gitster/orgs",
"repos_url": "https://api.github.com/users/gitster/repos",
"events_url": "https://api.github.com/users/gitster/events{/privacy}",
"received_events_url": "https://api.github.com/users/gitster/received_events",
"type": "User"
},
So you shouldn't need to scrape any web page here.
Here is a very crude jsfiddle to illustrate that, based on the javascript extract:
var url = "https://api.github.com/repos/git/git/commits?path=" + filename
$.getJSON(url, function(data) {
var twitterList = $("<ul />");
$.each(data, function(index, item) {
if(item.author) {
$("<li />", {
"text": item.author.html_url
}).appendTo(twitterList);
}
});
这篇关于获取Github个人文件贡献者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!