Skip to content

Commit 4995358

Browse files
committed
Implement paginated_request helper for API calls and update organization member/repo methods to use it
1 parent 790ee9a commit 4995358

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

api/ruby/find-inactive-members/find_inactive_members.rb

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,44 @@ def info(message)
183183
$stdout.print message
184184
end
185185

186+
# Helper method to manually paginate requests with proper throttling
187+
def paginated_request(method, *args, **kwargs)
188+
results = []
189+
page = 1
190+
per_page = 100
191+
192+
loop do
193+
# Merge pagination parameters with existing kwargs
194+
page_kwargs = kwargs.merge(page: page, per_page: per_page)
195+
196+
# Handle different method signatures
197+
if args.empty?
198+
response = @client.send(method, page_kwargs)
199+
else
200+
response = @client.send(method, *args, page_kwargs)
201+
end
202+
203+
break if response.empty?
204+
205+
results.concat(response)
206+
page += 1
207+
208+
# Break if we got less than a full page (indicates last page)
209+
break if response.length < per_page
210+
end
211+
212+
results
213+
end
214+
186215
def member_email(login)
187216
@email ? @client.user(login)[:email] : ""
188217
end
189218

190219
def organization_members
191220
# get all organization members and place into an array of hashes
192221
info "Finding #{@organization} members "
193-
@members = @client.organization_members(@organization).collect do |m|
222+
members_data = paginated_request(:organization_members, @organization)
223+
@members = members_data.collect do |m|
194224
email =
195225
{
196226
login: m["login"],
@@ -204,7 +234,8 @@ def organization_members
204234
def organization_repositories
205235
info "Gathering a list of repositories..."
206236
# get all repos in the organizaton and place into a hash
207-
@repositories = @client.organization_repositories(@organization).collect do |repo|
237+
repos_data = paginated_request(:organization_repositories, @organization)
238+
@repositories = repos_data.collect do |repo|
208239
repo["full_name"]
209240
end
210241
info "#{@repositories.length} repositories discovered\n"
@@ -224,7 +255,8 @@ def commit_activity(repo)
224255
# get all commits after specified date and iterate
225256
info "...commits"
226257
begin
227-
@client.commits_since(repo, @date).each do |commit|
258+
commits = paginated_request(:commits_since, repo, @date)
259+
commits.each do |commit|
228260
# if commmitter is a member of the org and not active, make active
229261
if commit["author"].nil?
230262
add_unrecognized_author(commit[:commit][:author])
@@ -246,7 +278,8 @@ def issue_activity(repo, date=@date)
246278
# get all issues after specified date and iterate
247279
info "...Issues"
248280
begin
249-
@client.list_issues(repo, { :since => date }).each do |issue|
281+
issues = paginated_request(:list_issues, repo, since: date)
282+
issues.each do |issue|
250283
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
251284
if issue["user"].nil?
252285
next
@@ -266,7 +299,8 @@ def issue_comment_activity(repo, date=@date)
266299
# get all issue comments after specified date and iterate
267300
info "...Issue comments"
268301
begin
269-
@client.issues_comments(repo, { :since => date }).each do |comment|
302+
comments = paginated_request(:issues_comments, repo, since: date)
303+
comments.each do |comment|
270304
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
271305
if comment["user"].nil?
272306
next
@@ -285,7 +319,8 @@ def issue_comment_activity(repo, date=@date)
285319
def pr_activity(repo, date=@date)
286320
# get all pull request comments comments after specified date and iterate
287321
info "...Pull Request comments"
288-
@client.pull_requests_comments(repo, { :since => date }).each do |comment|
322+
comments = paginated_request(:pull_requests_comments, repo, since: date)
323+
comments.each do |comment|
289324
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
290325
if comment["user"].nil?
291326
next
@@ -401,7 +436,7 @@ def member_activity
401436
end
402437

403438
Octokit.configure do |kit|
404-
kit.auto_paginate = true
439+
kit.auto_paginate = false # Disable auto-pagination to ensure throttling on each request
405440
kit.middleware = stack
406441
end
407442

0 commit comments

Comments
 (0)