2012-11-17 8 views
7

私は、ドキュメントページに寄稿した人物の名前とGithubプロファイルリンクを示すSphinxドキュメントシステムプラグイン用のプラグインを構築する予定です。Githubの個々のファイル投稿者を取得する

Githubのがこの機能を持っている内部

Contributors

  • それはGitHubのAPIを介してファイルの貢献者のGithubのプロファイルへのリンクを取得することはできますか?コミッターの電子メールでは不十分で、Githubのユーザープロファイルリンクにマップできる必要があります。また、私はすべてのリポジトリの貢献者を望んでいないことに注意してください。

  • Githubからこの情報を抽出することをお勧めしますか?これが可能でない場合は、どのような代替方法(プライベートAPI、スクレイピング)を提案できますか?

答えて

8

まず、あなたはshow the commits for a given fileことができます。例えば

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

https://api.github.com/repos/git/git/commits?path=README

第二に、JSON応答がないこと著者のセクションには、「」という名前のURLが含まれています'をGitHubプロフィールに追加:

"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" 
    }, 

ここでは、どのWebページもスクレイプする必要はありません。ここで


javascriptのエキスに基づいて、あることを示すために、very crude jsfiddleです:まで

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); 
     } 
    }); 

get Contributors from a GiHub file

+0

いつものように、あなたの答えを読むのはとても楽しいです。包括的かつポイントまで。 –

+0

ありがとうございます。これはまさに私が探していたものです。私は賞金を出す前に代替の回答があるかどうかを見るでしょう。 –

+1

OK結果はここに表示されます:https://github.com/miohtama/sphinxcontrib.contributors/ :) –

1

なぜGithub APIを使用する必要がありますか?あなただけのgit logをパッケージのクローンを作成して使用することができます。

git log --format=format:%an path/to/file ver1..ver2 |sort |uniq

+0

。なお、コミッターのメールでは不十分な場合は、それらをGithubのユーザープロフィールリンクにマップできる必要があります。 < - どの部分を理解するのが難しいですか? –

+0

email-> githubユーザをマップする別の層( '.mailmap'に似ています)を追加するのは難しくありません。 – plaes

+1

@MikkoOhtamaa GitHubでメールアドレスを検索することができます。 –

0

、それはGitHubのAPIとの対話する必要がない場合を除き、直接一つは得ることができますレポをクローンしてからクローンディレクトリに入ってから、ショートログコマンドを使ってgithubログファイルからリストを取得することによって貢献者のリスト

import os 
import commands 

cmd = "git shortlog -s -n" 

os.chdir("C:\Users\DhruvOhri\Documents\COMP 6411\pygithub3-0.3") 
os.system("git clone https://github.com/poise/python.git") 
os.chdir("/home/d/d_ohri/Desktop/python") 
output = commands.getoutput(cmd) 
print(output) 
raw_input("press enter to continue") 

1は、GitHubのAPIを使用したい場合は協力者をリストするもう一つの方法がありますが、我々はGitHubのAPIとの対話とlist_contributorsを使用して、以下のような貢献者のリストを取得するにはpytgithub3ラッパーを使用することができます。

from pytgithub3.services.repo import Repo 
r = Repo() 
r.lis_contributors(user='userid/author',repo='repo name') 
for page in r: 
    for result in page: 
      print result