ruby-on-railsgithub-apioctokit

List all users from Github organization && avoid Octokit gem limits


I'm using Octokit gem for communication with Github API. Using this gem I want to list all users from my organization and show their login names. Based on a docs it's straight forward:

client = Octokit::Client.new(access_token: ENV.fetch('PERSONAL_ACCESS_TOKEN'))
client.organization_members('my_organization')

The thing is there is some kind of limitations because I'm getting only 30 records instead of over 600. How to avoid such limits?


Solution

  • I'm getting only 30 records instead of over 600.

    GitHub API defaults to 30 items per page, and won't follow pagination by default. Please check the pagination docs to see how to use it.

    It might be as easy as this:

    client.auto_paginate = true
    issues = client.issues 'rails/rails'
    issues.length
    
    # => 702