Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased
* (bugfix) Retry GitHub server errors in background jobs with polynomial backoff for ten attempts
(about 4.3 hours plus jitter), retaining error reporting when retries are exhausted.
* (bugfix) Fetch every page of a commit's statuses from GitHub, instead of only the first 100.

# 0.45.5
* (bugfix) Update existing check runs without first attempting a duplicate insert. Concurrent
Expand Down
13 changes: 11 additions & 2 deletions app/models/shipit/commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,17 @@ def refresh_statuses!
github_statuses = stack.handle_github_redirections do
stack.github_api.statuses(github_repo_name, sha, per_page: 100)
end
github_statuses.each do |status|
create_status_from_github!(status)

loop do
next_page = stack.github_api.last_response.rels[:next]
github_statuses.each do |status|
create_status_from_github!(status)
end
break if next_page.nil?

github_statuses = stack.handle_github_redirections do
stack.github_api.get(next_page.href)
end
end
end

Expand Down
21 changes: 21 additions & 0 deletions test/models/commits_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,33 @@ class CommitsTest < ActiveSupport::TestCase
created_at: 1.day.ago
)
Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, @commit.sha, per_page: 100).returns([status])
Shipit.github.api.expects(:last_response).returns(stub(rels: {}))
assert_difference '@commit.statuses.count', 1 do
@commit.refresh_statuses!
end
assert_equal 'success', @commit.statuses.first.state
end

test "refresh_statuses! handles paginated responses from github" do
first_page = [
mock(state: 'success', description: nil, context: 'ci/a', target_url: 'http://example.com/a', created_at: 1.day.ago),
mock(state: 'pending', description: nil, context: 'ci/b', target_url: 'http://example.com/b', created_at: 1.day.ago)
]
second_page = [
mock(state: 'failure', description: nil, context: 'ci/c', target_url: 'http://example.com/c', created_at: 1.day.ago)
]
next_link = stub(href: 'https://api.github.com/repos/test/repo/commits/abc/statuses?page=2')

Shipit.github.api.expects(:statuses).with(@stack.github_repo_name, @commit.sha, per_page: 100).returns(first_page)
Shipit.github.api.expects(:get).with(next_link.href).returns(second_page)
Shipit.github.api.stubs(:last_response).returns(stub(rels: { next: next_link })).then.returns(stub(rels: {}))

assert_difference '@commit.statuses.count', 3 do
@commit.refresh_statuses!
end
assert_equal 'failure', @commit.statuses.find_by(context: 'ci/c')&.state
end

test "refresh_check_runs! pull state from github" do
check_run = mock(
id: 34_234_234_234_432,
Expand Down
2 changes: 1 addition & 1 deletion test/models/merge_request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MergeRequestTest < ActiveSupport::TestCase
)]
))

Shipit.github.api.expects(:last_response).returns(response)
Shipit.github.api.expects(:last_response).twice.returns(response)
Shipit.github.api.expects(:check_runs).with(@stack.github_repo_name, head_sha, per_page: 100).returns(response.data)
merge_request.refresh!

Expand Down
Loading