git_reflow 0.6.7 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +11 -9
  3. data/README.rdoc +3 -1
  4. data/bin/git-reflow +0 -11
  5. data/bin/gitreflow-common +1 -1
  6. data/git_reflow.gemspec +3 -2
  7. data/lib/git_reflow.rb +13 -60
  8. data/lib/git_reflow/commands/deliver.rb +1 -2
  9. data/lib/git_reflow/commands/start.rb +0 -6
  10. data/lib/git_reflow/config.rb +15 -14
  11. data/lib/git_reflow/git_server.rb +14 -4
  12. data/lib/git_reflow/git_server/base.rb +0 -39
  13. data/lib/git_reflow/git_server/bit_bucket.rb +15 -80
  14. data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +84 -0
  15. data/lib/git_reflow/git_server/git_hub.rb +18 -75
  16. data/lib/git_reflow/git_server/git_hub/pull_request.rb +108 -0
  17. data/lib/git_reflow/git_server/pull_request.rb +97 -0
  18. data/lib/git_reflow/version.rb +1 -1
  19. data/spec/fixtures/issues/comment.json.erb +27 -0
  20. data/spec/fixtures/issues/comments.json.erb +15 -0
  21. data/spec/fixtures/pull_requests/comment.json.erb +45 -0
  22. data/spec/fixtures/pull_requests/comments.json.erb +15 -0
  23. data/spec/fixtures/pull_requests/commits.json +29 -0
  24. data/spec/fixtures/pull_requests/external_pull_request.json +145 -0
  25. data/spec/fixtures/pull_requests/pull_request.json +19 -0
  26. data/spec/fixtures/pull_requests/pull_request.json.erb +142 -0
  27. data/spec/fixtures/pull_requests/pull_requests.json +19 -0
  28. data/spec/fixtures/repositories/commit.json.erb +53 -0
  29. data/spec/fixtures/repositories/commits.json.erb +13 -0
  30. data/spec/git_reflow_spec.rb +32 -25
  31. data/spec/lib/git_reflow/config_spec.rb +22 -6
  32. data/spec/lib/git_server/bit_bucket_spec.rb +5 -34
  33. data/spec/lib/git_server/git_hub/pull_request_spec.rb +319 -0
  34. data/spec/lib/git_server/git_hub_spec.rb +17 -25
  35. data/spec/lib/git_server/pull_request_spec.rb +93 -0
  36. data/spec/support/command_line_helpers.rb +16 -1
  37. data/spec/support/fake_github.rb +128 -0
  38. data/spec/support/fixtures.rb +52 -6
  39. data/spec/support/github_helpers.rb +22 -12
  40. metadata +47 -6
@@ -12,8 +12,8 @@ describe GitReflow::GitServer::GitHub do
12
12
  let(:enterprise_api) { 'https://github.gittyup.com/api/v3' }
13
13
  let(:github) { stub_github_with(pull: existing_pull_request) }
14
14
  let!(:github_api) { github.connection }
15
- let(:existing_pull_request) { Hashie::Mash.new JSON.parse(fixture('pull_requests/pull_request.json').read) }
16
- let(:existing_pull_requests) { JSON.parse(fixture('pull_requests/pull_requests.json').read).collect {|pull| Hashie::Mash.new pull } }
15
+ let(:existing_pull_request) { Fixture.new('pull_requests/pull_request.json').to_json_hashie }
16
+ let(:existing_pull_requests) { Fixture.new('pull_requests/pull_requests.json').to_json_hashie }
17
17
 
18
18
  before do
19
19
  HighLine.any_instance.stub(:ask) do |terminal, question|
@@ -38,7 +38,7 @@ describe GitReflow::GitServer::GitHub do
38
38
  it 'sets the reflow git server provider to GitHub in the git config' do
39
39
  GitReflow::Config.should_receive(:set).once.with('github.site', github_site, local: false)
40
40
  GitReflow::Config.should_receive(:set).once.with('github.endpoint', github_api_endpoint, local: false)
41
- GitReflow::Config.should_receive(:set).once.with('reflow.git-server', 'GitHub')
41
+ GitReflow::Config.should_receive(:set).once.with('reflow.git-server', 'GitHub', local: false)
42
42
  subject
