git_helper 3.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +2 -2
- data/README.md +31 -16
- data/Rakefile +1 -1
- data/bin/git-helper +12 -16
- data/lib/git_helper.rb +6 -1
- 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 +0 -2
- data/lib/git_helper/local_code.rb +17 -13
- data/lib/git_helper/merge_request.rb +1 -0
- data/lib/git_helper/octokit_client.rb +0 -2
- data/lib/git_helper/pull_request.rb +1 -0
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +18 -15
- data/spec/git_helper/code_request_spec.rb +20 -17
- data/spec/git_helper/git_config_reader_spec.rb +9 -7
- data/spec/git_helper/highline_cli_spec.rb +38 -36
- data/spec/git_helper/local_code_spec.rb +63 -26
- data/spec/git_helper/merge_request_spec.rb +49 -32
- data/spec/git_helper/new_branch_spec.rb +1 -0
- data/spec/git_helper/pull_request_spec.rb +39 -31
- data/spec/spec_helper.rb +2 -0
- metadata +27 -14
- data/Gemfile.lock +0 -101
@@ -2,13 +2,14 @@ require 'spec_helper'
|
|
2
2
|
require 'git_helper'
|
3
3
|
|
4
4
|
describe GitHelper::GitConfigReader do
|
5
|
-
let(:github_token) {
|
6
|
-
let(:gitlab_token) {
|
5
|
+
let(:github_token) { Faker::Internet.password(max_length: 10) }
|
6
|
+
let(:gitlab_token) { Faker::Internet.password(max_length: 10) }
|
7
|
+
|
7
8
|
let(:config_file) {
|
8
9
|
{
|
9
|
-
github_user:
|
10
|
+
github_user: Faker::Internet.username,
|
10
11
|
github_token: github_token,
|
11
|
-
gitlab_user:
|
12
|
+
gitlab_user: Faker::Internet.username,
|
12
13
|
gitlab_token: gitlab_token
|
13
14
|
}
|
14
15
|
}
|
@@ -48,13 +49,14 @@ describe GitHelper::GitConfigReader do
|
|
48
49
|
|
49
50
|
describe '#git_config_file_path' do
|
50
51
|
it 'should look in the current directory' do
|
51
|
-
expect(Dir).to receive(:pwd).and_return(
|
52
|
+
expect(Dir).to receive(:pwd).and_return("/Users/#{Faker::Name.first_name}/#{Faker::Lorem.word}")
|
52
53
|
subject.send(:git_config_file_path)
|
53
54
|
end
|
54
55
|
|
55
56
|
it 'should return the base path with the git config file at the end' do
|
56
|
-
|
57
|
-
|
57
|
+
user = Faker::Name.first_name
|
58
|
+
allow(Dir).to receive(:pwd).and_return("/Users/#{user}/#{Faker::Lorem.word}")
|
59
|
+
expect(subject.send(:git_config_file_path)).to eq("/Users/#{user}/.git_helper/config.yml")
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
@@ -12,7 +12,7 @@ describe GitHelper::HighlineCli do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#new_branch_name' do
|
15
|
-
it
|
15
|
+
it 'should ask the subjects ask method' do
|
16
16
|
expect(subject).to receive(:ask).with('New branch name?')
|
17
17
|
subject.new_branch_name
|
18
18
|
end
|
@@ -23,34 +23,34 @@ describe GitHelper::HighlineCli do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe '#process_directory_remotes' do
|
26
|
-
it
|
26
|
+
it 'should ask the subjects ask method' do
|
27
27
|
expect(subject).to receive(:ask).and_return('y')
|
28
|
-
subject.process_directory_remotes?(
|
28
|
+
subject.process_directory_remotes?(Faker::Lorem.word)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should be a boolean at the end' do
|
32
32
|
allow(subject).to receive(:ask).and_return('y')
|
33
|
-
expect([true, false]).to include(subject.process_directory_remotes?(
|
33
|
+
expect([true, false]).to include(subject.process_directory_remotes?(Faker::Lorem.word))
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should come out as a true boolean if somebody responds y' do
|
37
37
|
allow(subject).to receive(:ask).and_return('y')
|
38
|
-
expect(subject.process_directory_remotes?(
|
38
|
+
expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(true)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should come out as a false boolean if somebody responds n' do
|
42
42
|
allow(subject).to receive(:ask).and_return('n')
|
43
|
-
expect(subject.process_directory_remotes?(
|
43
|
+
expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(false)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'should come out as true if somebody presses enter' do
|
47
47
|
allow(subject).to receive(:ask).and_return('')
|
48
|
-
expect(subject.accept_autogenerated_title?(
|
48
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.word)).to eq(true)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe '#conflicting_remote_clarification' do
|
53
|
-
it
|
53
|
+
it 'should ask the subjects ask method' do
|
54
54
|
expect(subject).to receive(:ask).with('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').and_return('gitlab')
|
55
55
|
subject.conflicting_remote_clarification
|
56
56
|
end
|
@@ -61,7 +61,7 @@ describe GitHelper::HighlineCli do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '#title' do
|
64
|
-
it
|
64
|
+
it 'should ask the subjects ask method' do
|
65
65
|
expect(subject).to receive(:ask).with('Title?')
|
66
66
|
subject.title
|
67
67
|
end
|
@@ -72,7 +72,7 @@ describe GitHelper::HighlineCli do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
describe '#base_branch' do
|
75
|
-
it
|
75
|
+
it 'should ask the subjects ask method' do
|
76
76
|
expect(subject).to receive(:ask).with('Base branch?')
|
77
77
|
subject.base_branch
|
78
78
|
end
|
@@ -83,92 +83,94 @@ describe GitHelper::HighlineCli do
|
|
83
83
|
end
|
84
84
|
|
85
85
|
describe '#code_request_id' do
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
let(:phrase) { Faker::Lorem.sentence }
|
87
|
+
|
88
|
+
it 'should ask the subjects ask method' do
|
89
|
+
expect(subject).to receive(:ask).with("#{phrase} Request ID?")
|
90
|
+
subject.code_request_id(phrase)
|
89
91
|
end
|
90
92
|
|
91
93
|
it 'should come out a string' do
|
92
|
-
expect(subject.code_request_id(
|
94
|
+
expect(subject.code_request_id(phrase)).to be_a(String)
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
98
|
describe '#accept_autogenerated_title' do
|
97
|
-
it
|
99
|
+
it 'should ask the subjects ask method' do
|
98
100
|
expect(subject).to receive(:ask).and_return('y')
|
99
|
-
subject.accept_autogenerated_title?(
|
101
|
+
subject.accept_autogenerated_title?(Faker::Lorem.sentence)
|
100
102
|
end
|
101
103
|
|
102
104
|
it 'should be a boolean at the end' do
|
103
105
|
allow(subject).to receive(:ask).and_return('y')
|
104
|
-
expect([true, false]).to include(subject.accept_autogenerated_title?(
|
106
|
+
expect([true, false]).to include(subject.accept_autogenerated_title?(Faker::Lorem.sentence))
|
105
107
|
end
|
106
108
|
|
107
109
|
it 'should come out as a true boolean if somebody responds y' do
|
108
110
|
allow(subject).to receive(:ask).and_return('y')
|
109
|
-
expect(subject.accept_autogenerated_title?(
|
111
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
110
112
|
end
|
111
113
|
|
112
114
|
it 'should come out as a true boolean if somebody responds n' do
|
113
115
|
allow(subject).to receive(:ask).and_return('n')
|
114
|
-
expect(subject.accept_autogenerated_title?(
|
116
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
|
115
117
|
end
|
116
118
|
|
117
119
|
it 'should come out as a true boolean if somebody responds yes' do
|
118
120
|
allow(subject).to receive(:ask).and_return('yes')
|
119
|
-
expect(subject.accept_autogenerated_title?(
|
121
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
120
122
|
end
|
121
123
|
|
122
124
|
it 'should come out as a false boolean if somebody responds no' do
|
123
125
|
allow(subject).to receive(:ask).and_return('no')
|
124
|
-
expect(subject.accept_autogenerated_title?(
|
126
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
|
125
127
|
end
|
126
128
|
|
127
129
|
it 'should come out as true if somebody presses enter' do
|
128
130
|
allow(subject).to receive(:ask).and_return('')
|
129
|
-
expect(subject.accept_autogenerated_title?(
|
131
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
133
135
|
describe '#base_branch_default' do
|
134
|
-
it
|
136
|
+
it 'should ask the subjects ask method' do
|
135
137
|
expect(subject).to receive(:ask).and_return('y')
|
136
|
-
subject.base_branch_default?(
|
138
|
+
subject.base_branch_default?(Faker::Lorem.word)
|
137
139
|
end
|
138
140
|
|
139
141
|
it 'should be a boolean at the end' do
|
140
142
|
allow(subject).to receive(:ask).and_return('y')
|
141
|
-
expect([true, false]).to include(subject.base_branch_default?(
|
143
|
+
expect([true, false]).to include(subject.base_branch_default?(Faker::Lorem.word))
|
142
144
|
end
|
143
145
|
|
144
146
|
it 'should come out as a true boolean if somebody responds y' do
|
145
147
|
allow(subject).to receive(:ask).and_return('y')
|
146
|
-
expect(subject.base_branch_default?(
|
148
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
147
149
|
end
|
148
150
|
|
149
151
|
it 'should come out as a true boolean if somebody responds n' do
|
150
152
|
allow(subject).to receive(:ask).and_return('n')
|
151
|
-
expect(subject.base_branch_default?(
|
153
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
|
152
154
|
end
|
153
155
|
|
154
156
|
it 'should come out as a true boolean if somebody responds yes' do
|
155
157
|
allow(subject).to receive(:ask).and_return('yes')
|
156
|
-
expect(subject.base_branch_default?(
|
158
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
157
159
|
end
|
158
160
|
|
159
161
|
it 'should come out as a false boolean if somebody responds no' do
|
160
162
|
allow(subject).to receive(:ask).and_return('no')
|
161
|
-
expect(subject.base_branch_default?(
|
163
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
|
162
164
|
end
|
163
165
|
|
164
166
|
it 'should come out as true if somebody presses enter' do
|
165
167
|
allow(subject).to receive(:ask).and_return('')
|
166
|
-
expect(subject.base_branch_default?(
|
168
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
167
169
|
end
|
168
170
|
end
|
169
171
|
|
170
172
|
describe '#merge_method' do
|
171
|
-
it
|
173
|
+
it 'should ask the subjects ask_options method' do
|
172
174
|
expect(subject).to receive(:ask_options).and_return(3)
|
173
175
|
subject.merge_method(['1', '2', '3'])
|
174
176
|
end
|
@@ -180,7 +182,7 @@ describe GitHelper::HighlineCli do
|
|
180
182
|
end
|
181
183
|
|
182
184
|
describe '#template_to_apply' do
|
183
|
-
it
|
185
|
+
it 'should ask the subjects ask_options method' do
|
184
186
|
expect(subject).to receive(:ask_options).and_return(3)
|
185
187
|
subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')
|
186
188
|
end
|
@@ -194,22 +196,22 @@ describe GitHelper::HighlineCli do
|
|
194
196
|
describe '#ask' do
|
195
197
|
it 'should ask the highline client ask'do
|
196
198
|
expect(highline_client).to receive(:ask)
|
197
|
-
subject.send(:ask,
|
199
|
+
subject.send(:ask, Faker::Lorem.sentence)
|
198
200
|
end
|
199
201
|
|
200
202
|
it 'should return a string' do
|
201
|
-
expect(subject.send(:ask,
|
203
|
+
expect(subject.send(:ask, Faker::Lorem.sentence)).to be_a(String)
|
202
204
|
end
|
203
205
|
end
|
204
206
|
|
205
207
|
describe '#ask_options' do
|
206
208
|
it 'should ask the highline client ask'do
|
207
209
|
expect(highline_client).to receive(:ask)
|
208
|
-
subject.send(:ask_options,
|
210
|
+
subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])
|
209
211
|
end
|
210
212
|
|
211
213
|
it 'should return an integer' do
|
212
|
-
expect(subject.send(:ask_options,
|
214
|
+
expect(subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])).to be_a(Integer)
|
213
215
|
end
|
214
216
|
end
|
215
217
|
end
|
@@ -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
|
|
@@ -164,6 +178,7 @@ describe GitHelper::LocalCode do
|
|
164
178
|
describe '#template_options' do
|
165
179
|
let(:template_identifiers) do
|
166
180
|
{
|
181
|
+
template_directory: '.github',
|
167
182
|
nested_directory_name: 'PULL_REQUEST_TEMPLATE',
|
168
183
|
non_nested_file_name: 'pull_request_template'
|
169
184
|
}
|
@@ -189,43 +204,65 @@ describe GitHelper::LocalCode do
|
|
189
204
|
|
190
205
|
describe '#generate_title' do
|
191
206
|
it 'should return a title based on the branch' do
|
192
|
-
|
193
|
-
|
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(' ')}")
|
194
213
|
end
|
195
214
|
|
196
215
|
it 'should return a title based on the branch' do
|
197
|
-
|
198
|
-
|
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(' ')}")
|
199
222
|
end
|
200
223
|
|
201
224
|
it 'should return a title based on the branch' do
|
202
|
-
|
203
|
-
|
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(' ')}")
|
204
231
|
end
|
205
232
|
|
206
233
|
it 'should return a title based on the branch' do
|
207
|
-
|
208
|
-
|
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(' '))
|
209
238
|
end
|
210
239
|
|
211
240
|
it 'should return a title based on the branch' do
|
212
|
-
|
213
|
-
|
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(' '))
|
214
245
|
end
|
215
246
|
|
216
247
|
it 'should return a title based on the branch' do
|
217
|
-
branch =
|
218
|
-
expect(subject.generate_title(branch)).to eq(
|
248
|
+
branch = Faker::Lorem.word
|
249
|
+
expect(subject.generate_title(branch)).to eq(branch.capitalize)
|
219
250
|
end
|
220
251
|
|
221
252
|
it 'should return a title based on the branch' do
|
222
|
-
|
223
|
-
|
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(' '))
|
224
258
|
end
|
225
259
|
|
226
260
|
it 'should return a title based on the branch' do
|
227
|
-
|
228
|
-
|
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(' '))
|
229
266
|
end
|
230
267
|
end
|
231
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,40 +116,45 @@ 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([
|
122
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
110
123
|
expect(highline_cli).to receive(:apply_template?).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([
|
128
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
116
129
|
allow(highline_cli).to receive(:apply_template?).and_return(true)
|
117
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
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([
|
134
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
122
135
|
allow(highline_cli).to receive(:apply_template?).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(:template_to_apply).and_return(
|
145
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
146
|
+
expect(highline_cli).to receive(:template_to_apply).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(:template_to_apply).and_return(
|
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(:template_to_apply).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([
|
157
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
142
158
|
allow(highline_cli).to receive(:template_to_apply).and_return('None')
|
143
159
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
144
160
|
end
|
@@ -154,13 +170,14 @@ 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(:code_request_id).and_return(
|
173
|
+
expect(highline_cli).to receive(:code_request_id).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(:code_request_id).and_return(pr_id)
|
180
|
+
expect(subject.send(:mr_id)).to eq(pr_id)
|
164
181
|
end
|
165
182
|
end
|
166
183
|
|
@@ -198,12 +215,12 @@ 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
225
|
allow(highline_cli).to receive(:remove_source_branch?).and_return(true)
|
209
226
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
@@ -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(:code_request_id).and_return(
|
239
|
+
allow(highline_cli).to receive(:code_request_id).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
|