2017-07-11 42 views
2

我想得到特別是GitHub代表的pull請求和問題的數量。目前我使用的方法非常笨拙。Octokit GitHub API

使用octokit寶石和下面的代碼:

# Builds data that is sent to the API 
def request_params 
    data = { } 

    # labels example: "bug,invalid,question" 
    data["labels"] = labels.present? ? labels : "" 

    # filter example: "assigned" "created" "mentioned" "subscribed" "all" 
    data["filter"] = filter 

    # state example: "open" "closed" "all" 
    data["state"] = state 

    return data 
end 


Octokit.auto_paginate = true 
github = Octokit::Client.new(access_token: oauth_token) 
github.list_issues("#{user}/#{repository}", request_params).count 

接收到的數據是非常大的,所以它在內存方面非常ineficient。我不需要關於問題的數據,只有有多少問題,X問題(基於過濾器/狀態/標籤)。

我想到了一個解決方案,但無法實現它。 基本上:做1個請求獲取標題,在標題中應該有一個鏈接到最後一頁。然後再向最後一頁發出1個請求,並檢查有多少問題。然後我們可以計算:

​​

但是我沒有發現如何從octokit Authentificated Client獲取請求頭信息。 如果沒有octokit的簡單方法,我會很高興地使用它。

注:我想解決這個問題,因爲拉請求的數量非常高,上面的代碼在Heroku上生成R14錯誤。

謝謝!

回答

3

我覺得一個簡單的方法就是使用GitHub API並使用per_page過濾器來限制要在頁面中顯示的PR數量。例如:找出所有可以使用的回購OneGet/oneget的PR .. https://api.github.com/search/issues?q=repo:OneGet/oneget+type:pr&per_page=1。 JSON響應的字段爲「total_count」,它給出了PR總數。由於只列出一個問題,因此迴應會相對較輕。 Ref:Search Issues

+1

謝謝你的回答!我想出了完全相同的解決方案,完美地工作。 –