git_reflow 0.8.10 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.ruby-version +1 -1
  4. data/Appraisals +1 -6
  5. data/CHANGELOG.md +426 -348
  6. data/Gemfile.lock +15 -19
  7. data/LICENSE +20 -20
  8. data/README.md +27 -7
  9. data/Rakefile +8 -8
  10. data/bin/console +7 -7
  11. data/bin/setup +6 -6
  12. data/circle.yml +5 -5
  13. data/exe/git-reflow +9 -30
  14. data/git_reflow.gemspec +1 -2
  15. data/lib/git_reflow/config.rb +22 -13
  16. data/lib/git_reflow/git_helpers.rb +69 -22
  17. data/lib/git_reflow/git_server/base.rb +68 -68
  18. data/lib/git_reflow/git_server/git_hub/pull_request.rb +15 -13
  19. data/lib/git_reflow/git_server/pull_request.rb +4 -2
  20. data/lib/git_reflow/merge_error.rb +9 -9
  21. data/lib/git_reflow/rspec/command_line_helpers.rb +9 -1
  22. data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
  23. data/lib/git_reflow/rspec/workflow_helpers.rb +18 -0
  24. data/lib/git_reflow/rspec.rb +1 -0
  25. data/lib/git_reflow/sandbox.rb +1 -0
  26. data/lib/git_reflow/version.rb +1 -1
  27. data/lib/git_reflow/workflow.rb +277 -9
  28. data/lib/git_reflow/workflows/FlatMergeWorkflow +38 -0
  29. data/lib/git_reflow/workflows/core.rb +208 -79
  30. data/lib/git_reflow.rb +3 -14
  31. data/spec/fixtures/awesome_workflow.rb +2 -6
  32. data/spec/fixtures/git/git_config +7 -7
  33. data/spec/fixtures/issues/comment.json.erb +27 -27
  34. data/spec/fixtures/issues/comments.json +29 -29
  35. data/spec/fixtures/issues/comments.json.erb +15 -15
  36. data/spec/fixtures/pull_requests/comment.json.erb +45 -45
  37. data/spec/fixtures/pull_requests/comments.json +47 -47
  38. data/spec/fixtures/pull_requests/comments.json.erb +15 -15
  39. data/spec/fixtures/pull_requests/commits.json +29 -29
  40. data/spec/fixtures/pull_requests/external_pull_request.json +145 -145
  41. data/spec/fixtures/pull_requests/pull_request.json +142 -142
  42. data/spec/fixtures/pull_requests/pull_request.json.erb +142 -142
  43. data/spec/fixtures/pull_requests/pull_request_branch_nonexistent_error.json +32 -0
  44. data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -32
  45. data/spec/fixtures/pull_requests/pull_requests.json +136 -136
  46. data/spec/fixtures/repositories/commit.json +53 -53
  47. data/spec/fixtures/repositories/commit.json.erb +53 -53
  48. data/spec/fixtures/repositories/commits.json.erb +13 -13
  49. data/spec/fixtures/repositories/statuses.json +31 -31
  50. data/spec/lib/git_reflow/git_helpers_spec.rb +115 -12
  51. data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +6 -6
  52. data/spec/lib/git_reflow/git_server/pull_request_spec.rb +9 -3
  53. data/spec/lib/git_reflow/workflow_spec.rb +190 -11
  54. data/spec/lib/git_reflow/workflows/core_spec.rb +224 -65
  55. data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +17 -6
  56. data/spec/lib/git_reflow_spec.rb +2 -25
  57. data/spec/spec_helper.rb +3 -0
  58. data/spec/support/github_helpers.rb +1 -1
  59. data/spec/support/mock_pull_request.rb +17 -17
  60. data/spec/support/web_mocks.rb +39 -39
  61. metadata +9 -28
  62. data/lib/git_reflow/commands/deliver.rb +0 -10
  63. data/lib/git_reflow/commands/refresh.rb +0 -20
  64. data/lib/git_reflow/commands/review.rb +0 -13
  65. data/lib/git_reflow/commands/setup.rb +0 -11
  66. data/lib/git_reflow/commands/stage.rb +0 -9
  67. data/lib/git_reflow/commands/start.rb +0 -18
  68. data/lib/git_reflow/commands/status.rb +0 -7
  69. data/lib/git_reflow/workflows/flat_merge.rb +0 -10
  70. data/spec/fixtures/workflow_with_super.rb +0 -8
@@ -5,14 +5,51 @@ describe GitReflow::Workflows::Core do
5
5
  let(:existing_pull_requests) { Fixture.new('pull_requests/pull_requests.json').to_json_hashie }
6
6
  let(:existing_gh_pull_request) { GitReflow::GitServer::GitHub::PullRequest.new existing_pull_requests.first }