43
43
  end
44
44
 
@@ -48,7 +48,7 @@ describe GitReflow::GitServer::GitHub do
48
48
  it 'sets the enterprise site and api as the site and api endpoints for the GitHub provider in the git config' do
49
49
  GitReflow::Config.should_receive(:set).once.with('github.site', enterprise_site, local: false)
50
50
  GitReflow::Config.should_receive(:set).once.with('github.endpoint', enterprise_api, local: false)
51
- GitReflow::Config.should_receive(:set).once.with('reflow.git-server', 'GitHub')
51
+ GitReflow::Config.should_receive(:set).once.with('reflow.git-server', 'GitHub', local: false)
52
52
  subject
53
53
  end
54
54
 
@@ -167,12 +167,21 @@ describe GitReflow::GitServer::GitHub do
167
167
  let(:body) { 'Funky body' }
168
168
  let(:current_branch) { 'new-feature' }
169
169
 
170
- before { github.class.stub(:current_branch).and_return(current_branch) }
170
+ subject { github.create_pull_request({ title: title, body: body, base: 'master' }) }
171
+
172
+ before do
173
+ github.class.stub(:current_branch).and_return(current_branch)
174
+ allow(GitReflow).to receive(:git_server).and_return(github)
175
+ stub_request(:post, %r{/repos/#{user}/#{repo}/pulls}).
176
+ to_return(body: Fixture.new('pull_requests/pull_request.json').to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
177
+ end
178
+
179
+ specify { expect(subject.class.to_s).to eq('GitReflow::GitServer::GitHub::PullRequest') }
171
180
 
172
181
  it 'creates a pull request using the remote user and repo' do
173
182
  github_api.stub(:pull_requests)
174
- github_api.pull_requests.should_receive(:create).with(user, repo, title: title, body: body, head: "#{user}:#{current_branch}", base: 'master')
175
- github.create_pull_request({ title: title, body: body, base: 'master' })
183
+ expect(github_api.pull_requests).to receive(:create).with(user, repo, title: title, body: body, head: "#{user}:#{current_branch}", base: 'master').and_return(existing_pull_request)
184
+ subject
176
185
  end
177
186
  end
178
187
 
@@ -192,23 +201,6 @@ describe GitReflow::GitServer::GitHub do
192
201
  end
193
202
  end
194
203
 
195
- describe '#pull_request_comments(pull_request)' do
196
- let(:pull_request_comments) { JSON.parse(fixture('pull_requests/comments.json').read).collect {|c| Hashie::Mash.new(c) } }
197
-
198
- subject { github.pull_request_comments(existing_pull_request) }
199
-
200
- before do
201
- github_api.stub_chain(:issues, :comments)
202
- github_api.stub_chain(:pull_requests, :comments)
203
- end
204
-
205
- it 'includes both issue comments and pull request comments' do
206
- github_api.issues.comments.should_receive(:all).with(user, repo, number: existing_pull_request.number).and_return([pull_request_comments.first])
207
- github_api.pull_requests.comments.should_receive(:all).with(user, repo, number: existing_pull_request.number).and_return([pull_request_comments.first])
208
- subject.count.should == 2
209
- end
210
- end
211
-
212
204
  describe '#get_build_status(sha)' do
213
205
  let(:sha) { '6dcb09b5b57875f334f61aebed695e2e4193db5e' }
214
206
  subject { github.get_build_status(sha) }
@@ -223,7 +215,7 @@ describe GitReflow::GitServer::GitHub do
223
215
  describe '#comment_authors_for_pull_request(pull_request, options = {})' do
224
216
  end
225
217
 
226
- describe '#get_commited_time(commit_sha)' do
218
+ describe '#get_committed_time(commit_sha)' do
227
219
  end
228
220
 
229
221
  end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitReflow::GitServer::PullRequest do
4
+ let(:pull_request) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
5
+ let(:github) { stub_github_with({ user: 'reenhanced', repo: 'repo', pull: pull_request }) }
6
+ let!(:github_api) { github.connection }
7
+
8
+ describe "#good_to_merge?(options)" do
9
+ subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
10
+
11
+ before do
12
+ FakeGitHub.new(
13
+ repo_owner: 'reenhanced',
14
+ repo_name: 'repo',
15
+ pull_request: {
16
+ number: pull_request.number,
17
+ owner: pull_request.head.user.login,
18
+ comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
19
+ })
20
+ # setup initial valid state
21
+ allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
22
+ GitReflow.git_server.stub(:find_open_pull_request).with({from: 'new-feature', to: 'master'}).and_return(pull_request)
23
+ end
24
+
25
+ specify { expect(subject.good_to_merge?).to eq(true) }
26
+
27
+ context "with build status" do
28
+ context "of 'success'" do
29
+ before { allow(subject).to receive(:build_status).and_return('success') }
30
+ specify { expect(subject.good_to_merge?).to eq(true) }
31
+ end
32
+
33
+ context "NOT of 'success'" do
34
+ before { allow(subject).to receive(:build_status).and_return('failure') }
35
+ specify { expect(subject.good_to_merge?).to eq(false) }
36
+ end
37
+ end
38
+
39
+ context "with no comments" do
40
+ before { allow(subject).to receive(:has_comments?).and_return(false) }
41
+ specify { expect(subject.good_to_merge?).to eq(true) }
42
+ context "and no approvals" do
43
+ before { allow(subject).to receive(:approvals?).and_return([]) }
44
+ specify { expect(subject.good_to_merge?).to eq(true) }
45
+ end
46
+ end
47
+
48
+ context "with comments" do
49
+ before do
50
+ allow(subject).to receive(:reviewers).and_return(['bob'])
51
+ allow(subject).to receive(:approvals).and_return([])
52
+ end
53
+ specify { expect(subject.good_to_merge?).to eq(false) }
54
+ end
55
+
56
+ context "force merge?" do
57
+ context "with pending comments" do
58
+ before { allow(subject).to receive(:approvals).and_return([]) }
59
+ specify { expect(subject.good_to_merge?(force: true)).to eq(true) }
60
+ end
61
+
62
+ context "with build failure" do
63
+ before { allow(subject).to receive(:build_status).and_return('failure') }
64
+ specify { expect(subject.good_to_merge?(force: true)).to eq(true) }
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "#display_pull_request_summary" do
70
+ subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request).display_pull_request_summary }
71
+
72
+ before do
73
+ FakeGitHub.new(
74
+ repo_owner: 'reenhanced',
75
+ repo_name: 'repo',
76
+ pull_request: {
77
+ number: pull_request.number,
78
+ owner: pull_request.head.user.login,
79
+ comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
80
+ })
81
+ allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
82
+ GitReflow.git_server.stub(:find_open_pull_request).with({from: 'new-external-feature', to: 'master'}).and_return(pull_request)
83
+ end
84
+
85
+ it "displays relavent information about the pull request" do
86
+ expect{ subject }.to have_output("branches: new-external-feature -> reenhanced:master")
87
+ expect{ subject }.to have_output("number: #{pull_request.number}")
88
+ expect{ subject }.to have_output("url: #{pull_request.html_url}")
89
+ expect{ subject }.to have_output("reviewed by: #{"tito".colorize(:green)}, #{"ringo".colorize(:green)}")
90
+ expect{ subject }.to have_output("Last comment: \":+1:\"")
91
+ end
92
+ end
93
+ end
@@ -12,6 +12,11 @@ module CommandLineHelpers
12
12
  $output << output
13
13
  output = ''
14
14
  end
15
+
16
+ allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:printf) do |format, *output|
17
+ $output << Array(output).join(" ")
18
+ output = ''
19
+ end.and_return("")
15
20
  end
