git_helper 3.3.2 → 3.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -5
- data/lib/git_helper.rb +1 -1
- data/lib/git_helper/change_remote.rb +3 -3
- data/lib/git_helper/code_request.rb +8 -8
- data/lib/git_helper/merge_request.rb +7 -7
- data/lib/git_helper/new_branch.rb +1 -1
- data/lib/git_helper/pull_request.rb +6 -6
- data/lib/git_helper/setup.rb +1 -1
- data/lib/git_helper/version.rb +1 -1
- data/spec/git_helper/change_remote_spec.rb +7 -7
- data/spec/git_helper/code_request_spec.rb +28 -28
- data/spec/git_helper/merge_request_spec.rb +16 -16
- data/spec/git_helper/new_branch_spec.rb +8 -8
- data/spec/git_helper/pull_request_spec.rb +15 -15
- data/spec/git_helper/setup_spec.rb +23 -14
- data/spec/spec_helper.rb +1 -0
- metadata +23 -12
- data/lib/git_helper/highline_cli.rb +0 -35
- data/spec/git_helper/highline_cli_spec.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7e2fb7b1199964740a0d73091815fb81469b492a3de04adc16aea30ba794e79
|
4
|
+
data.tar.gz: 80abd21099775a4829c1e72accb74f7f91ae6e9f5e536cfd0468879065de06ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fdabeaa00c72c8f58e00bce3f054949ad1061dbbb132661d06caf788ca827b486d44c20d57213582c2eb7b9c8db28ac88636b5e4562366010c33cc6056c526c
|
7
|
+
data.tar.gz: '08eee4e6e95562f500c93df42f72a713b43ece4d39c96013d5313612f13bf33dc4b7dcd5ca6de243d3bba360af8d8bc183d6c5f2a8600d9692de2afa3bf7c675'
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (3.3.
|
4
|
+
git_helper (3.3.2)
|
5
5
|
gitlab (~> 4.16)
|
6
6
|
gli (~> 2.13)
|
7
|
-
|
7
|
+
highline_wrapper (~> 0.1.0)
|
8
8
|
octokit (~> 4.18)
|
9
9
|
|
10
10
|
GEM
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
gitlab (4.17.0)
|
29
29
|
httparty (~> 0.18)
|
30
30
|
terminal-table (~> 1.5, >= 1.5.1)
|
31
|
-
gli (2.
|
31
|
+
gli (2.20.0)
|
32
32
|
guard (2.16.2)
|
33
33
|
formatador (>= 0.2.4)
|
34
34
|
listen (>= 2.7, < 4.0)
|
@@ -44,6 +44,8 @@ GEM
|
|
44
44
|
guard-compat (~> 1.1)
|
45
45
|
rspec (>= 2.99.0, < 4.0)
|
46
46
|
highline (2.0.3)
|
47
|
+
highline_wrapper (0.1.0)
|
48
|
+
highline (~> 2.0)
|
47
49
|
httparty (0.18.1)
|
48
50
|
mime-types (~> 3.0)
|
49
51
|
multi_xml (>= 0.5.2)
|
@@ -56,7 +58,7 @@ GEM
|
|
56
58
|
method_source (1.0.0)
|
57
59
|
mime-types (3.3.1)
|
58
60
|
mime-types-data (~> 3.2015)
|
59
|
-
mime-types-data (3.
|
61
|
+
mime-types-data (3.2021.0225)
|
60
62
|
multi_xml (0.6.0)
|
61
63
|
multipart-post (2.1.1)
|
62
64
|
nenv (0.3.0)
|
@@ -123,9 +125,10 @@ DEPENDENCIES
|
|
123
125
|
faker (~> 2.15)
|
124
126
|
git_helper!
|
125
127
|
guard-rspec (~> 4.3)
|
128
|
+
pry (~> 0.13)
|
126
129
|
rake (~> 13.0)
|
127
130
|
rspec (~> 3.9)
|
128
|
-
rubocop
|
131
|
+
rubocop (~> 1.10)
|
129
132
|
|
130
133
|
BUNDLED WITH
|
131
134
|
2.2.9
|
data/lib/git_helper.rb
CHANGED
@@ -24,7 +24,7 @@ module GitHelper
|
|
24
24
|
private def process_dir(current_dir, original_dir)
|
25
25
|
Dir.chdir(current_dir)
|
26
26
|
|
27
|
-
if File.exist?('.git') &&
|
27
|
+
if File.exist?('.git') && highline.ask_yes_no(
|
28
28
|
"Found git directory: #{current_dir}. Do you wish to proceed in updating #{current_dir}'s remote URLs? (y/n)"
|
29
29
|
)
|
30
30
|
process_git_repository
|
@@ -69,8 +69,8 @@ module GitHelper
|
|
69
69
|
@local_code ||= GitHelper::LocalCode.new
|
70
70
|
end
|
71
71
|
|
72
|
-
private def
|
73
|
-
@
|
72
|
+
private def highline
|
73
|
+
@highline ||= HighlineWrapper.new
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -29,7 +29,7 @@ module GitHelper
|
|
29
29
|
|
30
30
|
# rubocop:disable Metrics/MethodLength
|
31
31
|
private def ask_for_clarification
|
32
|
-
resp =
|
32
|
+
resp = highline.ask(
|
33
33
|
'Found git remotes for both GitHub and GitLab. Would you like to proceed ' \
|
34
34
|
'with GitLab or GitHub? (github/gitlab)'
|
35
35
|
).downcase
|
@@ -58,7 +58,7 @@ module GitHelper
|
|
58
58
|
local_project: local_project,
|
59
59
|
local_branch: local_branch,
|
60
60
|
local_code: local_code,
|
61
|
-
|
61
|
+
highline: highline
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
@@ -72,10 +72,10 @@ module GitHelper
|
|
72
72
|
|
73
73
|
private def base_branch
|
74
74
|
@base_branch ||=
|
75
|
-
if
|
75
|
+
if highline.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
|
76
76
|
default_branch
|
77
77
|
else
|
78
|
-
|
78
|
+
highline.ask('Base branch?')
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -89,17 +89,17 @@ module GitHelper
|
|
89
89
|
|
90
90
|
private def new_code_request_title
|
91
91
|
@new_code_request_title ||=
|
92
|
-
if autogenerated_title &&
|
92
|
+
if autogenerated_title && highline.ask_yes_no(
|
93
93
|
"Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)"
|
94
94
|
)
|
95
95
|
autogenerated_title
|
96
96
|
else
|
97
|
-
|
97
|
+
highline.ask('Title?')
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
private def
|
102
|
-
@
|
101
|
+
private def highline
|
102
|
+
@highline ||= HighlineWrapper.new
|
103
103
|
end
|
104
104
|
|
105
105
|
private def local_code
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
module GitHelper
|
4
4
|
class GitLabMergeRequest
|
5
|
-
attr_accessor :local_project, :local_branch, :local_code, :
|
5
|
+
attr_accessor :local_project, :local_branch, :local_code, :highline, :base_branch, :new_mr_title
|
6
6
|
|
7
7
|
def initialize(options)
|
8
8
|
@local_project = options[:local_project]
|
9
9
|
@local_branch = options[:local_branch]
|
10
10
|
@local_code = options[:local_code]
|
11
|
-
@
|
11
|
+
@highline = options[:highline]
|
12
12
|
end
|
13
13
|
|
14
14
|
# rubocop:disable Metrics/MethodLength
|
@@ -97,12 +97,12 @@ module GitHelper
|
|
97
97
|
# rubocop:disable Metrics/MethodLength
|
98
98
|
private def determine_template
|
99
99
|
if mr_template_options.count == 1
|
100
|
-
apply_single_template =
|
100
|
+
apply_single_template = highline.ask_yes_no(
|
101
101
|
"Apply the merge request template from #{mr_template_options.first}? (y/n)"
|
102
102
|
)
|
103
103
|
@template_name_to_apply = mr_template_options.first if apply_single_template
|
104
104
|
else
|
105
|
-
response =
|
105
|
+
response = highline.ask_options(
|
106
106
|
'Which merge request template should be applied?', mr_template_options << 'None'
|
107
107
|
)
|
108
108
|
@template_name_to_apply = response unless response == 'None'
|
@@ -121,16 +121,16 @@ module GitHelper
|
|
121
121
|
end
|
122
122
|
|
123
123
|
private def mr_id
|
124
|
-
@mr_id ||=
|
124
|
+
@mr_id ||= highline.ask('Merge Request ID?')
|
125
125
|
end
|
126
126
|
|
127
127
|
private def squash_merge_request
|
128
|
-
@squash_merge_request ||=
|
128
|
+
@squash_merge_request ||= highline.ask_yes_no('Squash merge request? (y/n)')
|
129
129
|
end
|
130
130
|
|
131
131
|
private def remove_source_branch
|
132
132
|
@remove_source_branch ||=
|
133
|
-
existing_project.remove_source_branch_after_merge ||
|
133
|
+
existing_project.remove_source_branch_after_merge || highline.ask_yes_no(
|
134
134
|
'Remove source branch after merging? (y/n)'
|
135
135
|
)
|
136
136
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module GitHelper
|
4
4
|
class NewBranch
|
5
5
|
def execute(new_branch_name = nil)
|
6
|
-
branch_name = new_branch_name ||
|
6
|
+
branch_name = new_branch_name || HighlineWrapper.new.ask('New branch name?')
|
7
7
|
puts "Attempting to create a new branch: #{branch_name}"
|
8
8
|
GitHelper::LocalCode.new.new_branch(branch_name)
|
9
9
|
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
module GitHelper
|
4
4
|
class GitHubPullRequest
|
5
|
-
attr_accessor :local_repo, :local_branch, :local_code, :
|
5
|
+
attr_accessor :local_repo, :local_branch, :local_code, :highline, :base_branch, :new_pr_title
|
6
6
|
|
7
7
|
def initialize(options)
|
8
8
|
@local_repo = options[:local_project]
|
9
9
|
@local_branch = options[:local_branch]
|
10
10
|
@local_code = options[:local_code]
|
11
|
-
@
|
11
|
+
@highline = options[:highline]
|
12
12
|
end
|
13
13
|
|
14
14
|
# rubocop:disable Metrics/MethodLength
|
@@ -102,12 +102,12 @@ module GitHelper
|
|
102
102
|
# rubocop:disable Metrics/MethodLength
|
103
103
|
private def determine_template
|
104
104
|
if pr_template_options.count == 1
|
105
|
-
apply_single_template =
|
105
|
+
apply_single_template = highline.ask_yes_no(
|
106
106
|
"Apply the pull request template from #{pr_template_options.first}? (y/n)"
|
107
107
|
)
|
108
108
|
@template_name_to_apply = pr_template_options.first if apply_single_template
|
109
109
|
else
|
110
|
-
response =
|
110
|
+
response = highline.ask_options(
|
111
111
|
'Which pull request template should be applied?', pr_template_options << 'None'
|
112
112
|
)
|
113
113
|
@template_name_to_apply = response unless response == 'None'
|
@@ -126,7 +126,7 @@ module GitHelper
|
|
126
126
|
end
|
127
127
|
|
128
128
|
private def pr_id
|
129
|
-
@pr_id ||=
|
129
|
+
@pr_id ||= highline.ask('Pull Request ID?')
|
130
130
|
end
|
131
131
|
|
132
132
|
private def merge_method
|
@@ -134,7 +134,7 @@ module GitHelper
|
|
134
134
|
if merge_options.length == 1
|
135
135
|
merge_options.first
|
136
136
|
else
|
137
|
-
|
137
|
+
highline.ask_options('Merge method?', merge_options)
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
data/lib/git_helper/setup.rb
CHANGED
data/lib/git_helper/version.rb
CHANGED
@@ -6,7 +6,7 @@ require 'git_helper'
|
|
6
6
|
describe GitHelper::ChangeRemote do
|
7
7
|
let(:remote1) { "git@github.com:#{old_owner}/#{project}.git" }
|
8
8
|
let(:project) { Faker::Lorem.word }
|
9
|
-
let(:
|
9
|
+
let(:highline_wrapper) { double(:highline_wrapper, ask_yes_no: true) }
|
10
10
|
let(:old_owner) { Faker::Internet.username }
|
11
11
|
let(:new_owner) { Faker::Internet.username }
|
12
12
|
let(:directory_entries) { ['.', '..', project, Faker::Lorem.word, Faker::Lorem.word] }
|
@@ -25,7 +25,7 @@ describe GitHelper::ChangeRemote do
|
|
25
25
|
subject { GitHelper::ChangeRemote.new(old_owner, new_owner) }
|
26
26
|
|
27
27
|
before do
|
28
|
-
allow(
|
28
|
+
allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
29
29
|
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
30
30
|
allow(subject).to receive(:puts)
|
31
31
|
end
|
@@ -74,7 +74,7 @@ describe GitHelper::ChangeRemote do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'when the user says not to process the directory' do
|
77
|
-
let(:
|
77
|
+
let(:highline_wrapper) { double(:highline_wrapper, ask_yes_no: false) }
|
78
78
|
|
79
79
|
it 'should not call to process the directory' do
|
80
80
|
expect(subject).not_to receive(:process_git_repository)
|
@@ -167,10 +167,10 @@ describe GitHelper::ChangeRemote do
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
-
describe '#
|
171
|
-
it 'should create a new
|
172
|
-
expect(
|
173
|
-
subject.send(:
|
170
|
+
describe '#highline' do
|
171
|
+
it 'should create a new highline_wrapper instance' do
|
172
|
+
expect(HighlineWrapper).to receive(:new)
|
173
|
+
subject.send(:highline)
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
require 'git_helper'
|
5
5
|
|
6
6
|
describe GitHelper::CodeRequest do
|
7
|
-
let(:
|
7
|
+
let(:highline_wrapper) { double(:highline_wrapper) }
|
8
8
|
let(:local_code) { double(:local_code, project_name: Faker::Lorem.word, branch: Faker::Lorem.word) }
|
9
9
|
let(:process_project) { double(:process_project, create: :created, merge: :merged) }
|
10
10
|
let(:base_branch) { Faker::Lorem.word }
|
@@ -14,7 +14,7 @@ describe GitHelper::CodeRequest do
|
|
14
14
|
|
15
15
|
before do
|
16
16
|
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
17
|
-
allow(
|
17
|
+
allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
18
18
|
allow(subject).to receive(:puts)
|
19
19
|
end
|
20
20
|
|
@@ -103,19 +103,19 @@ describe GitHelper::CodeRequest do
|
|
103
103
|
|
104
104
|
describe '#ask_for_clarification' do
|
105
105
|
it 'should ask the CLI' do
|
106
|
-
expect(
|
106
|
+
expect(highline_wrapper).to receive(:ask).and_return('github')
|
107
107
|
subject.send(:ask_for_clarification)
|
108
108
|
end
|
109
109
|
|
110
110
|
context 'when response is github' do
|
111
111
|
it 'should return github_pull_request' do
|
112
|
-
allow(
|
112
|
+
allow(highline_wrapper).to receive(:ask).and_return('github')
|
113
113
|
expect(subject).to receive(:github_pull_request)
|
114
114
|
subject.send(:ask_for_clarification)
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'should return github_pull_request' do
|
118
|
-
allow(
|
118
|
+
allow(highline_wrapper).to receive(:ask).and_return('Github')
|
119
119
|
expect(subject).to receive(:github_pull_request)
|
120
120
|
subject.send(:ask_for_clarification)
|
121
121
|
end
|
@@ -123,13 +123,13 @@ describe GitHelper::CodeRequest do
|
|
123
123
|
|
124
124
|
context 'when response is gitlab' do
|
125
125
|
it 'should return gitlab_merge_request' do
|
126
|
-
allow(
|
126
|
+
allow(highline_wrapper).to receive(:ask).and_return('gitlab')
|
127
127
|
expect(subject).to receive(:gitlab_merge_request)
|
128
128
|
subject.send(:ask_for_clarification)
|
129
129
|
end
|
130
130
|
|
131
131
|
it 'should return gitlab_merge_request' do
|
132
|
-
allow(
|
132
|
+
allow(highline_wrapper).to receive(:ask).and_return('Gitlab')
|
133
133
|
expect(subject).to receive(:gitlab_merge_request)
|
134
134
|
subject.send(:ask_for_clarification)
|
135
135
|
end
|
@@ -138,7 +138,7 @@ describe GitHelper::CodeRequest do
|
|
138
138
|
# Unfortunately this test sometimes fails... just rerun the tests if it does
|
139
139
|
context 'when response is neither' do
|
140
140
|
it 'should raise an error' do
|
141
|
-
allow(
|
141
|
+
allow(highline_wrapper).to receive(:ask).and_return(Faker::Lorem.word)
|
142
142
|
expect(subject).to receive(:exit)
|
143
143
|
subject.send(:ask_for_clarification)
|
144
144
|
end
|
@@ -176,23 +176,23 @@ describe GitHelper::CodeRequest do
|
|
176
176
|
describe '#base_branch' do
|
177
177
|
it 'should call the default branch' do
|
178
178
|
expect(subject).to receive(:default_branch)
|
179
|
-
allow(
|
180
|
-
allow(
|
179
|
+
allow(highline_wrapper).to receive(:ask_yes_no).at_least(:once)
|
180
|
+
allow(highline_wrapper).to receive(:ask).at_least(:once).and_return(base_branch)
|
181
181
|
subject.send(:base_branch)
|
182
182
|
end
|
183
183
|
|
184
184
|
it 'should ask the CLI to ask the user' do
|
185
185
|
allow(subject).to receive(:default_branch)
|
186
|
-
expect(
|
187
|
-
allow(
|
186
|
+
expect(highline_wrapper).to receive(:ask_yes_no).at_least(:once)
|
187
|
+
allow(highline_wrapper).to receive(:ask).at_least(:once).and_return(base_branch)
|
188
188
|
subject.send(:base_branch)
|
189
189
|
end
|
190
190
|
|
191
191
|
context 'if the user says no' do
|
192
192
|
it 'definitely asks for the users base branch' do
|
193
193
|
allow(subject).to receive(:default_branch)
|
194
|
-
expect(
|
195
|
-
expect(
|
194
|
+
expect(highline_wrapper).to receive(:ask_yes_no).at_least(:once).and_return(false)
|
195
|
+
expect(highline_wrapper).to receive(:ask).at_least(:once).and_return(base_branch)
|
196
196
|
subject.send(:base_branch)
|
197
197
|
end
|
198
198
|
end
|
@@ -200,8 +200,8 @@ describe GitHelper::CodeRequest do
|
|
200
200
|
context 'if the user says yes' do
|
201
201
|
it 'does not ask for the users base branch' do
|
202
202
|
allow(subject).to receive(:default_branch)
|
203
|
-
expect(
|
204
|
-
expect(
|
203
|
+
expect(highline_wrapper).to receive(:ask_yes_no).at_least(:once).and_return(true)
|
204
|
+
expect(highline_wrapper).not_to receive(:base_branch)
|
205
205
|
subject.send(:base_branch)
|
206
206
|
end
|
207
207
|
end
|
@@ -218,23 +218,23 @@ describe GitHelper::CodeRequest do
|
|
218
218
|
describe '#new_code_request_title' do
|
219
219
|
it 'should call autogenerated title method' do
|
220
220
|
expect(subject).to receive(:autogenerated_title)
|
221
|
-
allow(
|
222
|
-
allow(
|
221
|
+
allow(highline_wrapper).to receive(:ask_yes_no).at_least(:once)
|
222
|
+
allow(highline_wrapper).to receive(:ask).at_least(:once).and_return(title)
|
223
223
|
subject.send(:new_code_request_title)
|
224
224
|
end
|
225
225
|
|
226
226
|
it 'should ask the CLI to ask the user' do
|
227
227
|
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
228
|
-
expect(
|
229
|
-
allow(
|
228
|
+
expect(highline_wrapper).to receive(:ask_yes_no).at_least(:once)
|
229
|
+
allow(highline_wrapper).to receive(:ask).at_least(:once).and_return(title)
|
230
230
|
subject.send(:new_code_request_title)
|
231
231
|
end
|
232
232
|
|
233
233
|
context 'if the user says no' do
|
234
234
|
it 'definitely asks for the users title' do
|
235
235
|
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
236
|
-
expect(
|
237
|
-
expect(
|
236
|
+
expect(highline_wrapper).to receive(:ask_yes_no).at_least(:once).and_return(false)
|
237
|
+
expect(highline_wrapper).to receive(:ask).at_least(:once).and_return(title)
|
238
238
|
subject.send(:new_code_request_title)
|
239
239
|
end
|
240
240
|
end
|
@@ -242,8 +242,8 @@ describe GitHelper::CodeRequest do
|
|
242
242
|
context 'if the user says yes to original title' do
|
243
243
|
it 'does not ask for the users chosen title' do
|
244
244
|
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
245
|
-
expect(
|
246
|
-
expect(
|
245
|
+
expect(highline_wrapper).to receive(:ask_yes_no).at_least(:once).and_return(true)
|
246
|
+
expect(highline_wrapper).not_to receive(:ask)
|
247
247
|
subject.send(:new_code_request_title)
|
248
248
|
end
|
249
249
|
end
|
@@ -256,10 +256,10 @@ describe GitHelper::CodeRequest do
|
|
256
256
|
end
|
257
257
|
end
|
258
258
|
|
259
|
-
describe '#
|
260
|
-
it 'should
|
261
|
-
expect(
|
262
|
-
subject.send(:
|
259
|
+
describe '#highline' do
|
260
|
+
it 'should create a highline_wrapper client' do
|
261
|
+
expect(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
262
|
+
subject.send(:highline)
|
263
263
|
end
|
264
264
|
end
|
265
265
|
end
|
@@ -5,7 +5,7 @@ require 'git_helper'
|
|
5
5
|
|
6
6
|
describe GitHelper::GitLabMergeRequest do
|
7
7
|
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
8
|
-
let(:
|
8
|
+
let(:highline_wrapper) { double(:highline_wrapper) }
|
9
9
|
let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
10
10
|
let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
|
11
11
|
let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
|
@@ -22,7 +22,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
22
22
|
local_project: Faker::Lorem.word,
|
23
23
|
local_branch: Faker::Lorem.word,
|
24
24
|
local_code: local_code,
|
25
|
-
|
25
|
+
highline: highline_wrapper
|
26
26
|
}
|
27
27
|
end
|
28
28
|
|
@@ -121,19 +121,19 @@ describe GitHelper::GitLabMergeRequest do
|
|
121
121
|
|
122
122
|
it 'should call the CLI to ask about a single template' do
|
123
123
|
allow(subject).to receive(:mr_template_options).and_return([template])
|
124
|
-
expect(
|
124
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
125
125
|
subject.send(:template_name_to_apply)
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'should return the single template if the user says yes' do
|
129
129
|
allow(subject).to receive(:mr_template_options).and_return([template])
|
130
|
-
allow(
|
130
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
131
131
|
expect(subject.send(:template_name_to_apply)).to eq(template)
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'should return nil if the user says no' do
|
135
135
|
allow(subject).to receive(:mr_template_options).and_return([template])
|
136
|
-
allow(
|
136
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
137
137
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
138
138
|
end
|
139
139
|
end
|
@@ -144,19 +144,19 @@ describe GitHelper::GitLabMergeRequest do
|
|
144
144
|
|
145
145
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
146
146
|
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
147
|
-
expect(
|
147
|
+
expect(highline_wrapper).to receive(:ask_options).and_return(template1)
|
148
148
|
subject.send(:template_name_to_apply)
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'should return the answer template if the user says yes' do
|
152
152
|
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
153
|
-
allow(
|
153
|
+
allow(highline_wrapper).to receive(:ask_options).and_return(template1)
|
154
154
|
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'should return nil if the user says no' do
|
158
158
|
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
159
|
-
allow(
|
159
|
+
allow(highline_wrapper).to receive(:ask_options).and_return('None')
|
160
160
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
161
161
|
end
|
162
162
|
end
|
@@ -171,25 +171,25 @@ describe GitHelper::GitLabMergeRequest do
|
|
171
171
|
|
172
172
|
describe '#mr_id' do
|
173
173
|
it 'should ask the CLI for the code request ID' do
|
174
|
-
expect(
|
174
|
+
expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
|
175
175
|
subject.send(:mr_id)
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should equal an integer' do
|
179
179
|
pr_id = Faker::Number.number
|
180
|
-
expect(
|
180
|
+
expect(highline_wrapper).to receive(:ask).and_return(pr_id)
|
181
181
|
expect(subject.send(:mr_id)).to eq(pr_id)
|
182
182
|
end
|
183
183
|
end
|
184
184
|
|
185
185
|
describe '#squash_merge_request' do
|
186
186
|
it 'should ask the CLI for the code request ID' do
|
187
|
-
expect(
|
187
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
188
188
|
subject.send(:squash_merge_request)
|
189
189
|
end
|
190
190
|
|
191
191
|
it 'should be a boolean' do
|
192
|
-
expect(
|
192
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
193
193
|
expect([true, false]).to include(subject.send(:squash_merge_request))
|
194
194
|
end
|
195
195
|
end
|
@@ -201,12 +201,12 @@ describe GitHelper::GitLabMergeRequest do
|
|
201
201
|
|
202
202
|
context 'when the existing project has no setting' do
|
203
203
|
it 'should ask the CLI for the code request ID' do
|
204
|
-
expect(
|
204
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
205
205
|
subject.send(:remove_source_branch)
|
206
206
|
end
|
207
207
|
|
208
208
|
it 'should be a boolean' do
|
209
|
-
allow(
|
209
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
210
210
|
expect([true, false]).to include(subject.send(:remove_source_branch))
|
211
211
|
end
|
212
212
|
end
|
@@ -223,7 +223,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
223
223
|
|
224
224
|
it 'should return the existing projects setting if it exists' do
|
225
225
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
|
226
|
-
allow(
|
226
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
227
227
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
228
228
|
end
|
229
229
|
end
|
@@ -237,7 +237,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
237
237
|
|
238
238
|
describe '#existing_mr' do
|
239
239
|
it 'should call the gitlab client' do
|
240
|
-
allow(
|
240
|
+
allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
|
241
241
|
expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
|
242
242
|
subject.send(:existing_mr)
|
243
243
|
end
|
@@ -6,13 +6,13 @@ require 'git_helper'
|
|
6
6
|
describe GitHelper::NewBranch do
|
7
7
|
let(:new_branch_name) { 'new-branch-name' }
|
8
8
|
let(:local_code) { double(:local_code, new_branch: :commit) }
|
9
|
-
let(:
|
9
|
+
let(:highline) { double(:highline_wrapper, ask: new_branch_name) }
|
10
10
|
|
11
11
|
subject { GitHelper::NewBranch.new }
|
12
12
|
|
13
13
|
before do
|
14
14
|
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
15
|
-
allow(
|
15
|
+
allow(HighlineWrapper).to receive(:new).and_return(highline)
|
16
16
|
allow(subject).to receive(:puts)
|
17
17
|
end
|
18
18
|
|
@@ -27,20 +27,20 @@ describe GitHelper::NewBranch do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'when no branch name is passed in' do
|
30
|
-
it 'should call the highline
|
31
|
-
expect(
|
30
|
+
it 'should call the highline client' do
|
31
|
+
expect(HighlineWrapper).to receive(:new).and_return(highline)
|
32
32
|
subject.execute
|
33
33
|
end
|
34
34
|
|
35
|
-
it 'should ask the highline
|
36
|
-
expect(
|
35
|
+
it 'should ask the highline client what the new branch name should be' do
|
36
|
+
expect(highline).to receive(:ask)
|
37
37
|
subject.execute
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
context 'when there is a branch name passed in' do
|
42
|
-
it 'should not create a
|
43
|
-
expect(
|
42
|
+
it 'should not create a highline_wrapper client' do
|
43
|
+
expect(HighlineWrapper).not_to receive(:new)
|
44
44
|
subject.execute(new_branch_name)
|
45
45
|
end
|
46
46
|
end
|
@@ -5,7 +5,7 @@ require 'git_helper'
|
|
5
5
|
|
6
6
|
describe GitHelper::GitHubPullRequest do
|
7
7
|
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
8
|
-
let(:
|
8
|
+
let(:highline_wrapper) { double(:highline_wrapper) }
|
9
9
|
let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
10
10
|
let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
|
11
11
|
|
@@ -14,7 +14,7 @@ describe GitHelper::GitHubPullRequest do
|
|
14
14
|
local_project: Faker::Lorem.word,
|
15
15
|
local_branch: Faker::Lorem.word,
|
16
16
|
local_code: local_code,
|
17
|
-
|
17
|
+
highline: highline_wrapper
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
@@ -103,19 +103,19 @@ describe GitHelper::GitHubPullRequest do
|
|
103
103
|
|
104
104
|
it 'should call the CLI to ask about a single template' do
|
105
105
|
allow(subject).to receive(:pr_template_options).and_return([template])
|
106
|
-
expect(
|
106
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
107
107
|
subject.send(:template_name_to_apply)
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'should return the single template if the user says yes' do
|
111
111
|
allow(subject).to receive(:pr_template_options).and_return([template])
|
112
|
-
allow(
|
112
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
113
113
|
expect(subject.send(:template_name_to_apply)).to eq(template)
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'should return nil if the user says no' do
|
117
117
|
allow(subject).to receive(:pr_template_options).and_return([template])
|
118
|
-
allow(
|
118
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
119
119
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
120
120
|
end
|
121
121
|
end
|
@@ -126,19 +126,19 @@ describe GitHelper::GitHubPullRequest do
|
|
126
126
|
|
127
127
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
128
128
|
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
129
|
-
expect(
|
129
|
+
expect(highline_wrapper).to receive(:ask_options).and_return(template1)
|
130
130
|
subject.send(:template_name_to_apply)
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'should return the answer template if the user says yes' do
|
134
134
|
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
135
|
-
allow(
|
135
|
+
allow(highline_wrapper).to receive(:ask_options).and_return(template1)
|
136
136
|
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'should return nil if the user says no' do
|
140
140
|
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
141
|
-
allow(
|
141
|
+
allow(highline_wrapper).to receive(:ask_options).and_return('None')
|
142
142
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
143
143
|
end
|
144
144
|
end
|
@@ -153,13 +153,13 @@ describe GitHelper::GitHubPullRequest do
|
|
153
153
|
|
154
154
|
describe '#pr_id' do
|
155
155
|
it 'should ask the CLI for the code request ID' do
|
156
|
-
expect(
|
156
|
+
expect(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
|
157
157
|
subject.send(:pr_id)
|
158
158
|
end
|
159
159
|
|
160
160
|
it 'should equal an integer' do
|
161
161
|
pr_id = Faker::Number.number
|
162
|
-
expect(
|
162
|
+
expect(highline_wrapper).to receive(:ask).and_return(pr_id)
|
163
163
|
expect(subject.send(:pr_id)).to eq(pr_id)
|
164
164
|
end
|
165
165
|
end
|
@@ -169,16 +169,16 @@ describe GitHelper::GitHubPullRequest do
|
|
169
169
|
|
170
170
|
before do
|
171
171
|
allow(subject).to receive(:existing_project).and_return(project)
|
172
|
-
allow(
|
172
|
+
allow(highline_wrapper).to receive(:ask_options)
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'should ask the CLI for the merge_method' do
|
176
|
-
expect(
|
176
|
+
expect(highline_wrapper).to receive(:ask_options).and_return('merge')
|
177
177
|
subject.send(:merge_method)
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'should be a string' do
|
181
|
-
allow(
|
181
|
+
allow(highline_wrapper).to receive(:ask_options).and_return('merge')
|
182
182
|
expect(subject.send(:merge_method)).to be_a(String)
|
183
183
|
end
|
184
184
|
|
@@ -186,7 +186,7 @@ describe GitHelper::GitHubPullRequest do
|
|
186
186
|
let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
|
187
187
|
|
188
188
|
it 'should not ask the CLI anything' do
|
189
|
-
expect(
|
189
|
+
expect(highline_wrapper).not_to receive(:merge_method)
|
190
190
|
subject.send(:merge_method)
|
191
191
|
end
|
192
192
|
end
|
@@ -241,7 +241,7 @@ describe GitHelper::GitHubPullRequest do
|
|
241
241
|
|
242
242
|
describe '#existing_pr' do
|
243
243
|
it 'should call the octokit client' do
|
244
|
-
allow(
|
244
|
+
allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
|
245
245
|
expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
|
246
246
|
subject.send(:existing_pr)
|
247
247
|
end
|
@@ -4,11 +4,10 @@ require 'spec_helper'
|
|
4
4
|
require 'git_helper'
|
5
5
|
|
6
6
|
describe GitHelper::Setup do
|
7
|
-
let(:
|
8
|
-
let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
|
7
|
+
let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
|
9
8
|
|
10
9
|
before do
|
11
|
-
allow(
|
10
|
+
allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
12
11
|
allow(subject).to receive(:puts)
|
13
12
|
end
|
14
13
|
|
@@ -17,9 +16,19 @@ describe GitHelper::Setup do
|
|
17
16
|
end
|
18
17
|
|
19
18
|
describe '#execute' do
|
20
|
-
it '
|
19
|
+
it 'only asks the user one question if the config file does not exist' do
|
20
|
+
allow(subject).to receive(:config_file_exists?).and_return(false)
|
21
21
|
allow(File).to receive(:exists?).and_return(true)
|
22
|
-
expect(
|
22
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).exactly(:once)
|
23
|
+
allow(subject).to receive(:create_or_update_config_file).and_return(true)
|
24
|
+
allow(subject).to receive(:create_or_update_plugin_files)
|
25
|
+
subject.execute
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should ask two questions if the config file exists' do
|
29
|
+
allow(subject).to receive(:config_file_exists?).and_return(true)
|
30
|
+
allow(File).to receive(:exists?).and_return(true)
|
31
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true).at_least(:twice)
|
23
32
|
allow(subject).to receive(:create_or_update_config_file).and_return(true)
|
24
33
|
allow(subject).to receive(:create_or_update_plugin_files)
|
25
34
|
subject.execute
|
@@ -27,7 +36,7 @@ describe GitHelper::Setup do
|
|
27
36
|
|
28
37
|
it 'should call to create or update the config file' do
|
29
38
|
allow(File).to receive(:exists?).and_return(true)
|
30
|
-
allow(
|
39
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
31
40
|
expect(subject).to receive(:create_or_update_config_file).and_return(true)
|
32
41
|
allow(subject).to receive(:create_or_update_plugin_files)
|
33
42
|
subject.execute
|
@@ -36,7 +45,7 @@ describe GitHelper::Setup do
|
|
36
45
|
it 'should skip if the user opts not to continue' do
|
37
46
|
allow(File).to receive(:exists?).and_return(true)
|
38
47
|
allow(subject).to receive(:config_file_exists?).and_return(true)
|
39
|
-
allow(
|
48
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
40
49
|
expect(subject).not_to receive(:create_or_update_config_file)
|
41
50
|
expect(subject).not_to receive(:create_or_update_plugin_files)
|
42
51
|
subject.execute
|
@@ -71,43 +80,43 @@ describe GitHelper::Setup do
|
|
71
80
|
|
72
81
|
describe '#ask_question' do
|
73
82
|
it 'should use highline to ask a question' do
|
74
|
-
expect(
|
83
|
+
expect(highline_wrapper).to receive(:ask).and_return(Faker::Lorem.word)
|
75
84
|
subject.send(:ask_question, Faker::Lorem.sentence)
|
76
85
|
end
|
77
86
|
|
78
87
|
it 'should recurse if the highline client gets an empty string' do
|
79
|
-
allow(
|
88
|
+
allow(highline_wrapper).to receive(:ask).and_return('', Faker::Lorem.word)
|
80
89
|
expect(subject).to receive(:ask_question).at_least(:twice).and_call_original
|
81
90
|
subject.send(:ask_question, Faker::Lorem.sentence)
|
82
91
|
end
|
83
92
|
|
84
93
|
it 'should return the answer if it is given' do
|
85
94
|
answer = Faker::Lorem.sentence
|
86
|
-
allow(
|
95
|
+
allow(highline_wrapper).to receive(:ask).and_return(answer)
|
87
96
|
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
|
88
97
|
end
|
89
98
|
end
|
90
99
|
|
91
100
|
describe '#generate_file_contents' do
|
92
101
|
it 'should ask two yes/no questions' do
|
93
|
-
expect(
|
102
|
+
expect(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(false)
|
94
103
|
subject.send(:generate_file_contents)
|
95
104
|
end
|
96
105
|
|
97
106
|
it 'should ask two additional questions for each time the user says yes' do
|
98
|
-
allow(
|
107
|
+
allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
|
99
108
|
expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
|
100
109
|
subject.send(:generate_file_contents)
|
101
110
|
end
|
102
111
|
|
103
112
|
it 'should ask four additional questions for each time the user says yes' do
|
104
|
-
allow(
|
113
|
+
allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
|
105
114
|
expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
|
106
115
|
subject.send(:generate_file_contents)
|
107
116
|
end
|
108
117
|
|
109
118
|
it 'should return a string no matter what' do
|
110
|
-
allow(
|
119
|
+
allow(highline_wrapper).to receive(:ask_yes_no).exactly(2).times.and_return(true)
|
111
120
|
allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
|
112
121
|
expect(subject.send(:generate_file_contents)).to be_a(String)
|
113
122
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emma Sax
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitlab
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: highline_wrapper
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: octokit
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '4.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.13'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.13'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: rake
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,16 +154,16 @@ dependencies:
|
|
140
154
|
name: rubocop
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- - "
|
157
|
+
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
159
|
+
version: '1.10'
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
|
-
- - "
|
164
|
+
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
166
|
+
version: '1.10'
|
153
167
|
description: A set of GitHub and GitLab workflow scripts to provide a smoother development
|
154
168
|
process for your git projects.
|
155
169
|
email:
|
@@ -174,7 +188,6 @@ files:
|
|
174
188
|
- lib/git_helper/forget_local_commits.rb
|
175
189
|
- lib/git_helper/git_config_reader.rb
|
176
190
|
- lib/git_helper/gitlab_client.rb
|
177
|
-
- lib/git_helper/highline_cli.rb
|
178
191
|
- lib/git_helper/local_code.rb
|
179
192
|
- lib/git_helper/merge_request.rb
|
180
193
|
- lib/git_helper/new_branch.rb
|
@@ -191,7 +204,6 @@ files:
|
|
191
204
|
- spec/git_helper/forget_local_commits_spec.rb
|
192
205
|
- spec/git_helper/git_config_reader_spec.rb
|
193
206
|
- spec/git_helper/gitlab_client_spec.rb
|
194
|
-
- spec/git_helper/highline_cli_spec.rb
|
195
207
|
- spec/git_helper/local_code_spec.rb
|
196
208
|
- spec/git_helper/merge_request_spec.rb
|
197
209
|
- spec/git_helper/new_branch_spec.rb
|
@@ -232,7 +244,6 @@ test_files:
|
|
232
244
|
- spec/git_helper/forget_local_commits_spec.rb
|
233
245
|
- spec/git_helper/git_config_reader_spec.rb
|
234
246
|
- spec/git_helper/gitlab_client_spec.rb
|
235
|
-
- spec/git_helper/highline_cli_spec.rb
|
236
247
|
- spec/git_helper/local_code_spec.rb
|
237
248
|
- spec/git_helper/merge_request_spec.rb
|
238
249
|
- spec/git_helper/new_branch_spec.rb
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GitHelper
|
4
|
-
class HighlineCli
|
5
|
-
def ask(prompt)
|
6
|
-
highline_client.ask(prompt) do |conf|
|
7
|
-
conf.readline = true
|
8
|
-
end.to_s
|
9
|
-
end
|
10
|
-
|
11
|
-
def ask_yes_no(prompt)
|
12
|
-
answer = highline_client.ask(prompt) do |conf|
|
13
|
-
conf.readline = true
|
14
|
-
end.to_s
|
15
|
-
|
16
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
17
|
-
end
|
18
|
-
|
19
|
-
def ask_options(prompt, choices)
|
20
|
-
choices_as_string_options = ''.dup
|
21
|
-
choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
|
22
|
-
compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
|
23
|
-
|
24
|
-
index = highline_client.ask(compiled_prompt) do |conf|
|
25
|
-
conf.readline = true
|
26
|
-
end.to_i - 1
|
27
|
-
|
28
|
-
choices[index]
|
29
|
-
end
|
30
|
-
|
31
|
-
private def highline_client
|
32
|
-
@highline_client ||= HighLine.new
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'git_helper'
|
5
|
-
|
6
|
-
describe GitHelper::HighlineCli do
|
7
|
-
let(:response) { double(:response, readline: true, to_i: 3) }
|
8
|
-
let(:highline_client) { double(:highline_cli, ask: response) }
|
9
|
-
|
10
|
-
subject { GitHelper::HighlineCli.new }
|
11
|
-
|
12
|
-
before do
|
13
|
-
allow(HighLine).to receive(:new).and_return(highline_client)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#ask' do
|
17
|
-
it 'should ask the highline client ask' do
|
18
|
-
expect(highline_client).to receive(:ask)
|
19
|
-
subject.ask(Faker::Lorem.sentence)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should return a string' do
|
23
|
-
expect(subject.ask(Faker::Lorem.sentence)).to be_a(String)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#ask_yes_no' do
|
28
|
-
it 'should ask the highline client ask' do
|
29
|
-
expect(highline_client).to receive(:ask)
|
30
|
-
subject.ask_yes_no(Faker::Lorem.sentence)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should return a boolean' do
|
34
|
-
expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_falsey
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should return true if we say yes' do
|
38
|
-
allow(response).to receive(:to_s).and_return('y')
|
39
|
-
expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_truthy
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#ask_options' do
|
44
|
-
it 'should ask the highline client ask' do
|
45
|
-
expect(highline_client).to receive(:ask)
|
46
|
-
subject.ask_options(Faker::Lorem.sentence, %w[one two three])
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should return a string from the options' do
|
50
|
-
expect(subject.ask_options(Faker::Lorem.sentence, %w[one two three])).to be_a(String)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|