@@ -133,6 +133,14 @@ class InactiveMemberSearch
133
133
134
134
def initialize ( options = { } )
135
135
@client = options [ :client ]
136
+ @options = options # Store options for later use
137
+
138
+ # Warn if throttling is disabled
139
+ if options [ :no_throttle ]
140
+ $stderr. print "⚠️ WARNING: API throttling is DISABLED! This may cause rate limit errors.\n "
141
+ $stderr. print "🚨 Use this option only for testing or with GitHub Enterprise instances with higher limits.\n \n "
142
+ end
143
+
136
144
if options [ :check ]
137
145
check_app
138
146
check_scopes
@@ -269,6 +277,23 @@ def paginated_request(method, *args, **kwargs)
269
277
results
270
278
end
271
279
280
+ # Smart request method that uses auto-pagination when throttling is disabled
281
+ def smart_request ( method , *args , **kwargs )
282
+ if @options [ :no_throttle ]
283
+ # Use auto-pagination (simpler, faster, but no throttling)
284
+ retry_on_403 ( "fetching #{ method } " ) do
285
+ if args . empty?
286
+ @client . send ( method , kwargs )
287
+ else
288
+ @client . send ( method , *args , kwargs )
289
+ end
290
+ end
291
+ else
292
+ # Use manual pagination with throttling
293
+ paginated_request ( method , *args , **kwargs )
294
+ end
295
+ end
296
+
272
297
def member_email ( login )
273
298
return "" unless @email
274
299
@@ -280,7 +305,7 @@ def member_email(login)
280
305
def organization_members
281
306
# get all organization members and place into an array of hashes
282
307
info "Finding #{ @organization } members "
283
- members_data = paginated_request ( :organization_members , @organization )
308
+ members_data = smart_request ( :organization_members , @organization )
284
309
@members = members_data . collect do |m |
285
310
email =
286
311
{
@@ -295,7 +320,7 @@ def organization_members
295
320
def organization_repositories
296
321
info "Gathering a list of repositories..."
297
322
# get all repos in the organizaton and place into a hash
298
- repos_data = paginated_request ( :organization_repositories , @organization )
323
+ repos_data = smart_request ( :organization_repositories , @organization )
299
324
@repositories = repos_data . collect do |repo |
300
325
repo [ "full_name" ]
301
326
end
@@ -316,7 +341,7 @@ def commit_activity(repo)
316
341
# get all commits after specified date and iterate
317
342
info "...commits"
318
343
begin
319
- commits = paginated_request ( :commits_since , repo , @date )
344
+ commits = smart_request ( :commits_since , repo , @date )
320
345
commits . each do |commit |
321
346
# if commmitter is a member of the org and not active, make active
322
347
if commit [ "author" ] . nil?
@@ -339,7 +364,7 @@ def issue_activity(repo, date=@date)
339
364
# get all issues after specified date and iterate
340
365
info "...Issues"
341
366
begin
342
- issues = paginated_request ( :list_issues , repo , since : date )
367
+ issues = smart_request ( :list_issues , repo , since : date )
343
368
issues . each do |issue |
344
369
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
345
370
if issue [ "user" ] . nil?
@@ -360,7 +385,7 @@ def issue_comment_activity(repo, date=@date)
360
385
# get all issue comments after specified date and iterate
361
386
info "...Issue comments"
362
387
begin
363
- comments = paginated_request ( :issues_comments , repo , since : date )
388
+ comments = smart_request ( :issues_comments , repo , since : date )
364
389
comments . each do |comment |
365
390
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
366
391
if comment [ "user" ] . nil?
@@ -380,7 +405,7 @@ def issue_comment_activity(repo, date=@date)
380
405
def pr_activity ( repo , date = @date )
381
406
# get all pull request comments comments after specified date and iterate
382
407
info "...Pull Request comments"
383
- comments = paginated_request ( :pull_requests_comments , repo , since : date )
408
+ comments = smart_request ( :pull_requests_comments , repo , since : date )
384
409
comments . each do |comment |
385
410
# if there's no user (ghost user?) then skip this // THIS NEEDS BETTER VALIDATION
386
411
if comment [ "user" ] . nil?
@@ -481,23 +506,34 @@ def member_activity
481
506
options [ :verbose ] = v
482
507
end
483
508
509
+ opts . on ( '-t' , '--no-throttle' , "Disable API request throttling (use with caution)" ) do |t |
510
+ puts "DEBUG: -t flag was triggered, t value = #{ t . inspect } "
511
+ options [ :no_throttle ] = true
512
+ end
513
+
484
514
opts . on ( '-h' , '--help' , "Display this help" ) do |h |
485
515
puts opts
486
516
exit 0
487
517
end
488
518
end . parse!
489
519
520
+ # Debug: Check if no_throttle option is set
521
+ if options [ :no_throttle ]
522
+ puts "DEBUG: no_throttle option is set to: #{ options [ :no_throttle ] } "
523
+ end
524
+
490
525
stack = Faraday ::RackBuilder . new do |builder |
491
- builder . use ThrottleMiddleware
526
+ builder . use ThrottleMiddleware unless options [ :no_throttle ]
492
527
builder . use Octokit ::Middleware ::FollowRedirects
493
528
builder . use Octokit ::Response ::RaiseError
494
529
builder . use Octokit ::Response ::FeedParser
495
530
builder . response :logger if @debug
496
531
builder . adapter Faraday . default_adapter
497
532
end
498
533
534
+ # Conditionally enable auto-pagination when throttling is disabled
499
535
Octokit . configure do |kit |
500
- kit . auto_paginate = false # Disable auto-pagination to ensure throttling on each request
536
+ kit . auto_paginate = options [ :no_throttle ] ? true : false
501
537
kit . middleware = stack
502
538
end
503
539
0 commit comments