Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octokit GitHub API

I would like to get the number of pull requests and issues for a particularly GitHub rep. At the moment the method I'm using is really clumsy.

Using the octokit gem and the following code:

# 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

The data received is extremely big, so its very ineficient in terms of memory. I don't need data regarding the issues only how many are there, X issues ( based on the filters / state / labels ).

I thought of a solution but was not able to implement it. Basically: do 1 request to get the header, in the header there should be a link to the last page. Then make 1 more request to the last page, and check how many issues are there. Then we can calculate:

count = ( number of pages * (issues-per-page - 1) ) + issues-on-last-page

But I did not found out how to get request header information from octokit Authentificated Client. If there is a simple way of doing it without octokit, I will happily use it.

Note: I want to fix this issue because the number of pull requests is quite high, and the code above generates R14 errors on Heroku.

Thank You!

like image 433
Rares R Avatar asked Feb 14 '26 20:02

Rares R


1 Answers

I feel an easy way is to use the GitHub API and restrict the number of PRs you want displayed in a page by using the per_page filter. For example: to find out all the PRs of the repo OneGet/oneget you can use.. https://api.github.com/search/issues?q=repo:OneGet/oneget+type:pr&per_page=1. The JSON response has the field "total_count" which gives the count of the total number of PRs. And the response will be relatively light since it will have only one issue listed. Ref: Search Issues

like image 100
Poonacha Avatar answered Feb 17 '26 12:02

Poonacha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!