我想得到特別是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錯誤。
謝謝!
謝謝你的回答!我想出了完全相同的解決方案,完美地工作。 –