16
21
 
17
22
  def stub_run_for(module_to_stub)
@@ -30,12 +35,22 @@ module CommandLineHelpers
30
35
  def reset_stubbed_command_line
31
36
  $commands_ran = []
32
37
  $stubbed_commands = {}
38
+ $output = []
39
+ $says = []
33
40
  end
34
41
 
35
42
  def stub_command(command, return_value)
36
43
  $stubbed_commands[command] = return_value
37
44
  GitReflow::Sandbox.stub(:run).with(command).and_return(return_value)
38
45
  end
46
+
47
+ def stub_command_line_inputs(inputs)
48
+ HighLine.any_instance.stub(:ask) do |terminal, question|
49
+ return_value = inputs[question]
50
+ question = ""
51
+ return_value
52
+ end
53
+ end
39
54
  end
40
55
 
41
56
  RSpec::Matchers.define :have_run_command do |command|
@@ -109,7 +124,7 @@ end
109
124
  RSpec::Matchers.define :have_output do |expected_output|
110
125
  match do |block|
111
126
  block.call
112
- $output.include? expected_output
127
+ $output.join("\n").include? expected_output
113
128
  end
114
129
 
115
130
  supports_block_expectations
@@ -0,0 +1,128 @@
1
+ require 'rspec/mocks'
2
+ require 'webmock'
3
+ require 'chronic'
4
+
5
+ class FakeGitHub
6
+ include WebMock::API
7
+
8
+ attr_accessor :repo_owner, :repo_name
9
+
10
+ DEFAULT_COMMIT_AUTHOR = "reenhanced".freeze
11
+ DEFAULT_COMMIT_TIME = "1 minute ago".freeze
12
+
13
+ # EXAMPLE:
14
+ #
15
+ # FakeGitHub.new(repo_owner: user, repo_name: repo,
16
+ # pull_request: {
17
+ # number: existing_pull_request.number,
18
+ # comments: [{author: comment_author}]
19
+ # },
20
+ # issue: {
21
+ # comments: [{author: comment_author}]
22
+ # })
23
+ #
24
+ def initialize(repo_owner: nil, repo_name: nil, pull_request: {}, issue: {}, commits: [])
25
+ raise "FakeGitHub#new: repo_owner AND repo_name keywords are required" unless repo_owner and repo_name
26
+
27
+ self.repo_owner = repo_owner
28
+ self.repo_name = repo_name
29
+
30
+ stub_github_request(:pull_request, pull_request) if pull_request
31
+ stub_github_request(:issue, issue) if issue
32
+ stub_github_request(:commits, commits) if commits.any?
33
+
34
+ if pull_request and (issue.none? or !issue[:comments])
35
+ stub_github_request(:issue, pull_request.merge({comments: []}))
36
+ end
37
+
38
+ if pull_request and commits.none?
39
+ stub_github_request(:commits, [{
40
+ author: pull_request[:owner] || DEFAULT_COMMIT_AUTHOR,
41
+ created_at: Chronic.parse(DEFAULT_COMMIT_TIME)
42
+ }])
43
+ end
44
+
45
+ self
46
+ end
47
+
48
+ def stub_github_request(object_to_stub, object_data)
49
+ case object_to_stub
50
+ when :commits
51
+ commits_response = Fixture.new('repositories/commits.json.erb',
52
+ repo_owner: repo_owner,
53
+ repo_name: repo_name,
54
+ commits: object_data)
55
+ commits_response.to_json_hashie.each_with_index do |commit, index|
56
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?commits/#{commit.sha}\?}).
57
+ to_return(
58
+ body: commit.to_json.to_s,
59
+ status: 201,
60
+ headers: {content_type: "application/json; charset=utf-8"})
61
+ stub_request(:get, %r{/repos/#{self.repo_owner}/commits\Z}).
62
+ to_return(
63
+ body: commits_response.to_s,
64
+ status: 201,
65
+ headers: {content_type: "application/json; charset=utf-8"})
66
+ end
67
+ when :issue
68
+ # Stubbing issue comments
69
+ if object_data[:comments]
70
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?issues/#{object_data[:number] || 1}/comments}).
71
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
72
+ to_return(body: Fixture.new('issues/comments.json.erb',
73
+ repo_owner: self.repo_owner,
74
+ repo_name: self.repo_name,
75
+ comments: object_data[:comments],
76
+ pull_request_number: object_data[:number] || 1,
77
+ body: object_data[:body] || 'Hammer time',
78
+ created_at: object_data[:created_at] || Chronic.parse("1.minute ago")).to_s,
79
+ status: 201,
80
+ headers: {content_type: "application/json; charset=utf-8"})
81
+ else
82
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?issues/#{object_data[:number] || 1}/comments}).
83
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
84
+ to_return(body: '[]', status: 201, headers: {content_type: "application/json; charset=utf-8"})
85
+ end
86
+ when :pull_request
87
+ # EXAMPLES
88
+ stubbed_pull_request_response = Fixture.new('pull_requests/pull_request.json.erb',
89
+ number: object_data[:number] || 1,
90
+ title: object_data[:title] || 'Please merge these changes',
91
+ body: object_data[:body] || 'Bone saw is ready.',
92
+ state: object_data[:state] || 'open',
93
+ owner: object_data[:owner] || 'octocat',
94
+ feature_repo_owner: object_data[:feature_repo_owner] || self.repo_owner,
95
+ feature_branch: object_data[:feature_branch] || 'new-feature',
96
+ base_branch: object_data[:base_branch] || 'master',
97
+ repo_owner: self.repo_owner,
98
+ repo_name: self.repo_name)
99
+
100
+ stub_request(:get, "#{GitReflow::GitServer::GitHub.api_endpoint}/repos/#{self.repo_owner}/#{self.repo_name}/pulls/#{object_data[:number]}").
101
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
102
+ to_return(body: stubbed_pull_request_response.to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
103
+ stub_request(:get, "#{GitReflow::GitServer::GitHub.api_endpoint}/repos/#{self.repo_owner}/#{self.repo_name}/pulls")
104
+ .with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => object_data[:base_branch] || 'master', 'head' => "#{object_data[:feature_repo_owner] || self.repo_owner}:#{object_data[:feature_branch] || "new-feature"}", 'state' => object_data[:state] || 'open'}).
105
+ to_return(:body => "[#{stubbed_pull_request_response.to_s}]", :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
106
+
107
+ # Stubbing pull request comments
108
+ if object_data[:comments]
109
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?pulls/#{object_data[:number] || 1}/comments}).
110
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
111
+ to_return(body: Fixture.new('pull_requests/comments.json.erb',
112
+ repo_owner: self.repo_owner,
113
+ repo_name: self.repo_name,
114
+ comments: object_data[:comments],
115
+ pull_request_number: object_data[:number] || 1,
116
+ created_at: object_data[:created_at] || Time.now).to_s,
117
+ status: 201,
118
+ headers: {content_type: "application/json; charset=utf-8"})
119
+ end
120
+
121
+ # Stubbing pull request commits
122
+ #stub_get(%r{#{GitReflow::GitServer::GitHub.api_endpoint}/repos/#{user}/#{repo}/pulls/#{existing_pull_request.number}/commits}).
123
+ # with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
124
+ # to_return(:body => Fixture.new("pull_requests/commits.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
125
+ end
126
+ end
127
+ end
128
+
@@ -1,8 +1,54 @@
1
- def fixture_path
2
- File.expand_path("../../fixtures", __FILE__)
3
- end
1
+ # ERB parsing credit:
2
+ # http://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash/9734736#9734736
4
3
 
5
- def fixture(file)
6
- File.new(File.join(fixture_path, '/', file))
7
- end
4
+ require 'erb'
5
+ require 'ostruct'
6
+
7
+ class Fixture
8
+ attr_accessor :file, :locals
9
+
10
+ def initialize(file, locals = {})
11
+ @file = fixture(file)
12
+ @locals = locals
13
+ end
14
+
15
+ def fixture_path
16
+ File.expand_path("../../fixtures", __FILE__)
17
+ end
18
+
19
+ def fixture(file)
20
+ File.new(File.join(fixture_path, "/", file))
21
+ end
8
22
 
23
+ def to_s
24
+ if File.extname(file) == ".erb"
25
+ ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding }).to_s
26
+ else
27
+ template_file_content.to_s
28
+ end
29
+ end
30
+
31
+ def to_json
32
+ if File.extname(file) == ".erb"
33
+ rendered_file = ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding })
34
+ JSON.parse(rendered_file)
35
+ else
36
+ JSON.parse(template_file_content)
37
+ end
38
+ end
39
+
40
+ def to_json_hashie
41
+ json = self.to_json
42
+ if json.is_a? Array
43
+ json.map {|json_object| Hashie::Mash.new json_object }
44
+ else
45
+ Hashie::Mash.new json
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def template_file_content
52
+ @file_content ||= file.read
53
+ end
54
+ end
@@ -1,8 +1,7 @@
1
1
  $LOAD_PATH << 'lib'
