git_helper 3.3.0 → 3.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +58 -64
  4. data/Guardfile +5 -3
  5. data/LICENSE.md +29 -0
  6. data/README.md +42 -34
  7. data/Rakefile +2 -0
  8. data/bin/git-helper +18 -13
  9. data/lib/git_helper/change_remote.rb +15 -6
  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 +33 -19
  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 +11 -5
  16. data/lib/git_helper/github_client.rb +70 -0
  17. data/lib/git_helper/gitlab_client.rb +48 -2
  18. data/lib/git_helper/local_code.rb +24 -14
  19. data/lib/git_helper/merge_request.rb +98 -70
  20. data/lib/git_helper/new_branch.rb +3 -1
  21. data/lib/git_helper/pull_request.rb +91 -73
  22. data/lib/git_helper/setup.rb +62 -39
  23. data/lib/git_helper/version.rb +3 -1
  24. data/lib/git_helper.rb +7 -4
  25. data/renovate.json +6 -0
  26. metadata +34 -80
  27. data/LICENSE +0 -22
  28. data/lib/git_helper/highline_cli.rb +0 -33
  29. data/lib/git_helper/octokit_client.rb +0 -11
  30. data/plugins.zip +0 -0
  31. data/spec/git_helper/change_remote_spec.rb +0 -176
  32. data/spec/git_helper/checkout_default_spec.rb +0 -19
  33. data/spec/git_helper/clean_branches_spec.rb +0 -19
  34. data/spec/git_helper/code_request_spec.rb +0 -263
  35. data/spec/git_helper/empty_commit_spec.rb +0 -19
  36. data/spec/git_helper/forget_local_commits_spec.rb +0 -19
  37. data/spec/git_helper/git_config_reader_spec.rb +0 -62
  38. data/spec/git_helper/gitlab_client_spec.rb +0 -26
  39. data/spec/git_helper/highline_cli_spec.rb +0 -51
  40. data/spec/git_helper/local_code_spec.rb +0 -268
  41. data/spec/git_helper/merge_request_spec.rb +0 -251
  42. data/spec/git_helper/new_branch_spec.rb +0 -45
  43. data/spec/git_helper/octokit_client_spec.rb +0 -26
  44. data/spec/git_helper/pull_request_spec.rb +0 -254
  45. data/spec/git_helper/setup_spec.rb +0 -170
  46. data/spec/spec_helper.rb +0 -47
