git_helper 3.2.0 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +131 -0
  4. data/Guardfile +3 -1
  5. data/README.md +11 -6
  6. data/Rakefile +2 -0
  7. data/bin/git-helper +25 -13
  8. data/lib/git_helper.rb +5 -1
  9. data/lib/git_helper/change_remote.rb +11 -3
  10. data/lib/git_helper/checkout_default.rb +2 -0
  11. data/lib/git_helper/clean_branches.rb +2 -0
  12. data/lib/git_helper/code_request.rb +29 -15
  13. data/lib/git_helper/empty_commit.rb +2 -0
  14. data/lib/git_helper/forget_local_commits.rb +2 -0
  15. data/lib/git_helper/git_config_reader.rb +12 -6
  16. data/lib/git_helper/gitlab_client.rb +2 -0
  17. data/lib/git_helper/highline_cli.rb +15 -69
  18. data/lib/git_helper/local_code.rb +18 -8
  19. data/lib/git_helper/merge_request.rb +88 -68
  20. data/lib/git_helper/new_branch.rb +3 -1
  21. data/lib/git_helper/octokit_client.rb +2 -0
  22. data/lib/git_helper/pull_request.rb +95 -64
  23. data/lib/git_helper/setup.rb +116 -0
  24. data/lib/git_helper/version.rb +3 -1
  25. data/spec/git_helper/change_remote_spec.rb +19 -19
  26. data/spec/git_helper/checkout_default_spec.rb +2 -0
  27. data/spec/git_helper/clean_branches_spec.rb +2 -0
  28. data/spec/git_helper/code_request_spec.rb +27 -24
  29. data/spec/git_helper/empty_commit_spec.rb +2 -0
  30. data/spec/git_helper/forget_local_commits_spec.rb +2 -0
  31. data/spec/git_helper/git_config_reader_spec.rb +32 -4
  32. data/spec/git_helper/gitlab_client_spec.rb +2 -0
  33. data/spec/git_helper/highline_cli_spec.rb +21 -185
  34. data/spec/git_helper/local_code_spec.rb +2 -0
  35. data/spec/git_helper/merge_request_spec.rb +22 -21
  36. data/spec/git_helper/new_branch_spec.rb +4 -2
  37. data/spec/git_helper/octokit_client_spec.rb +2 -0
  38. data/spec/git_helper/pull_request_spec.rb +17 -15
  39. data/spec/git_helper/setup_spec.rb +180 -0
  40. data/spec/spec_helper.rb +3 -1
  41. metadata +22 -5
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,18 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
4
6
  describe GitHelper::GitConfigReader do
7
+ let(:github_user) { Faker::Internet.username }
5
8
  let(:github_token) { Faker::Internet.password(max_length: 10) }
9
+ let(:gitlab_user) { Faker::Internet.username }
6
10
  let(:gitlab_token) { Faker::Internet.password(max_length: 10) }
7
11
 
8
- let(:config_file) {
12
+ let(:config_file) do
9
13
  {
10
- github_user: Faker::Internet.username,
14
+ github_user: github_user,
11
15
  github_token: github_token,
12
- gitlab_user: Faker::Internet.username,
16
+ gitlab_user: gitlab_user,
13
17
  gitlab_token: gitlab_token
14
18
  }
15
- }
19
+ end
16
20
 
17
21
  subject { GitHelper::GitConfigReader.new }
18
22
 
@@ -40,6 +44,30 @@ describe GitHelper::GitConfigReader do
40
44
  end
41
45
  end
42
46
 
47
+ describe '#github_user' do
48
+ it 'should locate the github_user' do
49
+ expect(subject).to receive(:config_file).and_return(config_file)
50
+ expect(subject.github_user).to eq(github_user)
51
+ end
52
+
53
+ it 'should call the config file' do
54
+ expect(subject).to receive(:config_file).and_return(config_file)
55
+ subject.github_user
56
+ end
57
+ end
58
+
59
+ describe '#gitlab_user' do
60
+ it 'should locate the gitlab_user' do
61
+ expect(subject).to receive(:config_file).and_return(config_file)
62
+ expect(subject.gitlab_user).to eq(gitlab_user)
63
+ end
64
+
65
+ it 'should call the config file' do
66
+ expect(subject).to receive(:config_file).and_return(config_file)
67
+ subject.gitlab_user
68
+ end
69
+ end
70
+
43
71
  describe '#config_file' do
44
72
  it 'should yaml load the file path' do
45
73
  expect(YAML).to receive(:load_file)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
4
6
  describe GitHelper::HighlineCli do
5
- let(:response) { double(:response, readline: true, to_i: 5) }
7
+ let(:response) { double(:response, readline: true, to_i: 3) }
6
8
  let(:highline_client) { double(:highline_cli, ask: response) }
7
9
 
