git_helper 3.0.1 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +33 -23
- data/Guardfile +2 -2
- data/README.md +26 -13
- data/Rakefile +1 -1
- data/bin/git-helper +12 -16
- data/lib/git_helper.rb +6 -1
- data/lib/git_helper/change_remote.rb +1 -1
- data/lib/git_helper/code_request.rb +6 -5
- data/lib/git_helper/git_config_reader.rb +0 -2
- data/lib/git_helper/gitlab_client.rb +0 -2
- data/lib/git_helper/highline_cli.rb +12 -70
- data/lib/git_helper/local_code.rb +9 -9
- data/lib/git_helper/merge_request.rb +5 -5
- data/lib/git_helper/new_branch.rb +1 -1
- data/lib/git_helper/octokit_client.rb +0 -2
- data/lib/git_helper/pull_request.rb +4 -4
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +19 -16
- data/spec/git_helper/code_request_spec.rb +37 -34
- data/spec/git_helper/git_config_reader_spec.rb +9 -7
- data/spec/git_helper/highline_cli_spec.rb +18 -182
- data/spec/git_helper/local_code_spec.rb +62 -26
- data/spec/git_helper/merge_request_spec.rb +58 -41
- data/spec/git_helper/new_branch_spec.rb +3 -2
- data/spec/git_helper/pull_request_spec.rb +46 -38
- data/spec/spec_helper.rb +2 -0
- metadata +27 -14
@@ -4,11 +4,24 @@ require 'git_helper'
|
|
4
4
|
describe GitHelper::LocalCode do
|
5
5
|
let(:response) { double(:response, readline: true, to_i: 5) }
|
6
6
|
let(:local_codeent) { double(:local_code, ask: response) }
|
7
|
-
let(:
|
8
|
-
let(:
|
9
|
-
let(:
|
10
|
-
let(:
|
7
|
+
let(:project_name) { Faker::Lorem.word }
|
8
|
+
let(:owner) { Faker::Name.first_name }
|
9
|
+
let(:ssh_remote) { "origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)" }
|
10
|
+
let(:https_remote) { "origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)" }
|
11
|
+
|
12
|
+
let(:github_remotes) do
|
13
|
+
[
|
14
|
+
"origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)",
|
15
|
+
"origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)"
|
16
|
+
]
|
17
|
+
end
|
11
18
|
|
19
|
+
let(:gitlab_remotes) do
|
20
|
+
[
|
21
|
+
"origin\tgit@gitlab.com:#{owner}/#{project_name}.git (fetch)",
|
22
|
+
"origin\thttps://gitlab.com/#{owner}/#{project_name}.git (fetch)"
|
23
|
+
]
|
24
|
+
end
|
12
25
|
|
13
26
|
subject { GitHelper::LocalCode.new }
|
14
27
|
|
@@ -51,13 +64,14 @@ describe GitHelper::LocalCode do
|
|
51
64
|
describe '#new_branch' do
|
52
65
|
it 'should make a system call' do
|
53
66
|
expect(subject).to receive(:system).exactly(4).times
|
54
|
-
subject.new_branch(
|
67
|
+
subject.new_branch(Faker::Lorem.word)
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
58
71
|
describe '#change_remote' do
|
59
72
|
it 'should return a string' do
|
60
|
-
|
73
|
+
allow(subject).to receive(:`).and_return(Faker::Lorem.word)
|
74
|
+
expect(subject.change_remote(Faker::Lorem.word, Faker::Internet.url)).to be_a(String)
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
@@ -96,11 +110,11 @@ describe GitHelper::LocalCode do
|
|
96
110
|
|
97
111
|
describe '#remote_project' do
|
98
112
|
it 'should return just the plain project if ssh' do
|
99
|
-
expect(subject.remote_project(ssh_remote)).to eq(
|
113
|
+
expect(subject.remote_project(ssh_remote)).to eq(project_name)
|
100
114
|
end
|
101
115
|
|
102
116
|
it 'should return just the plain project if https' do
|
103
|
-
expect(subject.remote_project(https_remote)).to eq(
|
117
|
+
expect(subject.remote_project(https_remote)).to eq(project_name)
|
104
118
|
end
|
105
119
|
end
|
106
120
|
|
@@ -144,8 +158,8 @@ describe GitHelper::LocalCode do
|
|
144
158
|
end
|
145
159
|
|
146
160
|
it 'should equal this project name' do
|
147
|
-
allow_any_instance_of(String).to receive(:scan).and_return([[
|
148
|
-
expect(subject.project_name).to eq(
|
161
|
+
allow_any_instance_of(String).to receive(:scan).and_return([["#{owner}/#{project_name}"]])
|
162
|
+
expect(subject.project_name).to eq("#{owner}/#{project_name}")
|
149
163
|
end
|
150
164
|
end
|
151
165
|
|
@@ -190,43 +204,65 @@ describe GitHelper::LocalCode do
|
|
190
204
|
|
191
205
|
describe '#generate_title' do
|
192
206
|
it 'should return a title based on the branch' do
|
193
|
-
|
194
|
-
|
207
|
+
prefix = Faker::Lorem.word
|
208
|
+
word1 = Faker::Lorem.word
|
209
|
+
word2 = Faker::Lorem.word
|
210
|
+
description = [word1, word2].join('-')
|
211
|
+
branch = "#{prefix}-123-#{description}"
|
212
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
195
213
|
end
|
196
214
|
|
197
215
|
it 'should return a title based on the branch' do
|
198
|
-
|
199
|
-
|
216
|
+
prefix = Faker::Lorem.word
|
217
|
+
word1 = Faker::Lorem.word
|
218
|
+
word2 = Faker::Lorem.word
|
219
|
+
description = [word1, word2].join('_')
|
220
|
+
branch = "#{prefix}_123_#{description}"
|
221
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
200
222
|
end
|
201
223
|
|
202
224
|
it 'should return a title based on the branch' do
|
203
|
-
|
204
|
-
|
225
|
+
prefix = Faker::Lorem.word
|
226
|
+
word1 = Faker::Lorem.word
|
227
|
+
word2 = Faker::Lorem.word
|
228
|
+
description = [word1, word2].join('_')
|
229
|
+
branch = "#{prefix}-123_#{description}"
|
230
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
205
231
|
end
|
206
232
|
|
207
233
|
it 'should return a title based on the branch' do
|
208
|
-
|
209
|
-
|
234
|
+
word1 = Faker::Lorem.word
|
235
|
+
word2 = Faker::Lorem.word
|
236
|
+
branch = [word1, word2].join('_')
|
237
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
|
210
238
|
end
|
211
239
|
|
212
240
|
it 'should return a title based on the branch' do
|
213
|
-
|
214
|
-
|
241
|
+
word1 = Faker::Lorem.word
|
242
|
+
word2 = Faker::Lorem.word
|
243
|
+
branch = [word1, word2].join('-')
|
244
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
|
215
245
|
end
|
216
246
|
|
217
247
|
it 'should return a title based on the branch' do
|
218
|
-
branch =
|
219
|
-
expect(subject.generate_title(branch)).to eq(
|
248
|
+
branch = Faker::Lorem.word
|
249
|
+
expect(subject.generate_title(branch)).to eq(branch.capitalize)
|
220
250
|
end
|
221
251
|
|
222
252
|
it 'should return a title based on the branch' do
|
223
|
-
|
224
|
-
|
253
|
+
word1 = Faker::Lorem.word
|
254
|
+
word2 = Faker::Lorem.word
|
255
|
+
word3 = Faker::Lorem.word
|
256
|
+
branch = [word1, word2, word3].join('_')
|
257
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
|
225
258
|
end
|
226
259
|
|
227
260
|
it 'should return a title based on the branch' do
|
228
|
-
|
229
|
-
|
261
|
+
word1 = Faker::Lorem.word
|
262
|
+
word2 = Faker::Lorem.word
|
263
|
+
word3 = Faker::Lorem.word
|
264
|
+
branch = [word1, word2, word3].join('-')
|
265
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
|
230
266
|
end
|
231
267
|
end
|
232
268
|
end
|
@@ -2,23 +2,34 @@ require 'spec_helper'
|
|
2
2
|
require 'git_helper'
|
3
3
|
|
4
4
|
describe GitHelper::GitLabMergeRequest do
|
5
|
-
let(:local_code) { double(:local_code, read_template:
|
5
|
+
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
6
6
|
let(:highline_cli) { double(:highline_cli) }
|
7
7
|
let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
8
8
|
let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
|
9
|
+
let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
|
10
|
+
|
11
|
+
let(:merge_request) do
|
12
|
+
double(:merge_request,
|
13
|
+
diff_refs: diff_refs,
|
14
|
+
web_url: Faker::Internet.url,
|
15
|
+
merge_commit_sha: Faker::Internet.password
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
9
19
|
let(:options) do
|
10
20
|
{
|
11
|
-
local_project:
|
12
|
-
local_branch:
|
21
|
+
local_project: Faker::Lorem.word,
|
22
|
+
local_branch: Faker::Lorem.word,
|
13
23
|
local_code: local_code,
|
14
24
|
cli: highline_cli
|
15
25
|
}
|
16
26
|
end
|
17
27
|
|
18
|
-
subject {
|
28
|
+
subject { described_class.new(options) }
|
19
29
|
|
20
30
|
before do
|
21
31
|
allow(GitHelper::GitLabClient).to receive(:new).and_return(gitlab_client)
|
32
|
+
allow(subject).to receive(:puts)
|
22
33
|
end
|
23
34
|
|
24
35
|
describe '#create' do
|
@@ -26,16 +37,16 @@ describe GitHelper::GitLabMergeRequest do
|
|
26
37
|
allow(subject).to receive(:squash_merge_request).and_return(true)
|
27
38
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
28
39
|
allow(subject).to receive(:new_mr_body).and_return('')
|
29
|
-
expect(gitlab_client_client).to receive(:create_merge_request)
|
30
|
-
subject.create({base_branch:
|
40
|
+
expect(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
|
41
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
31
42
|
end
|
32
43
|
|
33
44
|
it 'should call various other methods' do
|
34
45
|
expect(subject).to receive(:squash_merge_request).and_return(true)
|
35
46
|
expect(subject).to receive(:remove_source_branch).and_return(false)
|
36
47
|
expect(subject).to receive(:new_mr_body).and_return('')
|
37
|
-
allow(gitlab_client_client).to receive(:create_merge_request)
|
38
|
-
subject.create({base_branch:
|
48
|
+
allow(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
|
49
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
39
50
|
end
|
40
51
|
|
41
52
|
it 'should catch the raised error if the creation does not work' do
|
@@ -43,36 +54,36 @@ describe GitHelper::GitLabMergeRequest do
|
|
43
54
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
44
55
|
allow(subject).to receive(:new_mr_body).and_return('')
|
45
56
|
allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
|
46
|
-
expect(subject.create({base_branch:
|
57
|
+
expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
|
47
58
|
end
|
48
59
|
end
|
49
60
|
|
50
61
|
describe '#merge' do
|
51
62
|
it 'should call the gitlab client to merge' do
|
52
63
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
53
|
-
allow(subject).to receive(:mr_id).and_return(
|
54
|
-
expect(gitlab_client_client).to receive(:accept_merge_request)
|
64
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
65
|
+
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
|
55
66
|
subject.merge
|
56
67
|
end
|
57
68
|
|
58
69
|
it 'should call various other methods' do
|
59
70
|
expect(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title')).at_least(:once)
|
60
|
-
expect(subject).to receive(:mr_id).and_return(
|
61
|
-
allow(gitlab_client_client).to receive(:accept_merge_request)
|
71
|
+
expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
|
72
|
+
allow(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
|
62
73
|
subject.merge
|
63
74
|
end
|
64
75
|
|
65
76
|
it 'should catch the raised error if the merge does not work' do
|
66
77
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
67
|
-
allow(subject).to receive(:mr_id).and_return(
|
78
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
68
79
|
allow(gitlab_client_client).to receive(:accept_merge_request).and_raise(StandardError)
|
69
80
|
expect(subject.merge).to eq(nil)
|
70
81
|
end
|
71
82
|
|
72
83
|
it 'should try to merge multiple times if the first merge errors' do
|
73
84
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
74
|
-
allow(subject).to receive(:mr_id).and_return(
|
75
|
-
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil)).exactly(2).times
|
85
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
86
|
+
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil, merge_error: Faker::Lorem.word)).exactly(2).times
|
76
87
|
expect(subject.merge).to eq(nil)
|
77
88
|
end
|
78
89
|
end
|
@@ -105,41 +116,46 @@ describe GitHelper::GitLabMergeRequest do
|
|
105
116
|
end
|
106
117
|
|
107
118
|
context 'if there is one template option' do
|
119
|
+
let(:template) { Faker::Lorem.word }
|
120
|
+
|
108
121
|
it 'should call the CLI to ask about a single template' do
|
109
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
110
|
-
expect(highline_cli).to receive(:
|
122
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
123
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
111
124
|
subject.send(:template_name_to_apply)
|
112
125
|
end
|
113
126
|
|
114
127
|
it 'should return the single template if the user says yes' do
|
115
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
116
|
-
allow(highline_cli).to receive(:
|
117
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
128
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
129
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
130
|
+
expect(subject.send(:template_name_to_apply)).to eq(template)
|
118
131
|
end
|
119
132
|
|
120
133
|
it 'should return nil if the user says no' do
|
121
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
122
|
-
allow(highline_cli).to receive(:
|
134
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
135
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
123
136
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
124
137
|
end
|
125
138
|
end
|
126
139
|
|
127
140
|
context 'if there are multiple template options' do
|
141
|
+
let(:template1) { Faker::Lorem.word }
|
142
|
+
let(:template2) { Faker::Lorem.word }
|
143
|
+
|
128
144
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
129
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
130
|
-
expect(highline_cli).to receive(:
|
145
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
146
|
+
expect(highline_cli).to receive(:ask_options).and_return(template1)
|
131
147
|
subject.send(:template_name_to_apply)
|
132
148
|
end
|
133
149
|
|
134
150
|
it 'should return the answer template if the user says yes' do
|
135
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
136
|
-
allow(highline_cli).to receive(:
|
137
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
151
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
152
|
+
allow(highline_cli).to receive(:ask_options).and_return(template1)
|
153
|
+
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
138
154
|
end
|
139
155
|
|
140
156
|
it 'should return nil if the user says no' do
|
141
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
142
|
-
allow(highline_cli).to receive(:
|
157
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
158
|
+
allow(highline_cli).to receive(:ask_options).and_return('None')
|
143
159
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
144
160
|
end
|
145
161
|
end
|
@@ -154,24 +170,25 @@ describe GitHelper::GitLabMergeRequest do
|
|
154
170
|
|
155
171
|
describe '#mr_id' do
|
156
172
|
it 'should ask the CLI for the code request ID' do
|
157
|
-
expect(highline_cli).to receive(:
|
173
|
+
expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
158
174
|
subject.send(:mr_id)
|
159
175
|
end
|
160
176
|
|
161
177
|
it 'should equal an integer' do
|
162
|
-
|
163
|
-
expect(
|
178
|
+
pr_id = Faker::Number.number
|
179
|
+
expect(highline_cli).to receive(:ask).and_return(pr_id)
|
180
|
+
expect(subject.send(:mr_id)).to eq(pr_id)
|
164
181
|
end
|
165
182
|
end
|
166
183
|
|
167
184
|
describe '#squash_merge_request' do
|
168
185
|
it 'should ask the CLI for the code request ID' do
|
169
|
-
expect(highline_cli).to receive(:
|
186
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
170
187
|
subject.send(:squash_merge_request)
|
171
188
|
end
|
172
189
|
|
173
190
|
it 'should be a boolean' do
|
174
|
-
expect(highline_cli).to receive(:
|
191
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(false)
|
175
192
|
expect([true, false]).to include(subject.send(:squash_merge_request))
|
176
193
|
end
|
177
194
|
end
|
@@ -183,12 +200,12 @@ describe GitHelper::GitLabMergeRequest do
|
|
183
200
|
|
184
201
|
context 'when the existing project has no setting' do
|
185
202
|
it 'should ask the CLI for the code request ID' do
|
186
|
-
expect(highline_cli).to receive(:
|
203
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
187
204
|
subject.send(:remove_source_branch)
|
188
205
|
end
|
189
206
|
|
190
207
|
it 'should be a boolean' do
|
191
|
-
allow(highline_cli).to receive(:
|
208
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
192
209
|
expect([true, false]).to include(subject.send(:remove_source_branch))
|
193
210
|
end
|
194
211
|
end
|
@@ -198,14 +215,14 @@ describe GitHelper::GitLabMergeRequest do
|
|
198
215
|
subject.send(:remove_source_branch)
|
199
216
|
end
|
200
217
|
|
201
|
-
it
|
218
|
+
it 'should return the existing projects setting if it exists' do
|
202
219
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: true))
|
203
220
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
204
221
|
end
|
205
222
|
|
206
|
-
it
|
223
|
+
it 'should return the existing projects setting if it exists' do
|
207
224
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
|
208
|
-
allow(highline_cli).to receive(:
|
225
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
209
226
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
210
227
|
end
|
211
228
|
end
|
@@ -219,7 +236,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
219
236
|
|
220
237
|
describe '#existing_mr' do
|
221
238
|
it 'should call the gitlab client' do
|
222
|
-
allow(highline_cli).to receive(:
|
239
|
+
allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
223
240
|
expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
|
224
241
|
subject.send(:existing_mr)
|
225
242
|
end
|
@@ -4,13 +4,14 @@ require 'git_helper'
|
|
4
4
|
describe GitHelper::NewBranch do
|
5
5
|
let(:new_branch_name) { 'new-branch-name' }
|
6
6
|
let(:local_code) { double(:local_code, new_branch: :commit) }
|
7
|
-
let(:cli) { double(:highline_cli,
|
7
|
+
let(:cli) { double(:highline_cli, ask: new_branch_name) }
|
8
8
|
|
9
9
|
subject { GitHelper::NewBranch.new }
|
10
10
|
|
11
11
|
before do
|
12
12
|
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
13
13
|
allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
|
14
|
+
allow(subject).to receive(:puts)
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'should call GitHelper::LocalCode' do
|
@@ -30,7 +31,7 @@ describe GitHelper::NewBranch do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'should ask the highline cli what the new branch name should be' do
|
33
|
-
expect(cli).to receive(:
|
34
|
+
expect(cli).to receive(:ask)
|
34
35
|
subject.execute
|
35
36
|
end
|
36
37
|
end
|
@@ -2,14 +2,15 @@ require 'spec_helper'
|
|
2
2
|
require 'git_helper'
|
3
3
|
|
4
4
|
describe GitHelper::GitHubPullRequest do
|
5
|
-
let(:local_code) { double(:local_code, read_template:
|
5
|
+
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
6
6
|
let(:highline_cli) { double(:highline_cli) }
|
7
7
|
let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
8
8
|
let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
|
9
|
+
|
9
10
|
let(:options) do
|
10
11
|
{
|
11
|
-
local_project:
|
12
|
-
local_branch:
|
12
|
+
local_project: Faker::Lorem.word,
|
13
|
+
local_branch: Faker::Lorem.word,
|
13
14
|
local_code: local_code,
|
14
15
|
cli: highline_cli
|
15
16
|
}
|
@@ -19,49 +20,50 @@ describe GitHelper::GitHubPullRequest do
|
|
19
20
|
|
20
21
|
before do
|
21
22
|
allow(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
|
23
|
+
allow(subject).to receive(:puts)
|
22
24
|
end
|
23
25
|
|
24
26
|
describe '#create' do
|
25
27
|
it 'should call the octokit client to create' do
|
26
28
|
allow(subject).to receive(:new_pr_body).and_return('')
|
27
|
-
expect(octokit_client_client).to receive(:create_pull_request)
|
28
|
-
subject.create({base_branch:
|
29
|
+
expect(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
|
30
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
29
31
|
end
|
30
32
|
|
31
33
|
it 'should call various other methods' do
|
32
34
|
expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
|
33
|
-
allow(octokit_client_client).to receive(:create_pull_request)
|
34
|
-
subject.create({base_branch:
|
35
|
+
allow(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
|
36
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'should catch the raised error if the creation does not work' do
|
38
40
|
allow(subject).to receive(:new_pr_body).and_return('')
|
39
41
|
allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
|
40
|
-
expect(subject.create({base_branch:
|
42
|
+
expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
describe '#merge' do
|
45
47
|
it 'should call the octokit client to merge' do
|
46
|
-
allow(subject).to receive(:existing_pr).and_return(double(title:
|
48
|
+
allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
|
47
49
|
allow(subject).to receive(:merge_method).and_return('rebase')
|
48
|
-
allow(subject).to receive(:pr_id).and_return(
|
49
|
-
expect(octokit_client_client).to receive(:merge_pull_request)
|
50
|
+
allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
|
51
|
+
expect(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
|
50
52
|
subject.merge
|
51
53
|
end
|
52
54
|
|
53
55
|
it 'should call various other methods' do
|
54
|
-
expect(subject).to receive(:existing_pr).and_return(double(title:
|
56
|
+
expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
|
55
57
|
expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
|
56
|
-
expect(subject).to receive(:pr_id).and_return(
|
57
|
-
allow(octokit_client_client).to receive(:merge_pull_request)
|
58
|
+
expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
|
59
|
+
allow(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
|
58
60
|
subject.merge
|
59
61
|
end
|
60
62
|
|
61
63
|
it 'should catch the raised error if the merge does not work' do
|
62
|
-
allow(subject).to receive(:existing_pr).and_return(double(title:
|
64
|
+
allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
|
63
65
|
allow(subject).to receive(:merge_method).and_return('rebase')
|
64
|
-
allow(subject).to receive(:pr_id).and_return(
|
66
|
+
allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
|
65
67
|
allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
|
66
68
|
expect(subject.merge).to eq(nil)
|
67
69
|
end
|
@@ -95,41 +97,46 @@ describe GitHelper::GitHubPullRequest do
|
|
95
97
|
end
|
96
98
|
|
97
99
|
context 'if there is one template option' do
|
100
|
+
let(:template) { Faker::Lorem.word }
|
101
|
+
|
98
102
|
it 'should call the CLI to ask about a single template' do
|
99
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
100
|
-
expect(highline_cli).to receive(:
|
103
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
104
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
101
105
|
subject.send(:template_name_to_apply)
|
102
106
|
end
|
103
107
|
|
104
108
|
it 'should return the single template if the user says yes' do
|
105
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
106
|
-
allow(highline_cli).to receive(:
|
107
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
109
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
110
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
111
|
+
expect(subject.send(:template_name_to_apply)).to eq(template)
|
108
112
|
end
|
109
113
|
|
110
114
|
it 'should return nil if the user says no' do
|
111
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
112
|
-
allow(highline_cli).to receive(:
|
115
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
116
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
113
117
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
117
121
|
context 'if there are multiple template options' do
|
122
|
+
let(:template1) { Faker::Lorem.word }
|
123
|
+
let(:template2) { Faker::Lorem.word }
|
124
|
+
|
118
125
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
119
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
120
|
-
expect(highline_cli).to receive(:
|
126
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
127
|
+
expect(highline_cli).to receive(:ask_options).and_return(template1)
|
121
128
|
subject.send(:template_name_to_apply)
|
122
129
|
end
|
123
130
|
|
124
131
|
it 'should return the answer template if the user says yes' do
|
125
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
126
|
-
allow(highline_cli).to receive(:
|
127
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
132
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
133
|
+
allow(highline_cli).to receive(:ask_options).and_return(template1)
|
134
|
+
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
128
135
|
end
|
129
136
|
|
130
137
|
it 'should return nil if the user says no' do
|
131
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
132
|
-
allow(highline_cli).to receive(:
|
138
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
139
|
+
allow(highline_cli).to receive(:ask_options).and_return('None')
|
133
140
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
134
141
|
end
|
135
142
|
end
|
@@ -144,13 +151,14 @@ describe GitHelper::GitHubPullRequest do
|
|
144
151
|
|
145
152
|
describe '#pr_id' do
|
146
153
|
it 'should ask the CLI for the code request ID' do
|
147
|
-
expect(highline_cli).to receive(:
|
154
|
+
expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
148
155
|
subject.send(:pr_id)
|
149
156
|
end
|
150
157
|
|
151
158
|
it 'should equal an integer' do
|
152
|
-
|
153
|
-
expect(
|
159
|
+
pr_id = Faker::Number.number
|
160
|
+
expect(highline_cli).to receive(:ask).and_return(pr_id)
|
161
|
+
expect(subject.send(:pr_id)).to eq(pr_id)
|
154
162
|
end
|
155
163
|
end
|
156
164
|
|
@@ -159,20 +167,20 @@ describe GitHelper::GitHubPullRequest do
|
|
159
167
|
|
160
168
|
before do
|
161
169
|
allow(subject).to receive(:existing_project).and_return(project)
|
162
|
-
allow(highline_cli).to receive(:
|
170
|
+
allow(highline_cli).to receive(:ask_options)
|
163
171
|
end
|
164
172
|
|
165
173
|
it 'should ask the CLI for the merge_method' do
|
166
|
-
expect(highline_cli).to receive(:
|
174
|
+
expect(highline_cli).to receive(:ask_options).and_return('merge')
|
167
175
|
subject.send(:merge_method)
|
168
176
|
end
|
169
177
|
|
170
178
|
it 'should be a string' do
|
171
|
-
allow(highline_cli).to receive(:
|
179
|
+
allow(highline_cli).to receive(:ask_options).and_return('merge')
|
172
180
|
expect(subject.send(:merge_method)).to be_a(String)
|
173
181
|
end
|
174
182
|
|
175
|
-
context
|
183
|
+
context 'if theres only one item' do
|
176
184
|
let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
|
177
185
|
|
178
186
|
it 'should not ask the CLI anything' do
|
@@ -231,7 +239,7 @@ describe GitHelper::GitHubPullRequest do
|
|
231
239
|
|
232
240
|
describe '#existing_pr' do
|
233
241
|
it 'should call the octokit client' do
|
234
|
-
allow(highline_cli).to receive(:
|
242
|
+
allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
235
243
|
expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
|
236
244
|
subject.send(:existing_pr)
|
237
245
|
end
|