7
7
  let(:pull_request_message_file) { "#{GitReflow.git_root_dir}/.git/GIT_REFLOW_PR_MSG" }
8
+ let(:workflow) { described_class }
8
9
 
9
10
  before do
10
- allow(GitReflow).to receive(:current_branch).and_return(feature_branch)
11
+ allow(workflow).to receive(:current_branch).and_return(feature_branch)
11
12
  allow_any_instance_of(HighLine).to receive(:choose)
12
13
  end
13
14
 
15
+ describe ".load_workflow(workflow_path)" do
16
+ let(:workflow_path) { "/tmp/Workflow" }
17
+ subject { GitReflow::Workflows::Core.load_workflow(workflow_path) }
18
+
19
+ before { allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_call_original }
20
+
21
+ it "returns `nil` if the workflow path doesn't exist" do
22
+ allow(File).to receive(:exists?).and_return(false)
23
+ expect(subject).to be_nil
24
+ end
25
+
26
+ it "evaluates the workflow file in the context of the class" do
27
+ workflow_content = "# testing"
28
+ allow(File).to receive(:exists?).with("#{GitReflow.git_root_dir}/Workflow").and_return(false)
29
+ allow(File).to receive(:exists?).with(workflow_path).and_return(true)
30
+ expect(File).to receive(:read).with(workflow_path).and_return(workflow_content)
31
+ expect(GitReflow::Workflows::Core).to receive(:load_raw_workflow).with(workflow_content)
32
+ subject
33
+ end
34
+ end
35
+
36
+ describe ".load_raw_workflow(workflow_string)" do
37
+ before { allow(GitReflow::Workflows::Core).to receive(:load_workflow).and_call_original }
38
+ it "evaluates the raw string in the context of the Core workflow" do
39
+ workflow_content = <<~WORKFLOW_CONTENT
40
+ command :dummy do
41
+ puts "Dummy"
42
+ end
43
+ WORKFLOW_CONTENT
44
+ fake_binding = instance_double(Binding)
45
+ expect(fake_binding).to receive(:eval).with(workflow_content)
46
+ expect(described_class).to receive(:binding).and_return(fake_binding)
47
+ GitReflow::Workflows::Core.load_raw_workflow(workflow_content)
48
+ end
49
+ end
50
+
14
51
  describe ".setup" do
15
- subject { GitReflow::Workflows::Core.setup }
52
+ subject { workflow.setup }
16
53
 
17
54
  before do
18
55
  allow(File).to receive(:exist?).and_return(false)
@@ -27,7 +64,8 @@ describe GitReflow::Workflows::Core do
27
64
  context "core.editor git config has already been set" do
28
65
  before do
29
66
  allow(GitReflow::Config).to receive(:get) { "" }
30
- allow(GitReflow::Config).to receive(:get).with('core.editor').and_return('emacs')
67
+ allow(workflow.git_config).to receive(:get) { "" }
68
+ allow(workflow.git_config).to receive(:get).with('core.editor').and_return('emacs')
31
69
  end
32
70
 
33
71
  specify { expect { subject }.to_not have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all core.editor \"#{GitReflow.default_editor}\"", blocking: false }
@@ -83,9 +121,9 @@ describe GitReflow::Workflows::Core do
83
121
 
84
122
  describe ".start" do
85
123
  let(:feature_branch) { 'new_feature' }
86
- subject { GitReflow::Workflows::Core.start feature_branch: feature_branch }
124
+ subject { workflow.start feature_branch: feature_branch }
87
125
 