8
10
  subject { GitHelper::HighlineCli.new }
@@ -11,207 +13,41 @@ describe GitHelper::HighlineCli do
11
13
  allow(HighLine).to receive(:new).and_return(highline_client)
12
14
  end
13
15
 
14
- describe '#new_branch_name' do
15
- it 'should ask the subjects ask method' do
16
- expect(subject).to receive(:ask).with('New branch name?')
17
- subject.new_branch_name
18
- end
19
-
20
- it 'should come out a string' do
21
- expect(subject.new_branch_name).to be_a(String)
22
- end
23
- end
24
-
25
- describe '#process_directory_remotes' do
26
- it 'should ask the subjects ask method' do
27
- expect(subject).to receive(:ask).and_return('y')
28
- subject.process_directory_remotes?(Faker::Lorem.word)
29
- end
30
-
31
- it 'should be a boolean at the end' do
32
- allow(subject).to receive(:ask).and_return('y')
33
- expect([true, false]).to include(subject.process_directory_remotes?(Faker::Lorem.word))
34
- end
35
-
36
- it 'should come out as a true boolean if somebody responds y' do
37
- allow(subject).to receive(:ask).and_return('y')
38
- expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(true)
39
- end
40
-
41
- it 'should come out as a false boolean if somebody responds n' do
42
- allow(subject).to receive(:ask).and_return('n')
43
- expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(false)
44
- end
45
-
46
- it 'should come out as true if somebody presses enter' do
47
- allow(subject).to receive(:ask).and_return('')
48
- expect(subject.accept_autogenerated_title?(Faker::Lorem.word)).to eq(true)
49
- end
50
- end
51
-
52
- describe '#conflicting_remote_clarification' do
53
- it 'should ask the subjects ask method' do
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
- subject.conflicting_remote_clarification
56
- end
57
-
58
- it 'should come out a string' do
59
- expect(subject.conflicting_remote_clarification).to be_a(String)
60
- end
61
- end
62
-
63
- describe '#title' do
64
- it 'should ask the subjects ask method' do
65
- expect(subject).to receive(:ask).with('Title?')
66
- subject.title
67
- end
68
-
69
- it 'should come out a string' do
70
- expect(subject.title).to be_a(String)
71
- end
72
- end
73
-
74
- describe '#base_branch' do
75
- it 'should ask the subjects ask method' do
76
- expect(subject).to receive(:ask).with('Base branch?')
77
- subject.base_branch
78
- end
79
-
80
- it 'should come out a string' do
81
- expect(subject.base_branch).to be_a(String)
82
- end
83
- end
84
-
85
- describe '#code_request_id' do
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)
91
- end
92
-
93
- it 'should come out a string' do
94
- expect(subject.code_request_id(phrase)).to be_a(String)
95
- end
96
- end
97
-
98
- describe '#accept_autogenerated_title' do
99
- it 'should ask the subjects ask method' do
100
- expect(subject).to receive(:ask).and_return('y')
101
- subject.accept_autogenerated_title?(Faker::Lorem.sentence)
102
- end
103
-
104
- it 'should be a boolean at the end' do
105
- allow(subject).to receive(:ask).and_return('y')
106
- expect([true, false]).to include(subject.accept_autogenerated_title?(Faker::Lorem.sentence))
107
- end
108
-
109
- it 'should come out as a true boolean if somebody responds y' do
110
- allow(subject).to receive(:ask).and_return('y')
111
- expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
112
- end
113
-
114
- it 'should come out as a true boolean if somebody responds n' do
115
- allow(subject).to receive(:ask).and_return('n')
116
- expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
117
- end
118
-
119
- it 'should come out as a true boolean if somebody responds yes' do
120
- allow(subject).to receive(:ask).and_return('yes')
121
- expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
122
- end
123
-
124
- it 'should come out as a false boolean if somebody responds no' do
125
- allow(subject).to receive(:ask).and_return('no')
126
- expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
127
- end
128
-
129
- it 'should come out as true if somebody presses enter' do
130
- allow(subject).to receive(:ask).and_return('')
131
- expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
132
- end
133
- end
134
-
135
- describe '#base_branch_default' do
136
- it 'should ask the subjects ask method' do
137
- expect(subject).to receive(:ask).and_return('y')
138
- subject.base_branch_default?(Faker::Lorem.word)
139
- end
140
-
141
- it 'should be a boolean at the end' do
142
- allow(subject).to receive(:ask).and_return('y')
143
- expect([true, false]).to include(subject.base_branch_default?(Faker::Lorem.word))
144
- end
145
-
146
- it 'should come out as a true boolean if somebody responds y' do
147
- allow(subject).to receive(:ask).and_return('y')
148
- expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
149
- end
150
-
151
- it 'should come out as a true boolean if somebody responds n' do
152
- allow(subject).to receive(:ask).and_return('n')
153
- expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
154
- end
155
-
156
- it 'should come out as a true boolean if somebody responds yes' do
157
- allow(subject).to receive(:ask).and_return('yes')
158
- expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
159
- end
160
-
161
- it 'should come out as a false boolean if somebody responds no' do
162
- allow(subject).to receive(:ask).and_return('no')
163
- expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
164
- end
165
-
166
- it 'should come out as true if somebody presses enter' do
167
- allow(subject).to receive(:ask).and_return('')
168
- expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
169
- end
170
- end
171
-
172
- describe '#merge_method' do
173
- it 'should ask the subjects ask_options method' do
174
- expect(subject).to receive(:ask_options).and_return(3)
175
- subject.merge_method(['1', '2', '3'])
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)
176
20
  end
