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

Commit b085308

Browse files
authored
Merge pull request #25 from camelpunch/base-branch
Can retrieve PRs from a specified base branch
2 parents 75a6339 + 0c8a229 commit b085308

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

assets/lib/check.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
if input['source']['every']
1212
json!(repo.pull_requests.map(&:as_json))
1313
else
14-
next_pull_request = repo.next_pull_request(id: input['version']['pr'], sha: input['version']['ref'])
14+
next_pull_request = repo.next_pull_request(
15+
id: input['version']['pr'],
16+
sha: input['version']['ref'],
17+
base: input['source']['base']
18+
)
1519
if next_pull_request
1620
json!([next_pull_request.as_json])
1721
else

assets/lib/common.rb

+14-4
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ def initialize(name:)
7979
@name = name
8080
end
8181

82-
def pull_requests
83-
@pull_requests ||= Octokit.pulls(name, state: 'open', sort: 'updated', direction: 'desc').map do |pr|
82+
def pull_requests(args = {})
83+
@pull_requests ||= Octokit.pulls(name, pulls_options(args)).map do |pr|
8484
PullRequest.new(repo: self, pr: pr)
8585
end
8686
end
@@ -90,8 +90,8 @@ def pull_request(id:)
9090
PullRequest.new(repo: self, pr: pr)
9191
end
9292

93-
def next_pull_request(id: nil, sha: nil)
94-
return if pull_requests.empty?
93+
def next_pull_request(id: nil, sha: nil, base: nil)
94+
return if pull_requests(base: base).empty?
9595

9696
if id && sha
9797
current = pull_requests.find { |pr| pr.equals?(id: id, sha: sha) }
@@ -102,6 +102,16 @@ def next_pull_request(id: nil, sha: nil)
102102
pr != current && pr.ready?
103103
end
104104
end
105+
106+
private
107+
108+
def pulls_options(base: nil)
109+
base ? default_opts.merge(base: base) : default_opts
110+
end
111+
112+
def default_opts
113+
{ state: 'open', sort: 'updated', direction: 'desc' }
114+
end
105115
end
106116

107117
def input

spec/integration/check_spec.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
end
2020
end
2121

22+
context 'when targetting a base branch other than master' do
23+
must_stub_query_params
24+
25+
before do
26+
proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls?base=my-base-branch&direction=desc&per_page=100&sort=updated&state=open')
27+
.and_return(json: [{ number: 1, head: { sha: 'abcdef' } }])
28+
end
29+
30+
it 'retrieves pull requests for the specified base branch' do
31+
expect(check(source: { repo: 'jtarchie/test', base: 'my-base-branch' })).to eq [{ 'ref' => 'abcdef', 'pr' => '1' }]
32+
end
33+
end
34+
2235
context 'with check for `version: every`' do
2336
context 'when there are no pull requests' do
2437
before do
@@ -40,8 +53,10 @@
4053
end
4154

4255
context 'when there is an open pull request' do
56+
must_stub_query_params
57+
4358
before do
44-
proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls')
59+
proxy.stub('https://api.github.com:443/repos/jtarchie/test/pulls?direction=desc&per_page=100&sort=updated&state=open')
4560
.and_return(json: [{ number: 1, head: { sha: 'abcdef' } }])
4661
end
4762

spec/spec_helper.rb

+9
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ def with_resource
7171
FileUtils.cp_r(dest_dir, File.join(tmp_dir, 'resource'))
7272
yield(tmp_dir)
7373
end
74+
75+
def must_stub_query_params
76+
around do |example|
77+
old_strip_params = Billy.config.strip_query_params
78+
Billy.config.strip_query_params = false
79+
example.run
80+
Billy.config.strip_query_params = old_strip_params
81+
end
82+
end

0 commit comments

Comments
 (0)