2
2
  require 'git_reflow'
3
3
  require 'github_api'
4
- require File.expand_path('../web_mocks', __FILE__)
5
- require File.expand_path('../fixtures', __FILE__)
4
+ require 'spec_helper'
6
5
 
7
6
  module GithubHelpers
8
7
  def stub_github_with(options = {})
@@ -56,15 +55,15 @@ module GithubHelpers
56
55
  github_server.class.stub(:remote_user).and_return(user)
57
56
  github_server.class.stub(:remote_repo).and_return(repo)
58
57
  github_server.class.stub(:oauth_token).and_return(oauth_token_hash.token)
59
- github_server.class.stub(:get_commited_time).and_return(Time.now)
58
+ github_server.class.stub(:get_committed_time).and_return(Time.now)
60
59
 
61
60
  GitReflow.stub(:git_server).and_return(github_server)
62
61
 
63
62
  # Stubbing statuses for a given commit
64
- stub_request(:get, %r{#{GitReflow.git_server.class.api_endpoint}/repos/#{user}/commits/\w+}).
65
- to_return(:body => fixture('repositories/commit.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
66
- stub_request(:get, %r{#{GitReflow.git_server.class.api_endpoint}/repos/#{user}/commits/\w+/statuses?}).
67
- to_return(:body => fixture('pull_requests/pull_requests.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
63
+ #stub_request(:get, %r{#{GitReflow.git_server.class.api_endpoint}/repos/#{user}/commits/\w+}).
64
+ # to_return(:body => Fixture.new('repositories/commit.json.erb', repo_owner: user, repo_name: repo, author: user).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
65
+ stub_request(:get, %r{/repos/#{user}/(#{repo}/)?commits/\w+/statuses}).
66
+ to_return(:body => Fixture.new('repositories/statuses.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
68
67
 
69
68
  if pull
70
69
  # Stubbing review
@@ -72,22 +71,33 @@ module GithubHelpers
72
71
  to_return(:body => pull.to_s, :status => 201, :headers => {:content_type => "application/json\; charset=utf-8"})
73
72
 
74
73
  # Stubbing pull request finder
74
+ stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
75
+ to_return(:body => Fixture.new('pull_requests/pull_request.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
75
76
  stub_get("/repos/#{user}/pulls").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => 'master', 'head' => "#{user}:#{branch}", 'state' => 'open'}).
76
- to_return(:body => fixture('pull_requests/pull_requests.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
77
+ to_return(:body => Fixture.new('pull_requests/pull_requests.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
77
78
  stub_get("/repos/#{user}/#{repo}/pulls").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => 'master', 'head' => "#{user}:#{branch}", 'state' => 'open'}).
78
- to_return(:body => fixture('pull_requests/pull_requests.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
79
+ to_return(:body => Fixture.new('pull_requests/pull_requests.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
79
80
  # Stubbing pull request comments
81
+ stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
82
+ to_return(:body => Fixture.new('pull_requests/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
80
83
  stub_get("/repos/#{user}/pulls/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
81
- to_return(:body => fixture('pull_requests/comments.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
84
+ to_return(:body => Fixture.new('pull_requests/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
82
85
  # Stubbing issue comments
83
86
  stub_get("/repos/#{user}/issues/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
84
- to_return(:body => fixture('issues/comments.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
87
+ to_return(:body => Fixture.new('issues/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
88
+ stub_get("/repos/#{user}/#{repo}/issues/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
89
+ to_return(:body => Fixture.new('issues/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
90
+ # Stubbing pull request commits
91
+ stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}/commits").with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
92
+ to_return(:body => Fixture.new("pull_requests/commits.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
93
+ stub_request(:get, %r{/repos/#{user}/commits/\w+}).with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
94
+ to_return(:body => Fixture.new("repositories/commit.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
85
95
  end
86
96
 
87
97
  github_server
88
98
  end
89
99
  end
90
-
100
+ #
91
101
  # the github_api gem does some overrides to Hash so we have to make sure
92
102
  # this still works here...
93
103
  class Hash