177
21
 
178
22
  it 'should return a string' do
179
- allow(subject).to receive(:ask_options).and_return(2)
180
- expect(subject.merge_method(['1', '2', '3'])).to be_a(String)
23
+ expect(subject.ask(Faker::Lorem.sentence)).to be_a(String)
181
24
  end
182
25
  end
183
26
 
184
- describe '#template_to_apply' do
185
- it 'should ask the subjects ask_options method' do
186
- expect(subject).to receive(:ask_options).and_return(3)
187
- subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')
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)
188
31
  end
189
32
 
190
- it 'should return a string' do
191
- allow(subject).to receive(:ask_options).and_return(3)
192
- expect(subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')).to eq('None')
33
+ it 'should return a boolean' do
34
+ expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_falsey
193
35
  end
194
- end
195
36
 
196
- describe '#ask' do
197
- it 'should ask the highline client ask'do
198
- expect(highline_client).to receive(:ask)
199
- subject.send(:ask, Faker::Lorem.sentence)
200
- end
201
-
202
- it 'should return a string' do
203
- expect(subject.send(:ask, Faker::Lorem.sentence)).to be_a(String)
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
204
40
  end
205
41
  end
206
42
 
207
43
  describe '#ask_options' do
208
- it 'should ask the highline client ask'do
44
+ it 'should ask the highline client ask' do
209
45
  expect(highline_client).to receive(:ask)
210
- subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])
46
+ subject.ask_options(Faker::Lorem.sentence, %w[one two three])
211
47
  end
212
48
 
213
- it 'should return an integer' do
214
- expect(subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])).to be_a(Integer)
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)
215
51
  end
216
52
  end
217
53
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
  require 'git_helper'
3
5
 
@@ -10,10 +12,9 @@ describe GitHelper::GitLabMergeRequest do
10
12
 
11
13
  let(:merge_request) do
12
14
  double(:merge_request,
13
- diff_refs: diff_refs,
14
- web_url: Faker::Internet.url,
15
- merge_commit_sha: Faker::Internet.password
16
- )
15
+ diff_refs: diff_refs,
16
+ web_url: Faker::Internet.url,
17
+ merge_commit_sha: Faker::Internet.password)
17
18
  end
18
19
 
19
20
  let(:options) do
@@ -38,7 +39,7 @@ describe GitHelper::GitLabMergeRequest do
38
39
  allow(subject).to receive(:remove_source_branch).and_return(false)
39
40
  allow(subject).to receive(:new_mr_body).and_return('')
40
41
  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})
42
+ subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
42
43
  end
43
44
 
44
45
  it 'should call various other methods' do
@@ -46,7 +47,7 @@ describe GitHelper::GitLabMergeRequest do
46
47
  expect(subject).to receive(:remove_source_branch).and_return(false)
47
48
  expect(subject).to receive(:new_mr_body).and_return('')
48
49
  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})
50
+ subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
50
51
  end
51
52
 
52
53
  it 'should catch the raised error if the creation does not work' do
@@ -54,7 +55,7 @@ describe GitHelper::GitLabMergeRequest do
54
55
  allow(subject).to receive(:remove_source_branch).and_return(false)
55
56
  allow(subject).to receive(:new_mr_body).and_return('')
56
57
  allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
57
- expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
58
+ expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
58
59
  end
59
60
  end
60
61
 
@@ -120,19 +121,19 @@ describe GitHelper::GitLabMergeRequest do
120
121
 
121
122
  it 'should call the CLI to ask about a single template' do
122
123
  allow(subject).to receive(:mr_template_options).and_return([template])
123
- expect(highline_cli).to receive(:apply_template?).and_return(true)
124
+ expect(highline_cli).to receive(:ask_yes_no).and_return(true)
124
125
  subject.send(:template_name_to_apply)
125
126
  end
126
127
 
127
128
  it 'should return the single template if the user says yes' do
128
129
  allow(subject).to receive(:mr_template_options).and_return([template])
