Skip to content

Commit

Permalink
Merge pull request joshsoftware#218 from prasadsurase/auto-pagination…
Browse files Browse the repository at this point in the history
…-for-github-api

Added auto pagination for github api calls where pagination is not handled manually.
  • Loading branch information
sethu authored Dec 12, 2016
2 parents cb30bd7 + 40602b6 commit c8288e3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/models/activities_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/commits_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion test/models/activities_fetcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
)
Expand Down
4 changes: 2 additions & 2 deletions test/models/commits_fetcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit c8288e3

Please sign in to comment.