@@ -1,254 +0,0 @@
1
- require 'spec_helper'
2
- require 'git_helper'
3
-
4
- describe GitHelper::GitHubPullRequest do
5
- let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
6
- let(:highline_cli) { double(:highline_cli) }
7
- let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
8
- let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
9
-
10
- let(:options) do
11
- {
12
- local_project: Faker::Lorem.word,
13
- local_branch: Faker::Lorem.word,
14
- local_code: local_code,
15
- cli: highline_cli
16
- }
17
- end
18
-
19
- subject { GitHelper::GitHubPullRequest.new(options) }
20
-
21
- before do
22
- allow(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
23
- allow(subject).to receive(:puts)
24
- end
25
-
26
- describe '#create' do
27
- it 'should call the octokit client to create' do
28
- allow(subject).to receive(:new_pr_body).and_return('')
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})
31
- end
32
-
33
- it 'should call various other methods' do
34
- expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
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})
37
- end
38
-
39
- it 'should catch the raised error if the creation does not work' do
40
- allow(subject).to receive(:new_pr_body).and_return('')
41
- allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
42
- expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
43
- end
44
- end
45
-
46
- describe '#merge' do
47
- it 'should call the octokit client to merge' do
48
- allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
49
- allow(subject).to receive(:merge_method).and_return('rebase')
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))
52
- subject.merge
53
- end
54
-
55
- it 'should call various other methods' do
56
- expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
57
- expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
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))
60
- subject.merge
61
- end
62
-
63
- it 'should catch the raised error if the merge does not work' do
64
- allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
65
- allow(subject).to receive(:merge_method).and_return('rebase')
66
- allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
67
- allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
68
- expect(subject.merge).to eq(nil)
69
- end
70
- end
71
-
72
- describe '#new_pr_body' do
73
- it 'should call the local code if the template to apply exists' do
74
- allow(subject).to receive(:template_name_to_apply).and_return('')
75
- expect(local_code).to receive(:read_template)
76
- subject.send(:new_pr_body)
77
- end
78
-
79
- it 'should not call the local code if the template is nil' do
80
- allow(subject).to receive(:template_name_to_apply).and_return(nil)
81
- expect(local_code).not_to receive(:read_template)
82
- subject.send(:new_pr_body)
83
- end
84
-
85
- it 'should return an empty string if the template is nil' do
86
- allow(subject).to receive(:template_name_to_apply).and_return(nil)
87
- expect(subject.send(:new_pr_body)).to eq('')
88
- end
89
- end
90
-
91
- describe '#template_name_to_apply' do
92
- context 'if PR template options are empty' do
93
- it 'should return nil' do
94
- allow(subject).to receive(:pr_template_options).and_return([])
95
- expect(subject.send(:template_name_to_apply)).to eq(nil)
96
- end
97
- end
98
-
99
- context 'if there is one template option' do
100
- let(:template) { Faker::Lorem.word }
101
-
102
- it 'should call the CLI to ask about a single template' do
103
- allow(subject).to receive(:pr_template_options).and_return([template])
104
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
105
- subject.send(:template_name_to_apply)
106
- end
107
-
108
- it 'should return the single template if the user says yes' do
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)
112
- end
113
-
114
- it 'should return nil if the user says no' do
115
- allow(subject).to receive(:pr_template_options).and_return([template])
116
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
117
- expect(subject.send(:template_name_to_apply)).to eq(nil)
118
- end
119
- end
120
-
121
- context 'if there are multiple template options' do
122
- let(:template1) { Faker::Lorem.word }
123
- let(:template2) { Faker::Lorem.word }
124
-
125
- it 'should call the CLI to ask which of multiple templates to apply' do
126
- allow(subject).to receive(:pr_template_options).and_return([template1, template2])
127
- expect(highline_cli).to receive(:ask_options).and_return(template1)
128
- subject.send(:template_name_to_apply)
129
- end
130
-
131
- it 'should return the answer template if the user says yes' do
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)
135
- end
136
-
137
- it 'should return nil if the user says no' do
138
- allow(subject).to receive(:pr_template_options).and_return([template1, template2])
139
- allow(highline_cli).to receive(:ask_options).and_return('None')
140
- expect(subject.send(:template_name_to_apply)).to eq(nil)
141
- end
142
- end
143
- end
144
-
145
- describe '#pr_template_options' do
146
- it 'should call the local code' do
147
- expect(local_code).to receive(:template_options)
148
- subject.send(:pr_template_options)
149
- end
150
- end
151
-
152
- describe '#pr_id' do
153
- it 'should ask the CLI for the code request ID' do
154
- expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
155
- subject.send(:pr_id)
156
- end
157
-
158
- it 'should equal an integer' do
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)
162
- end
163
- end
164
-
165
- describe '#merge_method' do
166
- let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: true, allow_rebase_merge: true) }
167
-
168
- before do
169
- allow(subject).to receive(:existing_project).and_return(project)
170
- allow(highline_cli).to receive(:ask_options)
171
- end
172
-
173
- it 'should ask the CLI for the merge_method' do
174
- expect(highline_cli).to receive(:ask_options).and_return('merge')
175
- subject.send(:merge_method)
176
- end
177
-
178
- it 'should be a string' do
179
- allow(highline_cli).to receive(:ask_options).and_return('merge')
180
- expect(subject.send(:merge_method)).to be_a(String)
181
- end
182
-
183
- context 'if theres only one item' do
184
- let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
185
-
186
- it 'should not ask the CLI anything' do
187
- expect(highline_cli).not_to receive(:merge_method)
188
- subject.send(:merge_method)
189
- end
190
- end
191
- end
192
-
193
- describe '#merge_options' do
194
- let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: true, allow_rebase_merge: true) }
195
-
196
- before do
197
- allow(subject).to receive(:existing_project).and_return(project)
198
- end
199
-
200
- it 'should return an array' do
201
- expect(subject.send(:merge_options)).to be_a(Array)
202
- end
203
-
204
- it 'should have three items' do
205
- expect(subject.send(:merge_options).length).to eq(3)
206
- end
207
-
208
- context 'when two options are present' do
209
- let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: true, allow_rebase_merge: true) }
210
-
211
- it 'should have two items' do
212
- expect(subject.send(:merge_options).length).to eq(2)
213
- end
214
- end
215
-
216
- context 'when one option is present' do
217
- let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: false, allow_rebase_merge: true) }
218
-
219
- it 'should have one item' do
220
- expect(subject.send(:merge_options).length).to eq(1)
221
- end
222
- end
223
-
224
- context 'when no options are present' do
225
- let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: false, allow_rebase_merge: false) }
226
-
227
- it 'should have no items' do
228
- expect(subject.send(:merge_options).length).to eq(0)
229
- end
230
- end
231
- end
232
-
233
- describe '#existing_project' do
234
- it 'should call the octokit client' do
235
- expect(octokit_client_client).to receive(:repository).and_return(:repository)
236
- subject.send(:existing_project)
237
- end
238
- end
239
-
240
- describe '#existing_pr' do
241
- it 'should call the octokit client' do
242
- allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
243
- expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
244
- subject.send(:existing_pr)
245
- end
246
- end
247
-
248
- describe '#octokit_client' do
249
- it 'should call the octokit client' do
250
- expect(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
251
- subject.send(:octokit_client)
252
- end
253
- end
254
- end
@@ -1,170 +0,0 @@
1
- require 'spec_helper'
2
- require 'git_helper'
3
-
4
- describe GitHelper::Setup do
5
- let(:response) { double(:response, readline: true, to_s: Faker::Lorem.sentence) }
6
- let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
7
-
8
- before do
9
- allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
10
- allow(subject).to receive(:puts)
11
- end
12
-
13
- after do
14
- GitHelper::Setup.instance_variable_set("@highline", nil)
15
- end
16
-
17
- describe '#execute' do
18
- it 'should ask a question if the config file exists' do
19
- allow(File).to receive(:exists?).and_return(true)
20
- expect(highline_cli).to receive(:ask_yes_no).and_return(true)
21
- allow(subject).to receive(:create_or_update_config_file).and_return(true)
22
- allow(subject).to receive(:create_or_update_plugin_files)
23
- subject.execute
24
- end
25
-
26
- it 'should call to create or update the config file' do
27
- allow(File).to receive(:exists?).and_return(true)
28
- allow(highline_cli).to receive(:ask_yes_no).and_return(true)
29
- expect(subject).to receive(:create_or_update_config_file).and_return(true)
30
- allow(subject).to receive(:create_or_update_plugin_files)
31
- subject.execute
32
- end
33
-
34
- it 'should skip if the user opts not to continue' do
35
- allow(File).to receive(:exists?).and_return(true)
36
- allow(highline_cli).to receive(:ask_yes_no).and_return(false)
37
- expect(subject).not_to receive(:create_or_update_config_file)
38
- expect(subject).not_to receive(:create_or_update_plugin_files)
39
- subject.execute
40
- end
41
- end
42
-
43
- describe '#create_or_update_config_file' do
44
- it 'should generate the file based on the answers to the questions' do
45
- expect(subject).to receive(:generate_file_contents)
46
- allow(File).to receive(:open).and_return(nil)
47
- subject.send(:create_or_update_config_file)
48
- end
49
-
50
- it 'should open the file for writing' do
51
- allow(subject).to receive(:generate_file_contents)
52
- expect(File).to receive(:open).and_return(nil)
53
- subject.send(:create_or_update_config_file)
54
- end
55
- end
56
-
57
- describe '#config_file_exists?' do
58
- it 'should return true if the file exists' do
59
- allow(File).to receive(:exists?).and_return(true)
60
- expect(subject.send(:config_file_exists?)).to eq(true)
61
- end
62
-
63
- it 'should return false if the file does not exist' do
64
- allow(File).to receive(:exists?).and_return(false)
65
- expect(subject.send(:config_file_exists?)).to eq(false)
66
- end
67
- end
68
-
69
- describe '#ask_question' do
70
- it 'should use highline to ask a question' do
71
- expect(highline_cli).to receive(:ask).and_return(Faker::Lorem.word)
72
- subject.send(:ask_question, Faker::Lorem.sentence)
73
- end
74
-
75
- it 'should recurse if the highline client gets an empty string' do
76
- allow(highline_cli).to receive(:ask).and_return('', Faker::Lorem.word)
77
- expect(subject).to receive(:ask_question).at_least(:twice).and_call_original
78
- subject.send(:ask_question, Faker::Lorem.sentence)
79
- end
80
-
81
- it 'should return the answer if it is given' do
82
- answer = Faker::Lorem.sentence
83
- allow(highline_cli).to receive(:ask).and_return(answer)
84
- expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
85
- end
86
- end
87
-
88
- describe '#generate_file_contents' do
89
- it 'should ask two yes/no questions' do
90
- expect(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(false)
91
- subject.send(:generate_file_contents)
92
- end
93
-
94
- it 'should ask two additional questions for each time the user says yes' do
95
- allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
96
- expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
97
- subject.send(:generate_file_contents)
98
- end
99
-
100
- it 'should ask four additional questions for each time the user says yes' do
101
- allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
102
- expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
103
- subject.send(:generate_file_contents)
104
- end
105
-
106
- it 'should return a string no matter what' do
107
- allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
108
- allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
109
- expect(subject.send(:generate_file_contents)).to be_a(String)
110
- end
111
- end
112
-
113
- describe '#create_or_update_plugin_files' do
114
- let(:plugins) do
115
- [
116
- {
117
- 'name': 'plugin-file-one'
118
- },
119
- {
120
- 'name': 'plugin-file-two'
121
- }
122
- ]
123
- end
124
-
125
- let(:plugins_json) do
126
- "[
127
- {
128
- \"name\": \"plugin-file-one\"
129
- },
130
- {
131
- \"name\": \"plugin-file-two\"
132
- }
133
- ]"
134
- end
135
-
136
- it 'should create the directory if it does not exist' do
137
- allow(File).to receive(:exists?).and_return(false)
138
- allow(File).to receive(:open).and_return(nil)
139
- expect(Dir).to receive(:mkdir)
140
- allow(subject).to receive(:`).and_return(plugins_json)
141
- allow(JSON).to receive(:parse).and_return(plugins)
142
- subject.send(:create_or_update_plugin_files)
143
- end
144
-
145
- it 'should not create the directory if it already exists' do
146
- allow(File).to receive(:exists?).and_return(true)
147
- allow(File).to receive(:open).and_return(nil)
148
- expect(Dir).not_to receive(:mkdir)
149
- allow(subject).to receive(:`).and_return(plugins_json)
150
- allow(JSON).to receive(:parse).and_return(plugins)
151
- subject.send(:create_or_update_plugin_files)
152
- end
153
-
154
- it 'should curl the GitHub API' do
155
- allow(File).to receive(:exists?).and_return(true)
156
- allow(File).to receive(:open).and_return(nil)
157
- allow(subject).to receive(:`).and_return(plugins_json)
158
- expect(JSON).to receive(:parse).with(plugins_json).and_return(plugins)
159
- subject.send(:create_or_update_plugin_files)
160
- end
161
-
162
- it 'should go through the loop for each plugin' do
163
- allow(File).to receive(:exists?).and_return(true)
164
- allow(File).to receive(:open).and_return(nil)
165
- expect(subject).to receive(:`).exactly(3).times
166
- allow(JSON).to receive(:parse).and_return(plugins)
167
- subject.send(:create_or_update_plugin_files)
168
- end
169
- end
170
- end
data/spec/spec_helper.rb DELETED
@@ -1,47 +0,0 @@
1
- require 'faker'
2
-
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause
6
- # this file to always be loaded, without a need to explicitly require it in any
7
- # files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider making
13
- # a separate helper file that requires the additional dependencies and performs
14
- # the additional setup, and require it from the spec files that actually need
15
- # it.
16
- #
17
- # The `.rspec` file also contains a few flags that are not defaults but that
18
- # users commonly want.
19
- #
20
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
- RSpec.configure do |config|
22
- # rspec-expectations config goes here. You can use an alternate
23
- # assertion/expectation library such as wrong or the stdlib/minitest
24
- # assertions if you prefer.
25
- config.expect_with :rspec do |expectations|
26
- # This option will default to `true` in RSpec 4. It makes the `description`
27
- # and `failure_message` of custom matchers include text for helper methods
28
- # defined using `chain`, e.g.:
29
- # be_bigger_than(2).and_smaller_than(4).description
30
- # # => "be bigger than 2 and smaller than 4"
31
- # ...rather than:
32
- # # => "be bigger than 2"
33
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
- end
35
-
36
- config.filter_run :focus => true
37
- config.run_all_when_everything_filtered = true
38
-
39
- # rspec-mocks config goes here. You can use an alternate test double
40
- # library (such as bogus or mocha) by changing the `mock_with` option here.
41
- config.mock_with :rspec do |mocks|
42
- # Prevents you from mocking or stubbing a method that does not exist on
43
- # a real object. This is generally recommended, and will default to
44
- # `true` in RSpec 4.
45
- mocks.verify_partial_doubles = true
46
- end
47
- end