12

ドキュメントページに貢献した人の名前とGithubプロファイルリンクを表示するSphinxドキュメントシステムプラグイン用のプラグインを構築することを計画しています。

Githubにはこの機能が内部にあります

寄稿者

  • Github APIを介してファイル寄稿者のGithubプロファイルリンクを取得することは可能ですか?コミットメールは十分ではないことに注意してください。Githubユーザープロファイルリンクにマップできる必要があります。また、すべてのリポジトリ寄稿者が必要なわけではなく、個々のファイル寄稿者だけが必要であることに注意してください。

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

4

4 に答える 4

17

まず、特定のファイルのコミットを表示できます。

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

例えば:

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

html_url次に、そのJSON応答には、作成者セクションに、GitHubプロファイルへの''という名前のURLが含まれています。

"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抽出に基づいて、それを説明するための非常に大雑把な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);
        }
    });

GiHubファイルから寄稿者を取得する

于 2013-10-05T16:57:01.787 に答える
6

GraphQL API v4を使用すると、次のものを使用できます。

{
  repository(owner: "torvalds", name: "linux") {
    object(expression: "master") {
      ... on Commit {
        history(first: 100, path: "MAINTAINERS") {
          nodes {
            author {
              email
              name
              user {
                email
                name
                avatarUrl
                login
                url
              }
            }
          }
        }
      }
    }
  }
}

エクスプローラーで試してみてください

を使用して、このファイルの最初の100人の寄稿者のリストを重複なしで取得します。

TOKEN=<YOUR_TOKEN>
OWNER=torvalds
REPO=linux
BRANCH=master
FILEPATH=MAINTAINERS
curl -s -H "Authorization: token $TOKEN" \
     -H  "Content-Type:application/json" \
     -d '{ 
          "query": "{repository(owner: \"'"$OWNER"'\", name: \"'"$REPO"'\") {object(expression: \"'"$BRANCH"'\") { ... on Commit { history(first: 100, path: \"'"$FILEPATH"'\") { nodes { author { email name user { email name avatarUrl login url}}}}}}}}"
      }' https://api.github.com/graphql | \
      jq '[.data.repository.object.history.nodes[].author| {name,email}]|unique'
于 2018-12-28T01:59:53.167 に答える
1

そのためにGithubAPIを使用する必要があるのはなぜですか?パッケージのクローンを作成して使用できますgit log

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

于 2012-11-17T13:13:35.453 に答える
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")

GITHUB APIを使用する場合に備えて、寄稿者を一覧表示する方法がもう1つあります。pytgithub3ラッパーを使用してGITHUB APIとやり取りし、list_contributorsを使用して次のように寄稿者のリストを取得できます。

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
于 2015-01-30T02:54:18.357 に答える