Skip to content

Commit

Permalink
Use correct api endpoint to get pr details for "branch" prs
Browse files Browse the repository at this point in the history
  • Loading branch information
ragurney committed Sep 17, 2018
1 parent b2e23df commit a68a261
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 1 addition & 3 deletions app/models/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def cache_key
def find_pull_requests_for_branch
return [] if not_pr_branch?
org = repo.split("/", 2).first
GITHUB.pull_requests(repo, head: "#{org}:#{commit}").map do |github_pr|
Changeset::PullRequest.new(repo, github_pr)
end
GITHUB.pull_requests(repo, head: "#{org}:#{commit}").map { |github_pr| PullRequest.find(repo, github_pr.number) }
rescue Octokit::Error, Faraday::ConnectionFailed => e
Rails.logger.warn "Failed fetching pull requests for branch #{commit}:\n#{e}"
[]
Expand Down
29 changes: 24 additions & 5 deletions test/models/changeset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,24 @@
let(:message1) { Sawyer::Resource.new(sawyer_agent, message: 'Merge pull request #42') }
let(:message2) { Sawyer::Resource.new(sawyer_agent, message: 'Fix typo') }
let(:pr_from_coolcommitter) do
Sawyer::Resource.new(sawyer_agent, user: {
Sawyer::Resource.new(
sawyer_agent,
user: {
login: 'coolcommitter'
})
},
additions: 10
)
end
let(:prs_from_coolcommitter) do
[
Sawyer::Resource.new(
sawyer_agent,
user: {
login: 'coolcommitter'
},
number: 5
)
]
end
let(:pr_from_coolcommitter_wrapped) { Changeset::PullRequest.new("foo/bar", pr_from_coolcommitter) }

Expand All @@ -105,10 +120,14 @@
it "finds pull requests open for a branch" do
comparison = Sawyer::Resource.new(sawyer_agent, commits: [commit2])
GITHUB.stubs(:compare).with("foo/bar", "a", "b").returns(comparison)
GITHUB.stubs(:pull_requests).with("foo/bar", head: "foo:b").returns([pr_from_coolcommitter])
GITHUB.stubs(:pull_requests).with("foo/bar", head: "foo:b").returns(prs_from_coolcommitter)
GITHUB.stubs(:pull_request).with("foo/bar", 5).returns(pr_from_coolcommitter)

changeset.pull_requests.size.must_equal 1
changeset.pull_requests.first.users.first.login.must_equal 'coolcommitter'
pull_requests = changeset.pull_requests

pull_requests.size.must_equal 1
pull_requests.first.users.first.login.must_equal 'coolcommitter'
pull_requests.first.additions.must_equal 10
end

it "does not fail if fetching pull request from Github fails" do
Expand Down

0 comments on commit a68a261

Please sign in to comment.