5

GitHub API Gemを使用して、寄稿者の追加、削除、およびコミット数に関する統計を取得しようとしています。問題は、結果が 100 件しか得られず、他のページにアクセスできないことです。非常に一般的な質問のようですが、答えが見つかりませんでした。

たとえば、Rails/Rails リポジトリを見てみましょう。1 990 人の貢献者がいます:

  repo = Github::Repos.new user: 'rails', repo: 'rails'
  repo.stats.contributors

私が得るのは最初の100件の結果です。

リンク ヘッダーに含まれるページネーション情報をクエリしてみました。Railsコンソールでの私の出力:

irb(main):001:0> repo = Github::Repos.new
=> #<Github::Repos:0xa6941dc *@current_options ommited* >

irb(main):002:0> res = repo.stats.contributors user: 'rails', repo: 'rails'
=> #<Github::ResponseWrapper *@body omitted* >

irb(main):003:0> res.links
=> #<Github::PageLinks:0xa2a966c @next=nil, @last=nil>

何もない。

合格auto_paginationオプションは私にとって何も変わりません。

私は何が欠けていますか?

4

3 に答える 3

11

I tried many things and ended up with the underlying GitHub API HTTP methods. For example:

curl https://api.github.com/repos/rails/rails/stats/contributors 

Got nothing. So, I dropped an e-mail to GitHub Support. Here's the answer from Wynn Netherland:

Thanks for getting in touch. That particular method doesn't support pagination, so we're effectively capping the contributors data to 100 as you've discovered. I can't promise if/when we'll be able to show more data on that one since it's sort of an expensive endpoint for us. Keep an eye on the API developer docs for updates.

Thanks Wynn. So, GitHub Repo Statistics API isn't supporting pagination. There is no way to get contributors list with more than 100 results.

于 2013-08-12T15:01:18.297 に答える
1

auto_pagination新しいGitHubインスタンスを作成するときに設定されているように見えるため、オプションを渡すことの意味がわかりません。

github = GitHub.new do |config|
  config.auto_pagination = true
end
github.repos.contributors 'rails', 'rails'

率直に言って、公式の GitHub API gem であるoctokit.rbを使用することをお勧めします。ページネーション作業を行い、ページあたりのアイテム数をいつ 100 に増やすことができるかをインテリジェントに認識します。

于 2013-08-10T02:36:12.210 に答える
0

同じ問題に直面したため、私の解決策は git コマンド ラインにフォールバックすることでした。

コミット数:

$ git log --author="X Y" --oneline --shortstat|wc -l
224

デルタを数える:

$ git log --author="X Y" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -

追加された行: 1861、削除された行: 1243、合計行: 618

于 2015-11-04T07:44:24.543 に答える