129
- allow(highline_cli).to receive(:apply_template?).and_return(true)
130
+ allow(highline_cli).to receive(:ask_yes_no).and_return(true)
130
131
  expect(subject.send(:template_name_to_apply)).to eq(template)
131
132
  end
132
133
 
133
134
  it 'should return nil if the user says no' do
134
135
  allow(subject).to receive(:mr_template_options).and_return([template])
135
- allow(highline_cli).to receive(:apply_template?).and_return(false)
136
+ allow(highline_cli).to receive(:ask_yes_no).and_return(false)
136
137
  expect(subject.send(:template_name_to_apply)).to eq(nil)
137
138
  end
138
139
  end
@@ -143,19 +144,19 @@ describe GitHelper::GitLabMergeRequest do
143
144
 
144
145
  it 'should call the CLI to ask which of multiple templates to apply' do
145
146
  allow(subject).to receive(:mr_template_options).and_return([template1, template2])
146
- expect(highline_cli).to receive(:template_to_apply).and_return(template1)
147
+ expect(highline_cli).to receive(:ask_options).and_return(template1)
147
148
  subject.send(:template_name_to_apply)
148
149
  end
149
150
 
150
151
  it 'should return the answer template if the user says yes' do
151
152
  allow(subject).to receive(:mr_template_options).and_return([template1, template2])
152
- allow(highline_cli).to receive(:template_to_apply).and_return(template1)
153
+ allow(highline_cli).to receive(:ask_options).and_return(template1)
153
154
  expect(subject.send(:template_name_to_apply)).to eq(template1)
154
155
  end
155
156
 
156
157
  it 'should return nil if the user says no' do
157
158
  allow(subject).to receive(:mr_template_options).and_return([template1, template2])
158
- allow(highline_cli).to receive(:template_to_apply).and_return('None')
159
+ allow(highline_cli).to receive(:ask_options).and_return('None')
159
160
  expect(subject.send(:template_name_to_apply)).to eq(nil)
160
161
  end
161
162
  end
@@ -170,25 +171,25 @@ describe GitHelper::GitLabMergeRequest do
170
171
 
171
172
  describe '#mr_id' do
172
173
  it 'should ask the CLI for the code request ID' do
173
- expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
174
+ expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
174
175
  subject.send(:mr_id)
175
176
  end
176
177
 
177
178
  it 'should equal an integer' do
178
179
  pr_id = Faker::Number.number
179
- expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
180
+ expect(highline_cli).to receive(:ask).and_return(pr_id)
180
181
  expect(subject.send(:mr_id)).to eq(pr_id)
181
182
  end
182
183
  end
183
184
 
184
185
  describe '#squash_merge_request' do
185
186
  it 'should ask the CLI for the code request ID' do
186
- expect(highline_cli).to receive(:squash_merge_request?).and_return(true)
187
+ expect(highline_cli).to receive(:ask_yes_no).and_return(true)
187
188
  subject.send(:squash_merge_request)
188
189
  end
189
190
 
190
191
  it 'should be a boolean' do
191
- expect(highline_cli).to receive(:squash_merge_request?).and_return(false)
192
+ expect(highline_cli).to receive(:ask_yes_no).and_return(false)
192
193
  expect([true, false]).to include(subject.send(:squash_merge_request))
193
194
  end
194
195
  end
@@ -200,12 +201,12 @@ describe GitHelper::GitLabMergeRequest do
200
201
 
201
202
  context 'when the existing project has no setting' do
202
203
  it 'should ask the CLI for the code request ID' do
203
- expect(highline_cli).to receive(:remove_source_branch?).and_return(true)
204
+ expect(highline_cli).to receive(:ask_yes_no).and_return(true)
204
205
  subject.send(:remove_source_branch)
205
206
  end
206
207
 
207
208
  it 'should be a boolean' do
208
- allow(highline_cli).to receive(:remove_source_branch?).and_return(false)
209
+ allow(highline_cli).to receive(:ask_yes_no).and_return(false)
209
210
  expect([true, false]).to include(subject.send(:remove_source_branch))
210
211
  end
211
212
  end
@@ -222,7 +223,7 @@ describe GitHelper::GitLabMergeRequest do
222
223
 
223
224
  it 'should return the existing projects setting if it exists' do
224
225
  allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
225
- allow(highline_cli).to receive(:remove_source_branch?).and_return(true)
226
+ allow(highline_cli).to receive(:ask_yes_no).and_return(true)
226
227
  expect(subject.send(:remove_source_branch)).to eq(true)
227
228
  end
228
229
  end
@@ -236,7 +237,7 @@ describe GitHelper::GitLabMergeRequest do
236
237
 
237
238
  describe '#existing_mr' do
238
239
  it 'should call the gitlab client' do
239
- allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
240
+ allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
240
241
  expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
241
242
  subject.send(:existing_mr)
242
243
  end