From 40602b60b3a7aeb3fecc437233d2cbe5fc51aef6 Mon Sep 17 00:00:00 2001 From: Prasad Surase Date: Fri, 9 Dec 2016 12:12:11 +0530 Subject: [PATCH] Added auto pagination for github api calls where pagination is not handled manually --- app/models/activities_fetcher.rb | 2 +- app/models/commits_fetcher.rb | 2 +- test/models/activities_fetcher_test.rb | 2 +- test/models/commits_fetcher_test.rb | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/activities_fetcher.rb b/app/models/activities_fetcher.rb index 3b0af97d..f71506aa 100644 --- a/app/models/activities_fetcher.rb +++ b/app/models/activities_fetcher.rb @@ -16,7 +16,7 @@ def fetch(type = :daily) end #repos = user.repositories.inject({}){|o, r| o[r.gh_id] = r; o} - activities = user.gh_client.activity.events.performed(user.github_handle, per_page: 200) + activities = user.gh_client.activity.events.performed(user.github_handle, auto_pagination: true) activities.each do |a| if TRACKING_EVENTS.key?(a.type) && Time.parse(a.created_at) > since_time diff --git a/app/models/commits_fetcher.rb b/app/models/commits_fetcher.rb index fb488d6e..d81ae8a9 100644 --- a/app/models/commits_fetcher.rb +++ b/app/models/commits_fetcher.rb @@ -33,7 +33,7 @@ def branch_commits(branch, type) since: since_time, 'until': round.end_date ? round.end_date.end_of_day : Time.now, sha: branch, - per_page: 200 + auto_pagination: true }) return if response.body.blank? diff --git a/test/models/activities_fetcher_test.rb b/test/models/activities_fetcher_test.rb index d96709b2..2121d6b2 100644 --- a/test/models/activities_fetcher_test.rb +++ b/test/models/activities_fetcher_test.rb @@ -7,7 +7,7 @@ def setup Timecop.freeze(Time.parse @activities[1].fetch('created_at')) @user = create :user, github_handle: 'prasadsurase' @round = create :round, :open, from_date: @activities.collect{|i| Time.parse i['created_at']}.min.beginning_of_month - stub_get('/users/prasadsurase/events?per_page=200').to_return( + stub_get('/users/prasadsurase/events').to_return( body: File.read('test/fixtures/activities.json'), status: 200, headers: {content_type: "application/json; charset=utf-8"} ) diff --git a/test/models/commits_fetcher_test.rb b/test/models/commits_fetcher_test.rb index fa2fbe16..53d58915 100644 --- a/test/models/commits_fetcher_test.rb +++ b/test/models/commits_fetcher_test.rb @@ -56,7 +56,7 @@ def teardown Timecop.freeze(Time.parse(@commits.first.commit.committer.date)) Github::Client::Repos.any_instance.stubs(:branches).returns([branch]) assert_equal 1, @commits.select{|i| i.commit.author.date >= (Time.now - 30.hours)}.count - query_params = { per_page: 200, author: 'prasadsurase', sha: 'master', since: (Time.now - 30.hours), 'until' => @round.end_date.end_of_day } + query_params = { author: 'prasadsurase', sha: 'master', since: (Time.now - 30.hours), 'until' => @round.end_date.end_of_day } stub_get('/repos/prasadsurase/code-curiosity/commits').with(query: query_params).to_return( body: File.read(file_path), status: 200, headers: {content_type: "application/json; charset=utf-8"} @@ -87,7 +87,7 @@ def teardown file_path = 'test/fixtures/commits.json' @commits = JSON.parse(File.read(file_path)).collect{|i| Hashie::Mash.new(i)} - query_params = { per_page: 200, author: 'prasadsurase', sha: 'master', since: @round.from_date.beginning_of_day, 'until' => @round.end_date.end_of_day } + query_params = { author: 'prasadsurase', sha: 'master', since: @round.from_date.beginning_of_day, 'until' => @round.end_date.end_of_day } stub_get('/repos/prasadsurase/code-curiosity/commits').with(query: query_params).to_return( body: File.read(file_path), status: 200, headers: {content_type: "application/json; charset=utf-8"}