88
- it "updates the local repo and starts creates a new branch" do
126
+ it "updates the local repo and creates a new branch" do
89
127
  expect { subject }.to have_run_commands_in_order [
90
128
  "git checkout master",
91
129
  "git pull origin master",
@@ -107,13 +145,23 @@ describe GitReflow::Workflows::Core do
107
145
  end
108
146
 
109
147
  it "starts from a different base branch when one is supplied" do
110
- expect { GitReflow::Workflows::Core.start feature_branch: feature_branch, base: 'development' }.to have_run_commands_in_order [
148
+ expect { workflow.start feature_branch: feature_branch, base: 'development' }.to have_run_commands_in_order [
111
149
  "git checkout development",
112
150
  "git pull origin development",
113
151
  "git push origin development:refs/heads/#{feature_branch}",
114
152
  "git checkout --track -b #{feature_branch} origin/#{feature_branch}"
115
153
  ]
116
154
  end
155
+
156
+ it "starts from a different base branch when one is configured" do
157
+ allow(GitReflow::Config).to receive(:get).with("reflow.base-branch").and_return("sudo-master")
158
+ expect { workflow.start feature_branch: feature_branch }.to have_run_commands_in_order [
159
+ "git checkout sudo-master",
160
+ "git pull origin sudo-master",
161
+ "git push origin sudo-master:refs/heads/#{feature_branch}",
162
+ "git checkout --track -b #{feature_branch} origin/#{feature_branch}"
163
+ ]
164
+ end
117
165
  end
118
166
 
119
167
  describe ".review" do
@@ -124,11 +172,11 @@ describe GitReflow::Workflows::Core do
124
172
  let(:inputs) { {} }
125
173
 
126
174
  before do
127
- allow(GitReflow).to receive(:remote_user).and_return(user)
175
+ allow(workflow).to receive(:remote_user).and_return(user)
128
176
  allow(GitReflow).to receive(:git_server).and_return(GitReflow::GitServer)
129
- allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
130
- allow(GitReflow.git_server).to receive(:find_open_pull_request).and_return(nil)
131
- allow(GitReflow.git_server).to receive(:create_pull_request).and_return(existing_gh_pull_request)
177
+ allow(workflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
178
+ allow(workflow.git_server).to receive(:find_open_pull_request).and_return(nil)
179
+ allow(workflow.git_server).to receive(:create_pull_request).and_return(existing_gh_pull_request)
132
180
  allow(File).to receive(:open).with(pull_request_message_file, 'w')
133
181
  allow(File).to receive(:read).with(pull_request_message_file).and_return("bingo")
134
182
  allow(File).to receive(:delete)
@@ -138,7 +186,7 @@ describe GitReflow::Workflows::Core do
138
186
  })
139
187
  end
140
188
 
141
- subject { GitReflow::Workflows::Core.review inputs }
189
+ subject { workflow.review inputs }
142
190
 
143
191
  it "fetches updates to the base branch" do
144
192
  expect { subject }.to have_run_command "git fetch origin master"
@@ -151,7 +199,7 @@ describe GitReflow::Workflows::Core do
151
199
  it "uses the current branch name as the text for the PR" do
152
200
  fake_file = double
153
201
  expect(File).to receive(:open).with(pull_request_message_file, "w").and_yield(fake_file)
154
- expect(fake_file).to receive(:write).with(GitReflow.current_branch)
202
+ expect(fake_file).to receive(:write).with(workflow.current_branch)
155
203
  subject
156
204
  end
157
205
 
@@ -175,7 +223,7 @@ describe GitReflow::Workflows::Core do
175
223
  context "and a PR template exists" do
176
224
  let(:template_content) { "hey now" }
177
225
  before do
178
- allow(GitReflow).to receive(:pull_request_template).and_return(template_content)
226
+ allow(workflow).to receive(:pull_request_template).and_return(template_content)
179
227
  end
180
228
 
181
229
  it "uses the template's content for the PR" do
@@ -184,7 +232,6 @@ describe GitReflow::Workflows::Core do
184
232
  expect(fake_file).to receive(:write).with(template_content)
185
233
  subject
186
234
  end
187
-
188
235
  end
189
236
 
190
237
  context "providing a base branch" do
@@ -197,7 +244,7 @@ describe GitReflow::Workflows::Core do
197
244
  end
198
245
 
199
246
  it "creates a pull request using the custom base branch" do
200
- expect(GitReflow.git_server).to receive(:create_pull_request).with({
247
+ expect(workflow.git_server).to receive(:create_pull_request).with({
201
248
  title: 'bingo',
202
249
  body: "\n",
203
250
  head: "#{user}:#{feature_branch}",
@@ -207,6 +254,25 @@ describe GitReflow::Workflows::Core do
207
254
  end
208
255
  end
209
256
 
257
+ context 'when a base branch is configured' do
258
+ before do
259
+ stub_command_line_inputs('Submit pull request? (Y)' => 'yes')
260
+ allow(GitReflow::Config).to receive(:get).and_call_original
261
+ allow(GitReflow::Config).to receive(:get).with('reflow.base-branch').and_return('racecar')
262
+ inputs.delete(:base)
263
+ end
264
+
265
+ it 'creates a pull request using the custom base branch' do
266
+ expect(GitReflow.git_server).to receive(:create_pull_request).with({
267
+ title: 'bingo',
268
+ body: "\n",
269
+ head: "#{user}:#{feature_branch}",
270
+ base: 'racecar'
271
+ })
272
+ subject
273
+ end
274
+ end
275
+
210
276
  context "providing only a title" do
211
277
  let(:inputs) {{ title: "Amazing new feature" }}
212
278
 
@@ -217,7 +283,7 @@ describe GitReflow::Workflows::Core do
217
283
  end
218
284
 
219
285
  it "creates a pull request with only the given title" do
220
- expect(GitReflow.git_server).to receive(:create_pull_request).with({
286
+ expect(workflow.git_server).to receive(:create_pull_request).with({
221
287
  title: inputs[:title],
222
288
  body: nil,
223
289
  head: "#{user}:#{feature_branch}",
@@ -235,7 +301,7 @@ describe GitReflow::Workflows::Core do
235
301
  end
236
302
 
237
303
  context "providing only a body" do
238
- let(:inputs) {{ body: "Please pull this in!" }}
304
+ let(:inputs) {{ message: "Please pull this in!" }}
239
305
 
240
306
  before do
241
307
  stub_command_line_inputs({
@@ -244,9 +310,9 @@ describe GitReflow::Workflows::Core do
244
310
  end
245
311
 
246
312
  it "creates a pull request with the body as both title and body" do
247
- expect(GitReflow.git_server).to receive(:create_pull_request).with({
248
- title: inputs[:body],
249
- body: inputs[:body],
313
+ expect(workflow.git_server).to receive(:create_pull_request).with({
314
+ title: inputs[:message],
315
+ body: inputs[:message],
250
316
  head: "#{user}:#{feature_branch}",
251
317
  base: 'master'
252
318
  })
@@ -255,7 +321,7 @@ describe GitReflow::Workflows::Core do
255
321
  end
256
322
 
257
323
  context "providing both title and body" do
258
- let(:inputs) {{ title: "Amazing new feature", body: "Please pull this in!" }}
324
+ let(:inputs) {{ title: "Amazing new feature", message: "Please pull this in!" }}
259
325
 
260
326
  before do
261
327
  stub_command_line_inputs({
@@ -264,9 +330,9 @@ describe GitReflow::Workflows::Core do
264
330
  end
265
331
 
266
332
  it "creates a pull request with only the given title" do
267
- expect(GitReflow.git_server).to receive(:create_pull_request).with({
333
+ expect(workflow.git_server).to receive(:create_pull_request).with({
268
334
  title: inputs[:title],
269
- body: inputs[:body],
335
+ body: inputs[:message],
270
336
  head: "#{user}:#{feature_branch}",
271
337
  base: 'master'
272
338
  })
@@ -276,7 +342,7 @@ describe GitReflow::Workflows::Core do
276
342
 
277
343
  context "with existing pull request" do
278
344
  before do
279
- expect(GitReflow.git_server).to receive(:find_open_pull_request).and_return(existing_gh_pull_request)
345
+ expect(workflow.git_server).to receive(:find_open_pull_request).and_return(existing_gh_pull_request)
280
346
  allow(existing_gh_pull_request).to receive(:display_pull_request_summary)
281
347
  end
282
348
 
@@ -296,7 +362,7 @@ describe GitReflow::Workflows::Core do
296
362
  end
297
363
 
298
364
  it "creates a pull request" do
299
- expect(GitReflow.git_server).to receive(:create_pull_request).with({
365
+ expect(workflow.git_server).to receive(:create_pull_request).with({
300
366
  title: 'bingo',
301
367
  body: "\n",
302
368
  head: "#{user}:#{feature_branch}",
@@ -306,9 +372,27 @@ describe GitReflow::Workflows::Core do
306
372
  end
307
373
 
308
374
  it "notifies the user that the pull request was created" do
309
- expect(GitReflow.git_server).to receive(:create_pull_request).and_return(existing_gh_pull_request)
375
+ expect(workflow.git_server).to receive(:create_pull_request).and_return(existing_gh_pull_request)
310
376
  expect{ subject }.to have_said "Successfully created pull request ##{existing_gh_pull_request.number}: #{existing_gh_pull_request.title}\nPull Request URL: #{existing_gh_pull_request.html_url}\n", :success
311
377
  end
378
+
379
+ context "when pull request creation fails" do
380
+ let(:github_error) { Github::Error::UnprocessableEntity.new(eval(Fixture.new('pull_requests/pull_request_branch_nonexistent_error.json').to_s)) }
381
+
382
+ it "retries creating a pull request" do
383
+ call_count = 0
384
+ allow(workflow.git_server).to receive(:create_pull_request) do
385
+ call_count += 1
386
+ (call_count <= 1) ? raise(github_error) : existing_gh_pull_request
387
+ end
388
+ expect{ subject }.to have_said "Successfully created pull request ##{existing_gh_pull_request.number}: #{existing_gh_pull_request.title}\nPull Request URL: #{existing_gh_pull_request.html_url}\n", :success
389
+ end
390
+
391
+ it "reports failures even after retrying" do
392
+ allow(workflow.git_server).to receive(:create_pull_request).and_raise github_error
393
+ expect { subject }.to have_said "Github Error: #{github_error.to_s}", :error
394
+ end
395
+ end
312
396
  end
313
397
 
314
398
  context "aborting during PR template review" do
@@ -319,7 +403,7 @@ describe GitReflow::Workflows::Core do
319
403
  end
320
404
 
321
405
  it "does not create a pull request" do
322
- expect(GitReflow.git_server).to_not receive(:create_pull_request)
406
+ expect(workflow.git_server).to_not receive(:create_pull_request)
323
407
  subject
324
408
  end
325
409
 
@@ -333,17 +417,17 @@ describe GitReflow::Workflows::Core do
333
417
  let(:feature_branch) { 'new-feature' }
334
418
  let(:destination_branch) { nil }
335
419
 
336
- subject { GitReflow::Workflows::Core.status destination_branch: destination_branch }
420
+ subject { workflow.status destination_branch: destination_branch }
337
421
 
338
422
  before do
339
423
  allow(GitReflow).to receive(:git_server).and_return(GitReflow::GitServer)
340
- allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
424
+ allow(workflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
341
425
  allow(GitReflow).to receive(:current_branch).and_return(feature_branch)
342
426
  allow(existing_gh_pull_request).to receive(:display_pull_request_summary)
343
427
  end
344
428
 
345
429
  context "with no existing pull request" do
346
- before { allow(GitReflow.git_server).to receive(:find_open_pull_request).with({from: feature_branch, to: 'master'}).and_return(nil) }
430
+ before { allow(workflow.git_server).to receive(:find_open_pull_request).with({from: feature_branch, to: 'master'}).and_return(nil) }
347
431
  it { expect{ subject }.to have_said "No pull request exists for #{feature_branch} -> master", :notice }
348
432
  it { expect{ subject }.to have_said "Run 'git reflow review master' to start the review process", :notice }
349
433
  end
@@ -351,7 +435,7 @@ describe GitReflow::Workflows::Core do
351
435
  context "with an existing pull request" do
352
436
  let(:destination_branch) { 'master' }
353
437
  before do
354
- allow(GitReflow.git_server).to receive(:find_open_pull_request).and_return(existing_gh_pull_request)
438
+ allow(workflow.git_server).to receive(:find_open_pull_request).and_return(existing_gh_pull_request)
355
439
  end
356
440
 
357
441
  it "displays a summary of the pull request" do
@@ -363,7 +447,19 @@ describe GitReflow::Workflows::Core do
363
447
  let(:destination_branch) { 'develop' }
364
448
 
365
449
  it "uses the custom destination branch to lookup the pull request" do
366
- expect(GitReflow.git_server).to receive(:find_open_pull_request).with({from: feature_branch, to: destination_branch}).and_return(existing_gh_pull_request)
450
+ expect(workflow.git_server).to receive(:find_open_pull_request).with({from: feature_branch, to: destination_branch}).and_return(existing_gh_pull_request)
451
+ subject
452
+ end
453
+ end
454
+
455
+ context "when custom base-branch is configured" do
456
+ before do
457
+ allow(GitReflow::Config).to receive(:get).and_call_original
458
+ allow(GitReflow::Config).to receive(:get).with('reflow.base-branch').and_return('racecar')
459
+ end
460
+ subject { workflow.status }
461
+ it "uses the custom configured base-branch to lookup the pull request" do
462
+ expect(GitReflow.git_server).to receive(:find_open_pull_request).with({from: feature_branch, to: 'racecar'}).and_return(existing_gh_pull_request)
367
463
  subject
368
464
  end
369
465
  end
@@ -373,7 +469,7 @@ describe GitReflow::Workflows::Core do
373
469
  describe ".deploy" do
374
470
  let(:deploy_command) { "bundle exec cap #{destination} deploy" }
375
471
  let(:destination) { nil }
376
- subject { GitReflow::Workflows::Core.deploy(destination_server: destination) }
472
+ subject { workflow.deploy(destination_server: destination) }
377
473
 
378
474
  before do
379
475
  stub_command_line_inputs({
@@ -408,16 +504,16 @@ describe GitReflow::Workflows::Core do
408
504
  describe ".stage" do
409
505
  let(:feature_branch) { 'new-feature' }
410
506
 
411
- subject { GitReflow::Workflows::Core.stage }
507
+ subject { workflow.stage }
412
508
 
413
509
  before do
414
- allow(GitReflow).to receive(:current_branch).and_return(feature_branch)
415
- allow(GitReflow::Config).to receive(:get).and_call_original
510
+ allow(workflow).to receive(:current_branch).and_return(feature_branch)
511
+ allow(workflow.git_config).to receive(:get).and_call_original
416
512
  allow(GitReflow::Workflows::Core).to receive(:deploy)
417
513
  end
418
514
 
419
515
  it "checks out and updates the staging branch" do
420
- expect(GitReflow::Config).to receive(:get).with('reflow.staging-branch', local: true).and_return('staging')
516
+ expect(workflow.git_config).to receive(:get).with('reflow.staging-branch', local: true).and_return('staging')
421
517
  expect { subject }.to have_run_commands_in_order([
422
518
  "git checkout staging",
423
519
  "git pull origin staging",
@@ -428,9 +524,9 @@ describe GitReflow::Workflows::Core do
428
524
 
429
525
  context "merge is not successful" do
430
526
  before do
431
- allow(GitReflow::Config).to receive(:get).with('reflow.staging-branch', local: true).and_return('staging')
432
- allow(GitReflow).to receive(:run_command_with_label).and_call_original
433
- expect(GitReflow).to receive(:run_command_with_label).with("git merge #{feature_branch}", with_system: true).and_return(false)
527
+ allow(workflow.git_config).to receive(:get).with('reflow.staging-branch', local: true).and_return('staging')
528
+ allow(workflow).to receive(:run_command_with_label).and_call_original
529
+ expect(workflow).to receive(:run_command_with_label).with("git merge #{feature_branch}", with_system: true).and_return(false)
434
530
  end
435
531
 
436
532
  it "notifies the user of unsuccessful merge" do
@@ -449,9 +545,9 @@ describe GitReflow::Workflows::Core do
449
545
 
450
546
  context "merge is successful" do
451
547
  before do
452
- allow(GitReflow::Config).to receive(:get).with('reflow.staging-branch', local: true).and_return('staging')
453
- allow(GitReflow).to receive(:run_command_with_label).and_call_original
454
- expect(GitReflow).to receive(:run_command_with_label).with("git merge #{feature_branch}", with_system: true).and_return(true).and_call_original
548
+ allow(workflow.git_config).to receive(:get).with('reflow.staging-branch', local: true).and_return('staging')
549
+ allow(workflow).to receive(:run_command_with_label).and_call_original
550
+ expect(workflow).to receive(:run_command_with_label).with("git merge #{feature_branch}", with_system: true).and_return(true).and_call_original
455
551
  end
456
552
 
457
553
  specify { expect{ subject }.to have_run_command "git push origin staging" }
@@ -469,19 +565,19 @@ describe GitReflow::Workflows::Core do
469
565
 
470
566
  context "no staging branch has been setup" do
471
567
  before do
472
- allow(GitReflow::Config).to receive(:get).with('reflow.staging-branch', local: true).and_return('')
568
+ allow(workflow.git_config).to receive(:get).with('reflow.staging-branch', local: true).and_return('')
473
569
  stub_command_line_inputs({
474
570
  "What's the name of your staging branch? (default: 'staging') " => "bobby"
475
571
  })
476
572
  end
477
573
 
478
574
  it "sets the reflow.staging-branch git config to 'staging'" do
479
- expect(GitReflow::Config).to receive(:set).with("reflow.staging-branch", "bobby", local: true)
575
+ expect(workflow.git_config).to receive(:set).with("reflow.staging-branch", "bobby", local: true)
480
576
  subject
481
577
  end
482
578
 
483
579
  it "checks out and updates the staging branch" do
484
- allow(GitReflow::Config).to receive(:set).with("reflow.staging-branch", "bobby", local: true)
580
+ allow(workflow.git_config).to receive(:set).with("reflow.staging-branch", "bobby", local: true)
485
581
  expect { subject }.to have_run_commands_in_order([
486
582
  "git checkout bobby",
487
583
  "git pull origin bobby",
@@ -518,23 +614,25 @@ describe GitReflow::Workflows::Core do
518
614
  let(:user) { 'reenhanced' }
519
615
  let(:repo) { 'repo' }
520
616
 
521
- subject { GitReflow::Workflows::Core.deliver }
617
+ subject { workflow.deliver }
522
618
 
523
619
  before do
524
620
  allow(GitReflow).to receive(:git_server).and_return(GitReflow::GitServer)
525
621
  allow(GitReflow).to receive(:remote_user).and_return(user)
622
+ allow(workflow).to receive(:remote_user).and_return(user)
526
623
  allow(GitReflow).to receive(:current_branch).and_return(feature_branch)
527
- allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
624
+ allow(workflow).to receive(:current_branch).and_return(feature_branch)
625
+ allow(workflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
528
626
  end
529
627
 
530
628
  context "pull request does not exist" do
531
- before { allow(GitReflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'master').and_return(nil) }
629
+ before { allow(workflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'master').and_return(nil) }
532
630
  specify { expect{ subject }.to have_said "No pull request exists for #{user}:#{feature_branch}\nPlease submit your branch for review first with \`git reflow review\`", :deliver_halted }
533
631
  end
534
632
 
535
633
  context "pull request exists" do
536
634
  before do
537
- allow(GitReflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'master').and_return(existing_gh_pull_request)
635
+ allow(workflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'master').and_return(existing_gh_pull_request)
538
636
  allow(GitReflow::Workflows::Core).to receive(:status)
539
637
  end
540
638
 
@@ -585,11 +683,16 @@ describe GitReflow::Workflows::Core do
585
683
  end
586
684
 
587
685
  context "but forcing the deliver" do
588
- subject { GitReflow::Workflows::Core.deliver force: true }
686
+ subject { workflow.deliver force: true }
589
687
 
590
688
  before do
591
689
  allow(existing_gh_pull_request).to receive(:good_to_merge?).with(force: true).and_return(true)
592
- allow(existing_gh_pull_request).to receive(:merge!).with(force: true, base: 'master')
690
+ allow(existing_gh_pull_request).to receive(:merge!).with(
691
+ force: true,
692
+ merge_method: "squash",
693
+ base: 'master',
694
+ skip_lgtm: false
695
+ )
593
696
  end
594
697
 
595
698
  it "displays the status of the PR" do
@@ -598,28 +701,74 @@ describe GitReflow::Workflows::Core do
598
701
  end
599
702
 
600
703
  it "merges the feature branch anyway" do
601
- expect(existing_gh_pull_request).to receive(:merge!).with(force: true, base: 'master')
704
+ expect(existing_gh_pull_request).to receive(:merge!).with(
705
+ force: true,
706
+ merge_method: "squash",
707
+ base: 'master',
708
+ skip_lgtm: false
709
+ )
602
710
  subject
603
711
  end
604
712
  end
605
713
  end
606
714
 
607
715
  context "and using a custom base branch" do
608
- subject { GitReflow::Workflows::Core.deliver base: 'development' }
716
+ subject { workflow.deliver base: 'development' }
609
717
  before do
610
- expect(GitReflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'development').and_return(existing_gh_pull_request)
718
+ expect(workflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'development').and_return(existing_gh_pull_request)
611
719
  allow(existing_gh_pull_request).to receive(:good_to_merge?).and_return(true)
612
720
  end
613
721
 
614
722
 
615
723
  it "displays the status of the PR" do
616
- allow(existing_gh_pull_request).to receive(:merge!).with(base: 'development')
724
+ allow(existing_gh_pull_request).to receive(:merge!).with(
725
+ base: 'development',
726
+ merge_method: "squash",
727
+ force: false,
728
+ skip_lgtm: false
729
+ )
617
730
  expect(GitReflow::Workflows::Core).to receive(:status).with(destination_branch: 'development')
618
731
  subject
619
732
  end
620
733
 
621
734
  it "merges the feature branch" do
622
- expect(existing_gh_pull_request).to receive(:merge!).with(base: 'development')
735
+ expect(existing_gh_pull_request).to receive(:merge!).with(
736
+ base: "development",
737
+ merge_method: "squash",
738
+ force: false,
739
+ skip_lgtm: false
740
+ )
741
+ subject
742
+ end
743
+ end
744
+
745
+ context "when a custom base-branch is configured" do
746
+ subject { workflow.deliver }
747
+ before do
748
+ expect(GitReflow.git_server).to receive(:find_open_pull_request).with( from: feature_branch, to: 'racecar').and_return(existing_gh_pull_request)
749
+ allow(existing_gh_pull_request).to receive(:good_to_merge?).and_return(true)
750
+ allow(GitReflow::Config).to receive(:get).with('reflow.base-branch').and_return('racecar')
751
+ end
752
+
753
+
754
+ it "displays the status of the PR" do
755
+ allow(existing_gh_pull_request).to receive(:merge!).with(
756
+ base: 'racecar',
757
+ merge_method: "squash",
758
+ force: false,
759
+ skip_lgtm: false
760
+ )
761
+ expect(GitReflow::Workflows::Core).to receive(:status).with(destination_branch: 'racecar')
762
+ subject
763
+ end
764
+
765
+ it "merges the feature branch" do
766
+ expect(existing_gh_pull_request).to receive(:merge!).with(
767
+ base: "racecar",
768
+ merge_method: "squash",
769
+ force: false,
770
+ skip_lgtm: false
771
+ )
623
772
  subject
624
773
  end
625
774
  end
@@ -627,36 +776,46 @@ describe GitReflow::Workflows::Core do
627
776
  end
628
777
 
629
778
  describe ".refresh" do
630
- subject { GitReflow::Workflows::Core.refresh }
779
+ subject { workflow.refresh }
631
780
 
632
781
  it "updates the feature branch with default remote repo and base branch" do
633
- expect(GitReflow).to receive(:update_feature_branch).with(remote: 'origin', base: 'master')
782
+ expect(workflow).to receive(:update_feature_branch).with(remote: 'origin', base: 'master')
634
783
  subject
635
784
  end
636
785
 
637
786
  context "providing a custom base branch" do
638
- subject { GitReflow::Workflows::Core.refresh base: 'development' }
787
+ subject { workflow.refresh base: 'development' }
639
788
 
640
789
  it "updates the feature branch with default remote repo and base branch" do
641
- expect(GitReflow).to receive(:update_feature_branch).with(remote: 'origin', base: 'development')
790
+ expect(workflow).to receive(:update_feature_branch).with(remote: 'origin', base: 'development')
791
+ subject
792
+ end
793
+ end
794
+
795
+ context "when a custom base branch is configured" do
796
+ before { allow(workflow.git_config).to receive(:get).with('reflow.base-branch').and_return('racecar') }
797
+ subject { workflow.refresh }
798
+
799
+ it "updates the feature branch with custom base branch" do
800
+ expect(workflow).to receive(:update_feature_branch).with(remote: 'origin', base: 'racecar')
642
801
  subject
643
802
  end
644
803
  end
645
804
 
646
805
  context "provding a custom remote repo" do
647
- subject { GitReflow::Workflows::Core.refresh remote: 'upstream' }
806
+ subject { workflow.refresh remote: 'upstream' }
648
807
 
649
808
  it "updates the feature branch with default remote repo and base branch" do
650
- expect(GitReflow).to receive(:update_feature_branch).with(remote: 'upstream', base: 'master')
809
+ expect(workflow).to receive(:update_feature_branch).with(remote: 'upstream', base: 'master')
651
810
  subject
652
811
  end
653
812
  end
654
813
 
655
814
  context "providing a custom base branch and remote repo" do
656
- subject { GitReflow::Workflows::Core.refresh remote: 'upstream', base: 'development' }
815
+ subject { workflow.refresh remote: 'upstream', base: 'development' }
657
816
 
658
817
  it "updates the feature branch with default remote repo and base branch" do
659
- expect(GitReflow).to receive(:update_feature_branch).with(remote: 'upstream', base: 'development')
818
+ expect(workflow).to receive(:update_feature_branch).with(remote: 'upstream', base: 'development')
660
819
  subject
661
820
  end
662
821
  end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'FlatMerge' do
4
- let(:workflow_path) { File.join(File.expand_path("../../../../../lib/git_reflow/workflows", __FILE__), "/flat_merge.rb") }
5
4
  let(:mergable_pr) { double(good_to_merge?: true, merge!: true) }
6
5
  let(:git_server) { double(find_open_pull_request: mergable_pr) }
7
6
 
8
7
  before do
9
8
  allow(GitReflow::Config).to receive(:get).and_call_original
10
- allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
11
9
  allow(GitReflow).to receive(:git_server).and_return(git_server)
12
10
  allow(GitReflow).to receive(:status)
11
+ # Makes sure we are loading the right workflow
12
+ workflow_path = File.join(File.expand_path("../../../../../lib/git_reflow/workflows", __FILE__), "FlatMergeWorkflow")
13
+ use_workflow(workflow_path)
13
14
  end
14
15
 
15
- # Makes sure we are loading the right workflow
16
- specify { expect( GitReflow.workflow ).to eql(GitReflow::Workflow::FlatMerge) }
16
+ after { GitReflow::Workflow.reset! }
17
17
 
18
18
  context ".deliver" do
19
19
  subject { GitReflow.deliver }
@@ -25,6 +25,7 @@ describe 'FlatMerge' do
25
25
  let!(:github_api) { github.connection }
26
26
 
27
27
  before do
28
+ allow(File).to receive(:read).and_call_original
28
29
  allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:deliver?).and_return(false)
29
30
  allow(GitReflow::Workflows::Core).to receive(:status)
30
31
  allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
@@ -33,7 +34,12 @@ describe 'FlatMerge' do
33
34
  end
34
35
 
35
36
  it "overrides squash merge in favor of flat merge" do
36
- expect(pr).to receive(:merge!).with(base: 'master', squash: false)
37
+ expect(pr).to receive(:merge!).with(
38
+ base: "master",
39
+ merge_method: "merge",
40
+ force: false,
41
+ skip_lgtm: false
42
+ )
37
43
  subject
38
44
  end
39
45
  end
@@ -51,7 +57,12 @@ describe 'FlatMerge' do
51
57
  end
52
58
 
53
59
  it "doesn't squash merge" do
54
- expect(pr).to receive(:merge!).with(base: 'master', squash: false, force: true)
60
+ expect(pr).to receive(:merge!).with(
61
+ base: "master",
62
+ merge_method: "merge",
63
+ force: true,
64
+ skip_lgtm: false
65
+ )
55
66
  subject
56
67
  end
57
68
  end