Getting Github individual file contributors

后端 未结 4 676
后悔当初
后悔当初 2020-12-31 11:23

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 documentat

4条回答
  •  悲哀的现实
    2020-12-31 12:14

    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 = $("
      "); $.each(data, function(index, item) { if(item.author) { $("
    • ", { "text": item.author.html_url }).appendTo(twitterList); } });

    get Contributors from a GiHub file

提交回复
热议问题