2012-11-17 3 views
7

기여자 플러그인에있는 이름과 문서 페이지에 공헌 한 사람의 Github에서 프로필 링크를 보여줍니다.얻기 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" 
    }, 

그래서 당신은 여기에 모든 웹 페이지를 긁어 필요가 없습니다. 여기

는 자바 스크립트 추출물을 기반으로 그것을 설명하는 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

확인 결과는 여기에서 볼 수 있습니다. 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 사용자 프로필 링크에 매핑 할 수 있어야합니다. <- 어느 부분을 이해하기가 어렵습니까? > GitHub의 사용자 - –

+0

그것은 하드가지도 이메일 ('.mailmap' 유사) 또 다른 레이어를 추가하는 것을하지 않을 것입니다. 당신은 그냥 GitHub의에서 이메일 주소를 검색 할 수 있습니다 – plaes

+1

@MikkoOhtamaa. –

0

까지하고 GitHub의의 API와 상호 작용하는 데 필요하지 않는 한 직접 하나가를 얻을 수 있습니다 레포를 복제 한 다음 복제 된 디렉토리로 들어간 다음 shortlog 명령을 사용하여 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") 

사용 list_contributors 다음과 같이 하나, 우리는 GitHub의 API를 사용하여 상호 작용하고 참여자의 목록을 가져 pytgithub3 래퍼를 사용할 수 GitHub의 API를 사용하고자하는 경우에 참여자를 나열하는 또 하나 개의 방법이 있습니다 :

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