git_reflow 0.8.4 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +1 -1
- data/Gemfile.lock +17 -17
- data/git_reflow.gemspec +1 -1
- data/lib/git_reflow/config.rb +1 -1
- data/lib/git_reflow/git_helpers.rb +2 -2
- data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +1 -1
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +11 -10
- data/lib/git_reflow/git_server/pull_request.rb +18 -4
- data/lib/git_reflow/rspec/command_line_helpers.rb +9 -9
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflow.rb +6 -1
- data/lib/git_reflow/workflows/core.rb +1 -3
- data/lib/git_reflow/workflows/flat_merge.rb +10 -0
- data/lib/git_reflow.rb +9 -1
- metadata +7 -70
- data/spec/fixtures/git/git_config +0 -7
- data/spec/fixtures/issues/comment.json.erb +0 -27
- data/spec/fixtures/issues/comments.json +0 -29
- data/spec/fixtures/issues/comments.json.erb +0 -15
- data/spec/fixtures/pull_requests/comment.json.erb +0 -45
- data/spec/fixtures/pull_requests/comments.json +0 -47
- data/spec/fixtures/pull_requests/comments.json.erb +0 -15
- data/spec/fixtures/pull_requests/commits.json +0 -29
- data/spec/fixtures/pull_requests/external_pull_request.json +0 -145
- data/spec/fixtures/pull_requests/pull_request.json +0 -142
- data/spec/fixtures/pull_requests/pull_request.json.erb +0 -142
- data/spec/fixtures/pull_requests/pull_request_exists_error.json +0 -32
- data/spec/fixtures/pull_requests/pull_requests.json +0 -136
- data/spec/fixtures/repositories/commit.json +0 -53
- data/spec/fixtures/repositories/commit.json.erb +0 -53
- data/spec/fixtures/repositories/commits.json.erb +0 -13
- data/spec/fixtures/repositories/statuses.json +0 -31
- data/spec/lib/git_reflow/config_spec.rb +0 -74
- data/spec/lib/git_reflow/git_helpers_spec.rb +0 -182
- data/spec/lib/git_reflow/git_server_spec.rb +0 -101
- data/spec/lib/git_reflow/workflow_spec.rb +0 -56
- data/spec/lib/git_reflow/workflows/core_spec.rb +0 -665
- data/spec/lib/git_reflow_spec.rb +0 -39
- data/spec/lib/git_server/bit_bucket_spec.rb +0 -81
- data/spec/lib/git_server/git_hub/pull_request_spec.rb +0 -472
- data/spec/lib/git_server/git_hub_spec.rb +0 -221
- data/spec/lib/git_server/pull_request_spec.rb +0 -583
- data/spec/spec_helper.rb +0 -38
- data/spec/support/fake_github.rb +0 -128
- data/spec/support/fixtures.rb +0 -54
- data/spec/support/github_helpers.rb +0 -109
- data/spec/support/web_mocks.rb +0 -39
@@ -1,583 +0,0 @@
|
|
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
|
-
let(:git_server) { GitReflow::GitServer::GitHub.new {} }
|
8
|
-
let(:user) { 'reenhanced' }
|
9
|
-
let(:password) { 'shazam' }
|
10
|
-
let(:enterprise_site) { 'https://github.reenhanced.com' }
|
11
|
-
let(:enterprise_api) { 'https://github.reenhanced.com' }
|
12
|
-
|
13
|
-
describe "#good_to_merge?(options)" do
|
14
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
|
15
|
-
|
16
|
-
before do
|
17
|
-
FakeGitHub.new(
|
18
|
-
repo_owner: 'reenhanced',
|
19
|
-
repo_name: 'repo',
|
20
|
-
pull_request: {
|
21
|
-
number: pull_request.number,
|
22
|
-
owner: pull_request.head.user.login,
|
23
|
-
comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
|
24
|
-
})
|
25
|
-
# setup initial valid state
|
26
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
|
27
|
-
allow(GitReflow.git_server).to receive(:find_open_pull_request).with({from: 'new-feature', to: 'master'}).and_return(pull_request)
|
28
|
-
|
29
|
-
# stubs approvals and last_comment conditions to default to true
|
30
|
-
allow(pull_request).to receive(:approvals).and_return(["Simon", "John"])
|
31
|
-
allow(pull_request).to receive_message_chain(:last_comment, :match).and_return(true)
|
32
|
-
allow(GitReflow::GitServer::PullRequest).to receive(:minimum_approvals).and_return("2")
|
33
|
-
allow(GitReflow::GitServer::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
|
34
|
-
|
35
|
-
end
|
36
|
-
context "with no status" do
|
37
|
-
specify { expect(subject.good_to_merge?).to eq(true) }
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with build status" do
|
41
|
-
context "of 'success'" do
|
42
|
-
before { allow(subject).to receive(:build_status).and_return('success') }
|
43
|
-
specify { expect(subject.good_to_merge?).to eq(true) }
|
44
|
-
end
|
45
|
-
|
46
|
-
context "NOT of 'success'" do
|
47
|
-
before { allow(subject).to receive(:build_status).and_return('failure') }
|
48
|
-
specify { expect(subject.good_to_merge?).to eq(false) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Need at least 1 comment for you to merge
|
53
|
-
context "with no comments" do
|
54
|
-
before {
|
55
|
-
allow(subject).to receive(:has_comments?).and_return(false)
|
56
|
-
allow(subject).to receive(:build_status).and_return('success')
|
57
|
-
allow(subject).to receive(:approvals).and_return(["Simon", "John"])
|
58
|
-
}
|
59
|
-
specify { expect(subject.good_to_merge?).to eq(true) }
|
60
|
-
context "and no approvals" do
|
61
|
-
before { allow(subject).to receive(:approvals).and_return([]) }
|
62
|
-
specify { expect(subject.good_to_merge?).to eq(false) }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "with 1 approval" do
|
67
|
-
before do
|
68
|
-
allow(subject).to receive(:reviewers).and_return(['bob'])
|
69
|
-
allow(subject).to receive(:approvals).and_return(['joe'])
|
70
|
-
end
|
71
|
-
specify { expect(subject.good_to_merge?).to eq(false) }
|
72
|
-
end
|
73
|
-
|
74
|
-
context "with 2 approvals" do
|
75
|
-
before do
|
76
|
-
allow(subject).to receive(:reviewers).and_return(['bob'])
|
77
|
-
allow(subject).to receive(:approvals).and_return(['joe', 'bob'])
|
78
|
-
allow(subject).to receive(:last_comment).and_return('hi')
|
79
|
-
allow(subject).to receive(:build_status).and_return('success')
|
80
|
-
end
|
81
|
-
specify { expect(subject.good_to_merge?).to eq(false) }
|
82
|
-
end
|
83
|
-
|
84
|
-
context "with 2 approvals and last comment LGTM" do
|
85
|
-
before do
|
86
|
-
allow(subject).to receive(:reviewers).and_return(['bob'])
|
87
|
-
allow(subject).to receive(:approvals).and_return(['joe', 'bob'])
|
88
|
-
allow(subject).to receive(:last_comment).and_return('LGTM')
|
89
|
-
end
|
90
|
-
specify { expect(subject.good_to_merge?).to eq(true) }
|
91
|
-
end
|
92
|
-
|
93
|
-
context "with comments" do
|
94
|
-
before do
|
95
|
-
allow(subject).to receive(:reviewers).and_return(['bob'])
|
96
|
-
allow(subject).to receive(:approvals).and_return([])
|
97
|
-
end
|
98
|
-
specify { expect(subject.good_to_merge?).to eq(false) }
|
99
|
-
end
|
100
|
-
|
101
|
-
context "force merge?" do
|
102
|
-
context "with pending comments" do
|
103
|
-
before { allow(subject).to receive(:approvals).and_return([]) }
|
104
|
-
specify { expect(subject.good_to_merge?(force: true)).to eq(true) }
|
105
|
-
end
|
106
|
-
|
107
|
-
context "with build failure" do
|
108
|
-
before { allow(subject).to receive(:build_status).and_return('failure') }
|
109
|
-
specify { expect(subject.good_to_merge?(force: true)).to eq(true) }
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "#approved?" do
|
115
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
|
116
|
-
|
117
|
-
context "no approvals and build success" do
|
118
|
-
before do
|
119
|
-
FakeGitHub.new(
|
120
|
-
repo_owner: 'reenhanced',
|
121
|
-
repo_name: 'repo',
|
122
|
-
pull_request: {
|
123
|
-
number: pull_request.number,
|
124
|
-
owner: pull_request.head.user.login,
|
125
|
-
comments: []
|
126
|
-
})
|
127
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
128
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("0")
|
129
|
-
end
|
130
|
-
specify { expect(subject.approved?).to be_truthy }
|
131
|
-
end
|
132
|
-
|
133
|
-
context "all commenters must approve and minimum_approvals is nil" do
|
134
|
-
before do
|
135
|
-
FakeGitHub.new(
|
136
|
-
repo_owner: 'reenhanced',
|
137
|
-
repo_name: 'repo',
|
138
|
-
pull_request: {
|
139
|
-
number: pull_request.number,
|
140
|
-
owner: pull_request.head.user.login,
|
141
|
-
comments: []
|
142
|
-
})
|
143
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
144
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return(nil)
|
145
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
146
|
-
allow(subject).to receive(:has_comments?).and_return(true)
|
147
|
-
allow(subject).to receive(:reviewers_pending_response).and_return([])
|
148
|
-
end
|
149
|
-
specify { expect(subject.approved?).to be_truthy }
|
150
|
-
end
|
151
|
-
|
152
|
-
context "all commenters must approve but we have no pending reviewers" do
|
153
|
-
before do
|
154
|
-
FakeGitHub.new(
|
155
|
-
repo_owner: 'reenhanced',
|
156
|
-
repo_name: 'repo',
|
157
|
-
pull_request: {
|
158
|
-
number: pull_request.number,
|
159
|
-
owner: pull_request.head.user.login,
|
160
|
-
comments: []
|
161
|
-
})
|
162
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
163
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
|
164
|
-
allow(subject).to receive(:has_comments?).and_return(true)
|
165
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
166
|
-
allow(subject).to receive(:reviewers_pending_response).and_return([])
|
167
|
-
end
|
168
|
-
specify { expect(subject.approved?).to be_truthy }
|
169
|
-
end
|
170
|
-
|
171
|
-
context "all commenters must approve but we have 1 pending reviewer" do
|
172
|
-
before do
|
173
|
-
FakeGitHub.new(
|
174
|
-
repo_owner: 'reenhanced',
|
175
|
-
repo_name: 'repo',
|
176
|
-
pull_request: {
|
177
|
-
number: pull_request.number,
|
178
|
-
owner: pull_request.head.user.login,
|
179
|
-
comments: []
|
180
|
-
})
|
181
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
182
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
|
183
|
-
allow(subject).to receive(:has_comments?).and_return(true)
|
184
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
185
|
-
allow(subject).to receive(:reviewers_pending_response).and_return(["Simon"])
|
186
|
-
end
|
187
|
-
specify { expect(subject.approved?).to be_falsy }
|
188
|
-
end
|
189
|
-
|
190
|
-
context "2 approvals required but we only have 1 approval" do
|
191
|
-
before do
|
192
|
-
FakeGitHub.new(
|
193
|
-
repo_owner: 'reenhanced',
|
194
|
-
repo_name: 'repo',
|
195
|
-
pull_request: {
|
196
|
-
number: pull_request.number,
|
197
|
-
owner: pull_request.head.user.login,
|
198
|
-
comments: []
|
199
|
-
})
|
200
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
201
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
|
202
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
203
|
-
allow(subject).to receive(:last_comment).and_return("LGTM")
|
204
|
-
end
|
205
|
-
specify { expect(subject.approved?).to be_falsy }
|
206
|
-
end
|
207
|
-
|
208
|
-
context "2 approvals required and we have 2 approvals but last comment is not approval" do
|
209
|
-
before do
|
210
|
-
FakeGitHub.new(
|
211
|
-
repo_owner: 'reenhanced',
|
212
|
-
repo_name: 'repo',
|
213
|
-
pull_request: {
|
214
|
-
number: pull_request.number,
|
215
|
-
owner: pull_request.head.user.login,
|
216
|
-
comments: []
|
217
|
-
})
|
218
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
219
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
|
220
|
-
allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
|
221
|
-
allow(subject).to receive(:last_comment).and_return("Boo")
|
222
|
-
end
|
223
|
-
specify { expect(subject.approved?).to be_falsy }
|
224
|
-
end
|
225
|
-
|
226
|
-
context "2 approvals required and we have 2 approvals and last comment is approval" do
|
227
|
-
before do
|
228
|
-
FakeGitHub.new(
|
229
|
-
repo_owner: 'reenhanced',
|
230
|
-
repo_name: 'repo',
|
231
|
-
pull_request: {
|
232
|
-
number: pull_request.number,
|
233
|
-
owner: pull_request.head.user.login,
|
234
|
-
comments: []
|
235
|
-
})
|
236
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
237
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
|
238
|
-
allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
|
239
|
-
allow(subject).to receive(:last_comment).and_return("LGTM")
|
240
|
-
end
|
241
|
-
specify { expect(subject.approved?).to be_truthy }
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
describe "#rejection_message" do
|
246
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
|
247
|
-
|
248
|
-
before do
|
249
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
250
|
-
end
|
251
|
-
|
252
|
-
context "Testing a Failure Build Status" do
|
253
|
-
before do
|
254
|
-
allow(subject).to receive(:build_status).and_return('failure')
|
255
|
-
end
|
256
|
-
|
257
|
-
specify { expect(subject.rejection_message).to eq(": ") }
|
258
|
-
end
|
259
|
-
|
260
|
-
context "Testing Minimum Approvals Failure" do
|
261
|
-
before do
|
262
|
-
allow(subject).to receive(:build_status).and_return('success')
|
263
|
-
allow(subject).to receive(:approval_minimums_reached?).and_return(false)
|
264
|
-
allow(GitReflow::GitServer::PullRequest).to receive(:minimum_approvals).and_return("2")
|
265
|
-
end
|
266
|
-
specify { expect(subject.rejection_message).to eq("You need approval from at least 2 users!") }
|
267
|
-
end
|
268
|
-
|
269
|
-
context "Testing Minimum Approvals Reached" do
|
270
|
-
before do
|
271
|
-
allow(subject).to receive(:build_status).and_return(nil)
|
272
|
-
allow(subject).to receive(:all_comments_addressed?).and_return(false)
|
273
|
-
allow(subject).to receive(:last_comment).and_return("Hello")
|
274
|
-
end
|
275
|
-
specify { expect(subject.rejection_message).to eq("The last comment is holding up approval:\nHello") }
|
276
|
-
end
|
277
|
-
|
278
|
-
context "Testing All Comments Addressed" do
|
279
|
-
before do
|
280
|
-
allow(subject).to receive(:build_status).and_return('success')
|
281
|
-
allow(subject).to receive(:all_comments_addressed?).and_return(false)
|
282
|
-
allow(subject).to receive(:last_comment).and_return("Hello")
|
283
|
-
end
|
284
|
-
specify { expect(subject.rejection_message).to eq("The last comment is holding up approval:\nHello") }
|
285
|
-
end
|
286
|
-
|
287
|
-
context "Testing All Comments Addressed" do
|
288
|
-
before do
|
289
|
-
allow(subject).to receive(:reviewers_pending_response).and_return(['Simon'])
|
290
|
-
allow(subject).to receive(:build?).and_return('success')
|
291
|
-
allow(subject).to receive(:all_comments_addressed?).and_return(true)
|
292
|
-
allow(subject).to receive(:approval_minimums_reached?).and_return(true)
|
293
|
-
end
|
294
|
-
specify { expect(subject.rejection_message).to eq( "You still need a LGTM from: Simon") }
|
295
|
-
end
|
296
|
-
|
297
|
-
context "Testing Last Case" do
|
298
|
-
before do
|
299
|
-
allow(subject).to receive(:reviewers_pending_response).and_return([])
|
300
|
-
allow(subject).to receive(:build?).and_return('success')
|
301
|
-
allow(subject).to receive(:all_comments_addressed?).and_return(true)
|
302
|
-
allow(subject).to receive(:approval_minimums_reached?).and_return(true)
|
303
|
-
end
|
304
|
-
specify { expect(subject.rejection_message).to eq("Your code has not been reviewed yet.") }
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe "#all_comments_addressed" do
|
309
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
|
310
|
-
|
311
|
-
before do
|
312
|
-
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
313
|
-
end
|
314
|
-
|
315
|
-
context "Testing a Failure Case" do
|
316
|
-
before do
|
317
|
-
allow(subject).to receive(:minimum_approvals).and_return('2')
|
318
|
-
allow(subject).to receive(:approvals).and_return(['Simon'])
|
319
|
-
end
|
320
|
-
specify { expect(subject.approval_minimums_reached?).to eq(true) }
|
321
|
-
end
|
322
|
-
|
323
|
-
context "Testing a Success Case" do
|
324
|
-
before do
|
325
|
-
allow(subject).to receive(:minimum_approvals).and_return('2')
|
326
|
-
allow(subject).to receive(:approvals).and_return(['Simon', 'John'])
|
327
|
-
end
|
328
|
-
specify { expect(subject.approval_minimums_reached?).to eq(true) }
|
329
|
-
end
|
330
|
-
|
331
|
-
context "Testing Case with no minimum_approval" do
|
332
|
-
before do
|
333
|
-
allow(subject).to receive(:minimum_approvals).and_return('')
|
334
|
-
allow(subject).to receive(:approvals).and_return([])
|
335
|
-
end
|
336
|
-
specify { expect(subject.approval_minimums_reached?).to eq(true) }
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
describe "#display_pull_request_summary" do
|
341
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request).display_pull_request_summary }
|
342
|
-
|
343
|
-
context "Testing Pull Request Properties" do
|
344
|
-
before do
|
345
|
-
FakeGitHub.new(
|
346
|
-
repo_owner: 'reenhanced',
|
347
|
-
repo_name: 'repo',
|
348
|
-
pull_request: {
|
349
|
-
number: pull_request.number,
|
350
|
-
owner: pull_request.head.user.login,
|
351
|
-
comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
|
352
|
-
})
|
353
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
|
354
|
-
allow(GitReflow.git_server).to receive(:find_open_pull_request).with({from: 'new-external-feature', to: 'master'}).and_return(pull_request)
|
355
|
-
end
|
356
|
-
|
357
|
-
it "displays relavent information about the pull request" do
|
358
|
-
expect{ subject }.to have_output("branches: new-external-feature -> master")
|
359
|
-
expect{ subject }.to have_output("number: #{pull_request.number}")
|
360
|
-
expect{ subject }.to have_output("url: #{pull_request.html_url}")
|
361
|
-
expect{ subject }.to have_output("reviewed by: #{"tito".colorize(:green)}, #{"ringo".colorize(:green)}")
|
362
|
-
expect{ subject }.to have_output("Last comment: \":+1:\"")
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
context "Testing Different LGTM Regex Expressions " do
|
367
|
-
before do
|
368
|
-
FakeGitHub.new(
|
369
|
-
repo_owner: 'reenhanced',
|
370
|
-
repo_name: 'repo',
|
371
|
-
pull_request: {
|
372
|
-
number: pull_request.number,
|
373
|
-
owner: pull_request.head.user.login,
|
374
|
-
comments: [
|
375
|
-
{author: 'tito', body: 'lgtm'},
|
376
|
-
{author: 'ringo', body: ':+1:'},
|
377
|
-
{author: 'Simon', body: ':shipit:'},
|
378
|
-
{author: 'Peter', body: 'looks good to me'},
|
379
|
-
{author: 'Johnny', body: 'LgTm'},
|
380
|
-
{author: 'Jacob', body: 'LOOKS GOOD TO ME'}
|
381
|
-
]
|
382
|
-
})
|
383
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
|
384
|
-
allow(GitReflow.git_server).to receive(:find_open_pull_request).with({from: 'new-external-feature', to: 'master'}).and_return(pull_request)
|
385
|
-
end
|
386
|
-
|
387
|
-
it "displays relavent information about the pull request" do
|
388
|
-
expect{ subject }.to have_output("branches: new-external-feature -> master")
|
389
|
-
expect{ subject }.to have_output("number: #{pull_request.number}")
|
390
|
-
expect{ subject }.to have_output("url: #{pull_request.html_url}")
|
391
|
-
expect{ subject }.to have_output("reviewed by: #{"tito".colorize(:green)}, #{"ringo".colorize(:green)}, #{"Simon".colorize(:green)}, #{"Peter".colorize(:green)}, #{"Johnny".colorize(:green)}, #{"Jacob".colorize(:green)}")
|
392
|
-
expect{ subject }.to have_output("Last comment: \"LOOKS GOOD TO ME\"")
|
393
|
-
end
|
394
|
-
end
|
395
|
-
end
|
396
|
-
|
397
|
-
context ".merge!" do
|
398
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
|
399
|
-
|
400
|
-
let(:inputs) {
|
401
|
-
{
|
402
|
-
:base => "base_branch",
|
403
|
-
:title => "title",
|
404
|
-
:message => "message"
|
405
|
-
}
|
406
|
-
}
|
407
|
-
|
408
|
-
let(:lgtm_comment_authors) {
|
409
|
-
["simonzhu24", "reenhanced"]
|
410
|
-
}
|
411
|
-
|
412
|
-
let(:merge_response) { { :message => "Failure_Message" } }
|
413
|
-
|
414
|
-
context "finds pull request but merge response fails" do
|
415
|
-
before do
|
416
|
-
allow(GitReflow).to receive(:git_server).and_return(git_server)
|
417
|
-
allow(git_server).to receive(:connection).and_return(github)
|
418
|
-
allow(git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :target_url).new())
|
419
|
-
allow(GitReflow::GitServer::GitHub).to receive_message_chain(:connection, :pull_requests, :merge).and_return(merge_response)
|
420
|
-
allow(merge_response).to receive(:success?).and_return(false)
|
421
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:approvals).and_return(lgtm_comment_authors)
|
422
|
-
allow(subject).to receive(:deliver?).and_return(true)
|
423
|
-
allow(merge_response).to receive(:to_s).and_return("Merge failed")
|
424
|
-
end
|
425
|
-
|
426
|
-
it "throws an error" do
|
427
|
-
expect { subject.merge! inputs }.to have_said "Merge failed", :deliver_halted
|
428
|
-
expect { subject.merge! inputs }.to have_said "There were problems commiting your feature... please check the errors above and try again.", :error
|
429
|
-
end
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
context ".commit_message_for_merge" do
|
434
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request) }
|
435
|
-
|
436
|
-
let(:lgtm_comment_authors) {
|
437
|
-
["simonzhu24", "reenhanced"]
|
438
|
-
}
|
439
|
-
|
440
|
-
let(:output) { lgtm_comment_authors.join(', @') }
|
441
|
-
|
442
|
-
context "checks commit message generated is correct" do
|
443
|
-
before do
|
444
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
|
445
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:description).and_return("Description")
|
446
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:number).and_return(1)
|
447
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:approvals).and_return(lgtm_comment_authors)
|
448
|
-
end
|
449
|
-
|
450
|
-
it "throws an exception without message" do
|
451
|
-
expect(subject.commit_message_for_merge).to eq("Description\nMerges #1\n\nLGTM given by: @simonzhu24, @reenhanced\n\n")
|
452
|
-
end
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
context :cleanup_feature_branch? do
|
457
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request).cleanup_feature_branch? }
|
458
|
-
|
459
|
-
before do
|
460
|
-
allow(GitReflow::Config).to receive(:get).with("reflow.always-cleanup").and_return("false")
|
461
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
|
462
|
-
FakeGitHub.new(
|
463
|
-
repo_owner: 'reenhanced',
|
464
|
-
repo_name: 'repo',
|
465
|
-
pull_request: {
|
466
|
-
number: pull_request.number,
|
467
|
-
owner: pull_request.head.user.login,
|
468
|
-
comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
|
469
|
-
})
|
470
|
-
end
|
471
|
-
|
472
|
-
context "doesn't cleanup feature branch" do
|
473
|
-
before do
|
474
|
-
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
475
|
-
values = {
|
476
|
-
"Please enter your GitHub username: " => user,
|
477
|
-
"Please enter your GitHub password (we do NOT store this): " => password,
|
478
|
-
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
479
|
-
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api,
|
480
|
-
"Would you like to push this branch to your remote repo and cleanup your feature branch? " => 'no',
|
481
|
-
"Would you like to open it in your browser?" => 'n',
|
482
|
-
"This is the current status of your Pull Request. Are you sure you want to deliver? " => 'n',
|
483
|
-
"Please enter your delivery commit title: (leaving blank will use default)" => 'title',
|
484
|
-
"Please enter your delivery commit message: (leaving blank will use default)" => 'message'
|
485
|
-
}
|
486
|
-
return_value = values[question] || values[terminal]
|
487
|
-
question = ""
|
488
|
-
return_value
|
489
|
-
end
|
490
|
-
end
|
491
|
-
|
492
|
-
it "doesn't cleans up feature branch" do
|
493
|
-
expect(subject).to be_falsy
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
|
-
context "does cleanup feature branch" do
|
498
|
-
before do
|
499
|
-
stub_command_line_inputs({
|
500
|
-
"Please enter your GitHub username: " => user,
|
501
|
-
"Please enter your GitHub password (we do NOT store this): " => password,
|
502
|
-
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
503
|
-
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api,
|
504
|
-
"Would you like to push this branch to your remote repo and cleanup your feature branch? " => 'yes',
|
505
|
-
"This is the current status of your Pull Request. Are you sure you want to deliver? " => 'n',
|
506
|
-
"Please enter your delivery commit title: (leaving blank will use default)" => 'title',
|
507
|
-
"Please enter your delivery commit message: (leaving blank will use default)" => 'message'
|
508
|
-
})
|
509
|
-
end
|
510
|
-
|
511
|
-
it "cleans up feature branch" do
|
512
|
-
expect(subject).to be_truthy
|
513
|
-
end
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
context :deliver? do
|
518
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(pull_request).deliver? }
|
519
|
-
|
520
|
-
before do
|
521
|
-
allow(GitReflow::Config).to receive(:get).with("reflow.always-deliver").and_return("false")
|
522
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub::PullRequest).to receive(:build).and_return(Struct.new(:state, :description, :url).new)
|
523
|
-
FakeGitHub.new(
|
524
|
-
repo_owner: 'reenhanced',
|
525
|
-
repo_name: 'repo',
|
526
|
-
pull_request: {
|
527
|
-
number: pull_request.number,
|
528
|
-
owner: pull_request.head.user.login,
|
529
|
-
comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
|
530
|
-
})
|
531
|
-
end
|
532
|
-
|
533
|
-
context "doesn't deliver feature branch" do
|
534
|
-
before do
|
535
|
-
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
536
|
-
values = {
|
537
|
-
"Please enter your GitHub username: " => user,
|
538
|
-
"Please enter your GitHub password (we do NOT store this): " => password,
|
539
|
-
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
540
|
-
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api,
|
541
|
-
"Would you like to push this branch to your remote repo and cleanup your feature branch? " => 'no',
|
542
|
-
"Would you like to open it in your browser?" => 'n',
|
543
|
-
"This is the current status of your Pull Request. Are you sure you want to deliver? " => 'n',
|
544
|
-
"Please enter your delivery commit title: (leaving blank will use default)" => 'title',
|
545
|
-
"Please enter your delivery commit message: (leaving blank will use default)" => 'message'
|
546
|
-
}
|
547
|
-
return_value = values[question] || values[terminal]
|
548
|
-
question = ""
|
549
|
-
return_value
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
it "doesn't deliver feature branch" do
|
554
|
-
expect(subject).to be_falsy
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
context "does deliver feature branch" do
|
559
|
-
before do
|
560
|
-
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
561
|
-
values = {
|
562
|
-
"Please enter your GitHub username: " => user,
|
563
|
-
"Please enter your GitHub password (we do NOT store this): " => password,
|
564
|
-
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
565
|
-
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api,
|
566
|
-
"Would you like to push this branch to your remote repo and cleanup your feature branch? " => 'no',
|
567
|
-
"Would you like to open it in your browser?" => 'n',
|
568
|
-
"This is the current status of your Pull Request. Are you sure you want to deliver? " => 'y',
|
569
|
-
"Please enter your delivery commit title: (leaving blank will use default)" => 'title',
|
570
|
-
"Please enter your delivery commit message: (leaving blank will use default)" => 'message'
|
571
|
-
}
|
572
|
-
return_value = values[question] || values[terminal]
|
573
|
-
question = ""
|
574
|
-
return_value
|
575
|
-
end
|
576
|
-
end
|
577
|
-
|
578
|
-
it "does deliver feature branch" do
|
579
|
-
expect(subject).to be_truthy
|
580
|
-
end
|
581
|
-
end
|
582
|
-
end
|
583
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rspec'
|
3
|
-
require 'multi_json'
|
4
|
-
require 'webmock/rspec'
|
5
|
-
require 'pry'
|
6
|
-
|
7
|
-
$LOAD_PATH << 'lib'
|
8
|
-
require 'git_reflow'
|
9
|
-
|
10
|
-
require 'git_reflow/rspec'
|
11
|
-
|
12
|
-
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f}
|
13
|
-
|
14
|
-
RSpec.configure do |config|
|
15
|
-
config.include WebMock::API
|
16
|
-
config.include GitReflow::RSpec::CommandLineHelpers
|
17
|
-
config.include GithubHelpers
|
18
|
-
config.include GitReflow::RSpec::StubHelpers
|
19
|
-
|
20
|
-
config.expect_with :rspec do |c|
|
21
|
-
c.syntax = [:should, :expect]
|
22
|
-
end
|
23
|
-
|
24
|
-
config.mock_with :rspec do |c|
|
25
|
-
c.syntax = [:should, :expect]
|
26
|
-
end
|
27
|
-
|
28
|
-
config.before(:each) do
|
29
|
-
WebMock.reset!
|
30
|
-
stub_command_line
|
31
|
-
allow_message_expectations_on_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
config.after(:each) do
|
35
|
-
WebMock.reset!
|
36
|
-
reset_stubbed_command_line
|
37
|
-
end
|
38
|
-
end
|