Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Can retrieve PRs from a specified base branch #25

Merged
merged 1 commit into from
Jul 27, 2016
Merged
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
6 changes: 5 additions & 1 deletion assets/lib/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
if input['source']['every']
json!(repo.pull_requests.map(&:as_json))
else
next_pull_request = repo.next_pull_request(id: input['version']['pr'], sha: input['version']['ref'])
next_pull_request = repo.next_pull_request(
id: input['version']['pr'],
sha: input['version']['ref'],
base: input['source']['base']
)
if next_pull_request
json!([next_pull_request.as_json])
else
Expand Down
18 changes: 14 additions & 4 deletions assets/lib/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def initialize(name:)
@name = name
end

def pull_requests
@pull_requests ||= Octokit.pulls(name, state: 'open', sort: 'updated', direction: 'desc').map do |pr|
def pull_requests(args = {})
@pull_requests ||= Octokit.pulls(name, pulls_options(args)).map do |pr|
PullRequest.new(repo: self, pr: pr)
end
end
Expand All @@ -90,8 +90,8 @@ def pull_request(id:)
PullRequest.new(repo: self, pr: pr)
end

def next_pull_request(id: nil, sha: nil)
return if pull_requests.empty?
def next_pull_request(id: nil, sha: nil, base: nil)
return if pull_requests(base: base).empty?

if id && sha
current = pull_requests.find { |pr| pr.equals?(id: id, sha: sha) }
Expand All @@ -102,6 +102,16 @@ def next_pull_request(id: nil, sha: nil)
pr != current && pr.ready?
end
end

private

def pulls_options(base: nil)
base ? default_opts.merge(base: base) : default_opts
end

def default_opts
{ state: 'open', sort: 'updated', direction: 'desc' }
end
end

def input
Expand Down
17 changes: 16 additions & 1 deletion spec/integration/check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
end
end

context 'when targetting a base branch other than master' do
must_stub_query_params

before do
proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls?base=my-base-branch&direction=desc&per_page=100&sort=updated&state=open')
.and_return(json: [{ number: 1, head: { sha: 'abcdef' } }])
end

it 'retrieves pull requests for the specified base branch' do
expect(check(source: { repo: 'jtarchie/test', base: 'my-base-branch' })).to eq [{ 'ref' => 'abcdef', 'pr' => '1' }]
end
end

context 'with check for `version: every`' do
context 'when there are no pull requests' do
before do
Expand All @@ -43,8 +56,10 @@
end

context 'when there is an open pull request' do
must_stub_query_params

before do
proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls')
proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls?direction=desc&per_page=100&sort=updated&state=open')
.and_return(json: [{ number: 1, head: { sha: 'abcdef' } }])
end

Expand Down
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ def with_resource
FileUtils.cp_r(dest_dir, File.join(tmp_dir, 'resource'))
yield(tmp_dir)
end

def must_stub_query_params
around do |example|
old_strip_params = Billy.config.strip_query_params
Billy.config.strip_query_params = false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this was a thing. I'm going to turn this on for everything!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, otherwise we're only asserting on path, which could miss a lot of mistakes.

example.run
Billy.config.strip_query_params = old_strip_params
end
end