git_helper 1.2.0 → 2.0.2

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +17 -13
  3. data/README.md +27 -33
  4. data/Rakefile +1 -37
  5. data/bin/git-helper +10 -28
  6. data/lib/git_helper.rb +3 -5
  7. data/lib/git_helper/change_remote.rb +53 -40
  8. data/lib/git_helper/checkout_default.rb +1 -1
  9. data/lib/git_helper/clean_branches.rb +1 -4
  10. data/lib/git_helper/code_request.rb +95 -0
  11. data/lib/git_helper/empty_commit.rb +1 -1
  12. data/lib/git_helper/forget_local_commits.rb +7 -0
  13. data/lib/git_helper/gitlab_client.rb +0 -1
  14. data/lib/git_helper/highline_cli.rb +72 -6
  15. data/lib/git_helper/local_code.rb +124 -0
  16. data/lib/git_helper/merge_request.rb +57 -126
  17. data/lib/git_helper/new_branch.rb +2 -11
  18. data/lib/git_helper/octokit_client.rb +0 -1
  19. data/lib/git_helper/pull_request.rb +45 -110
  20. data/lib/git_helper/version.rb +1 -1
  21. data/spec/git_helper/change_remote_spec.rb +173 -0
  22. data/spec/git_helper/checkout_default_spec.rb +19 -0
  23. data/spec/git_helper/clean_branches_spec.rb +19 -0
  24. data/spec/git_helper/code_request_spec.rb +259 -0
  25. data/spec/git_helper/empty_commit_spec.rb +19 -0
  26. data/spec/git_helper/forget_local_commits_spec.rb +19 -0
  27. data/spec/git_helper/git_config_reader_spec.rb +60 -0
  28. data/spec/git_helper/gitlab_client_spec.rb +26 -0
  29. data/spec/git_helper/highline_cli_spec.rb +215 -0
  30. data/spec/git_helper/local_code_spec.rb +231 -0
  31. data/spec/git_helper/merge_request_spec.rb +234 -0
  32. data/spec/git_helper/new_branch_spec.rb +44 -0
  33. data/spec/git_helper/octokit_client_spec.rb +26 -0
  34. data/spec/git_helper/pull_request_spec.rb +246 -0
  35. data/spec/spec_helper.rb +0 -7
  36. metadata +41 -24
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'git_helper'
3
+
4
+ describe GitHelper::NewBranch do
5
+ let(:new_branch_name) { 'new-branch-name' }
6
+ let(:local_code) { double(:local_code, new_branch: :commit) }
7
+ let(:cli) { double(:highline_cli, new_branch_name: new_branch_name) }
8
+
9
+ subject { GitHelper::NewBranch.new }
10
+
11
+ before do
12
+ allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
13
+ allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
14
+ end
15
+
16
+ it 'should call GitHelper::LocalCode' do
17
+ expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
18
+ subject.execute
19
+ end
20
+
21
+ it 'should call the new_branch method from the local code class' do
22
+ expect(local_code).to receive(:new_branch)
23
+ subject.execute
24
+ end
25
+
26
+ context 'when no branch name is passed in' do
27
+ it 'should call the highline cli' do
28
+ expect(GitHelper::HighlineCli).to receive(:new).and_return(cli)
29
+ subject.execute
30
+ end
31
+
32
+ it 'should ask the highline cli what the new branch name should be' do
33
+ expect(cli).to receive(:new_branch_name)
34
+ subject.execute
35
+ end
36
+ end
37
+
38
+ context 'when there is a branch name passed in' do
39
+ it 'should not create a highline cli' do
40
+ expect(GitHelper::HighlineCli).not_to receive(:new)
41
+ subject.execute(new_branch_name)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'git_helper'
3
+
4
+ describe GitHelper::OctokitClient do
5
+ let(:git_config_reader) { double(:git_config_reader, github_token: :token) }
6
+
7
+ subject { GitHelper::OctokitClient.new }
8
+
9
+ before do
10
+ allow(GitHelper::GitConfigReader).to receive(:new).and_return(git_config_reader)
11
+ end
12
+
13
+ describe '#client' do
14
+ it 'should call the GitLab client to make a new client' do
15
+ expect(Octokit::Client).to receive(:new)
16
+ subject.client
17
+ end
18
+ end
19
+
20
+ describe '#git_config_reader' do
21
+ it 'should make a new git config reader' do
22
+ expect(GitHelper::GitConfigReader).to receive(:new)
23
+ subject.send(:git_config_reader)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,246 @@
1
+ require 'spec_helper'
2
+ require 'git_helper'
3
+
4
+ describe GitHelper::GitHubPullRequest do
5
+ let(:local_code) { double(:local_code, read_template: 'template') }
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
+ let(:options) do
10
+ {
11
+ local_project: 'emmasax4/git_helper',
12
+ local_branch: 'main',
13
+ local_code: local_code,
14
+ cli: highline_cli
15
+ }
16
+ end
17
+
18
+ subject { GitHelper::GitHubPullRequest.new(options) }
19
+
20
+ before do
21
+ allow(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
22
+ end
23
+
24
+ describe '#create' do
25
+ it 'should call the octokit client to create' do
26
+ allow(subject).to receive(:new_pr_body).and_return('')
27
+ expect(octokit_client_client).to receive(:create_pull_request)
28
+ subject.create({base_branch: 'base', new_title: 'title'})
29
+ end
30
+
31
+ it 'should call various other methods' do
32
+ expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
33
+ allow(octokit_client_client).to receive(:create_pull_request)
34
+ subject.create({base_branch: 'base', new_title: 'title'})
35
+ end
36
+
37
+ it 'should catch the raised error if the creation does not work' do
38
+ allow(subject).to receive(:new_pr_body).and_return('')
39
+ allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
40
+ expect(subject.create({base_branch: 'base', new_title: 'title'})).to eq(nil)
41
+ end
42
+ end
43
+
44
+ describe '#merge' do
45
+ it 'should call the octokit client to merge' do
46
+ allow(subject).to receive(:existing_pr).and_return(double(title: 'title'))
47
+ allow(subject).to receive(:merge_method).and_return('rebase')
48
+ allow(subject).to receive(:pr_id).and_return(123)
49
+ expect(octokit_client_client).to receive(:merge_pull_request)
50
+ subject.merge
51
+ end
52
+
53
+ it 'should call various other methods' do
54
+ expect(subject).to receive(:existing_pr).and_return(double(title: 'title')).at_least(:once)
55
+ expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
56
+ expect(subject).to receive(:pr_id).and_return(123).at_least(:once)
57
+ allow(octokit_client_client).to receive(:merge_pull_request)
58
+ subject.merge
59
+ end
60
+
61
+ it 'should catch the raised error if the merge does not work' do
62
+ allow(subject).to receive(:existing_pr).and_return(double(title: 'title'))
63
+ allow(subject).to receive(:merge_method).and_return('rebase')
64
+ allow(subject).to receive(:pr_id).and_return(123)
65
+ allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
66
+ expect(subject.merge).to eq(nil)
67
+ end
68
+ end
69
+
70
+ describe '#new_pr_body' do
71
+ it 'should call the local code if the template to apply exists' do
72
+ allow(subject).to receive(:template_name_to_apply).and_return('')
73
+ expect(local_code).to receive(:read_template)
74
+ subject.send(:new_pr_body)
75
+ end
76
+
77
+ it 'should not call the local code if the template is nil' do
78
+ allow(subject).to receive(:template_name_to_apply).and_return(nil)
79
+ expect(local_code).not_to receive(:read_template)
80
+ subject.send(:new_pr_body)
81
+ end
82
+
83
+ it 'should return an empty string if the template is nil' do
84
+ allow(subject).to receive(:template_name_to_apply).and_return(nil)
85
+ expect(subject.send(:new_pr_body)).to eq('')
86
+ end
87
+ end
88
+
89
+ describe '#template_name_to_apply' do
90
+ context 'if PR template options are empty' do
91
+ it 'should return nil' do
92
+ allow(subject).to receive(:pr_template_options).and_return([])
93
+ expect(subject.send(:template_name_to_apply)).to eq(nil)
94
+ end
95
+ end
96
+
97
+ context 'if there is one template option' do
98
+ it 'should call the CLI to ask about a single template' do
99
+ allow(subject).to receive(:pr_template_options).and_return(['template1'])
100
+ expect(highline_cli).to receive(:apply_template?).and_return(true)
101
+ subject.send(:template_name_to_apply)
102
+ end
103
+
104
+ it 'should return the single template if the user says yes' do
105
+ allow(subject).to receive(:pr_template_options).and_return(['template1'])
106
+ allow(highline_cli).to receive(:apply_template?).and_return(true)
107
+ expect(subject.send(:template_name_to_apply)).to eq('template1')
108
+ end
109
+
110
+ it 'should return nil if the user says no' do
111
+ allow(subject).to receive(:pr_template_options).and_return(['template1'])
112
+ allow(highline_cli).to receive(:apply_template?).and_return(false)
113
+ expect(subject.send(:template_name_to_apply)).to eq(nil)
114
+ end
115
+ end
116
+
117
+ context 'if there are multiple template options' do
118
+ it 'should call the CLI to ask which of multiple templates to apply' do
119
+ allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
120
+ expect(highline_cli).to receive(:template_to_apply).and_return('template1')
121
+ subject.send(:template_name_to_apply)
122
+ end
123
+
124
+ it 'should return the answer template if the user says yes' do
125
+ allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
126
+ allow(highline_cli).to receive(:template_to_apply).and_return('template1')
127
+ expect(subject.send(:template_name_to_apply)).to eq('template1')
128
+ end
129
+
130
+ it 'should return nil if the user says no' do
131
+ allow(subject).to receive(:pr_template_options).and_return(['template1', 'template2'])
132
+ allow(highline_cli).to receive(:template_to_apply).and_return('None')
133
+ expect(subject.send(:template_name_to_apply)).to eq(nil)
134
+ end
135
+ end
136
+ end
137
+
138
+ describe '#pr_template_options' do
139
+ it 'should call the local code' do
140
+ expect(local_code).to receive(:template_options)
141
+ subject.send(:pr_template_options)
142
+ end
143
+ end
144
+
145
+ describe '#pr_id' do
146
+ it 'should ask the CLI for the code request ID' do
147
+ expect(highline_cli).to receive(:code_request_id).and_return(123)
148
+ subject.send(:pr_id)
149
+ end
150
+
151
+ it 'should equal an integer' do
152
+ expect(highline_cli).to receive(:code_request_id).and_return(123)
153
+ expect(subject.send(:pr_id)).to eq(123)
154
+ end
155
+ end
156
+
157
+ describe '#merge_method' do
158
+ let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: true, allow_rebase_merge: true) }
159
+
160
+ before do
161
+ allow(subject).to receive(:existing_project).and_return(project)
162
+ allow(highline_cli).to receive(:merge_method)
163
+ end
164
+
165
+ it 'should ask the CLI for the merge_method' do
166
+ expect(highline_cli).to receive(:merge_method).and_return('merge')
167
+ subject.send(:merge_method)
168
+ end
169
+
170
+ it 'should be a string' do
171
+ allow(highline_cli).to receive(:merge_method).and_return('merge')
172
+ expect(subject.send(:merge_method)).to be_a(String)
173
+ end
174
+
175
+ context "if there's only one item" do
176
+ let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
177
+
178
+ it 'should not ask the CLI anything' do
179
+ expect(highline_cli).not_to receive(:merge_method)
180
+ subject.send(:merge_method)
181
+ end
182
+ end
183
+ end
184
+
185
+ describe '#merge_options' do
186
+ let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: true, allow_rebase_merge: true) }
187
+
188
+ before do
189
+ allow(subject).to receive(:existing_project).and_return(project)
190
+ end
191
+
192
+ it 'should return an array' do
193
+ expect(subject.send(:merge_options)).to be_a(Array)
194
+ end
195
+
196
+ it 'should have three items' do
197
+ expect(subject.send(:merge_options).length).to eq(3)
198
+ end
199
+
200
+ context 'when two options are present' do
201
+ let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: true, allow_rebase_merge: true) }
202
+
203
+ it 'should have two items' do
204
+ expect(subject.send(:merge_options).length).to eq(2)
205
+ end
206
+ end
207
+
208
+ context 'when one option is present' do
209
+ let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: false, allow_rebase_merge: true) }
210
+
211
+ it 'should have one item' do
212
+ expect(subject.send(:merge_options).length).to eq(1)
213
+ end
214
+ end
215
+
216
+ context 'when no options are present' do
217
+ let(:project) { double(:project, allow_merge_commit: false, allow_squash_merge: false, allow_rebase_merge: false) }
218
+
219
+ it 'should have no items' do
220
+ expect(subject.send(:merge_options).length).to eq(0)
221
+ end
222
+ end
223
+ end
224
+
225
+ describe '#existing_project' do
226
+ it 'should call the octokit client' do
227
+ expect(octokit_client_client).to receive(:repository).and_return(:repository)
228
+ subject.send(:existing_project)
229
+ end
230
+ end
231
+
232
+ describe '#existing_pr' do
233
+ it 'should call the octokit client' do
234
+ allow(highline_cli).to receive(:code_request_id).and_return(123)
235
+ expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
236
+ subject.send(:existing_pr)
237
+ end
238
+ end
239
+
240
+ describe '#octokit_client' do
241
+ it 'should call the octokit client' do
242
+ expect(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
243
+ subject.send(:octokit_client)
244
+ end
245
+ end
246
+ end
@@ -1,9 +1,3 @@
1
- require 'simplecov'
2
-
3
- SimpleCov.start do
4
- add_filter '/spec/'
5
- end
6
-
7
1
  # This file was generated by the `rspec --init` command. Conventionally, all
8
2
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
9
3
  # The generated `.rspec` file contains `--require spec_helper` which will cause
@@ -37,7 +31,6 @@ RSpec.configure do |config|
37
31
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
32
  end
39
33
 
40
- config.use_transactional_fixtures = true
41
34
  config.filter_run :focus => true
42
35
  config.run_all_when_everything_filtered = true
43
36
 
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: 1.2.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emma Sax
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-30 00:00:00.000000000 Z
11
+ date: 2020-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.1'
83
- - !ruby/object:Gem::Dependency
84
- name: guard
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.6'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.6'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: guard-rspec
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -114,29 +100,30 @@ dependencies:
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 12.3.3
103
+ version: '13.0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: 12.3.3
110
+ version: '13.0'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: rspec
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: '2.99'
117
+ version: '3.9'
132
118
  type: :development
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: '2.99'
139
- description: A set of GitHub and GitLab workflow scripts.
124
+ version: '3.9'
125
+ description: A set of GitHub and GitLab workflow scripts to provide a smoother development
126
+ process for your git projects.
140
127
  email:
141
128
  - emma.sax4@gmail.com
142
129
  executables:
@@ -155,15 +142,32 @@ files:
155
142
  - lib/git_helper/change_remote.rb
156
143
  - lib/git_helper/checkout_default.rb
157
144
  - lib/git_helper/clean_branches.rb
145
+ - lib/git_helper/code_request.rb
158
146
  - lib/git_helper/empty_commit.rb
147
+ - lib/git_helper/forget_local_commits.rb
159
148
  - lib/git_helper/git_config_reader.rb
160
149
  - lib/git_helper/gitlab_client.rb
161
150
  - lib/git_helper/highline_cli.rb
151
+ - lib/git_helper/local_code.rb
162
152
  - lib/git_helper/merge_request.rb
163
153
  - lib/git_helper/new_branch.rb
164
154
  - lib/git_helper/octokit_client.rb
165
155
  - lib/git_helper/pull_request.rb
166
156
  - lib/git_helper/version.rb
157
+ - spec/git_helper/change_remote_spec.rb
158
+ - spec/git_helper/checkout_default_spec.rb
159
+ - spec/git_helper/clean_branches_spec.rb
160
+ - spec/git_helper/code_request_spec.rb
161
+ - spec/git_helper/empty_commit_spec.rb
162
+ - spec/git_helper/forget_local_commits_spec.rb
163
+ - spec/git_helper/git_config_reader_spec.rb
164
+ - spec/git_helper/gitlab_client_spec.rb
165
+ - spec/git_helper/highline_cli_spec.rb
166
+ - spec/git_helper/local_code_spec.rb
167
+ - spec/git_helper/merge_request_spec.rb
168
+ - spec/git_helper/new_branch_spec.rb
169
+ - spec/git_helper/octokit_client_spec.rb
170
+ - spec/git_helper/pull_request_spec.rb
167
171
  - spec/spec_helper.rb
168
172
  homepage: https://github.com/emmasax4/git_helper
169
173
  licenses:
@@ -184,10 +188,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
188
  - !ruby/object:Gem::Version
185
189
  version: '0'
186
190
  requirements: []
187
- rubygems_version: 3.1.2
191
+ rubygems_version: 3.1.4
188
192
  signing_key:
189
193
  specification_version: 4
190
- summary: A set of GitHub and GitLab workflow scripts to provide a smoother development
191
- process for your git projects.
194
+ summary: A set of GitHub and GitLab workflow scripts.
192
195
  test_files:
193
196
  - spec/spec_helper.rb
197
+ - spec/git_helper/octokit_client_spec.rb
198
+ - spec/git_helper/new_branch_spec.rb
199
+ - spec/git_helper/forget_local_commits_spec.rb
200
+ - spec/git_helper/clean_branches_spec.rb
201
+ - spec/git_helper/change_remote_spec.rb
202
+ - spec/git_helper/checkout_default_spec.rb
203
+ - spec/git_helper/pull_request_spec.rb
204
+ - spec/git_helper/gitlab_client_spec.rb
205
+ - spec/git_helper/code_request_spec.rb
206
+ - spec/git_helper/empty_commit_spec.rb
207
+ - spec/git_helper/highline_cli_spec.rb
208
+ - spec/git_helper/git_config_reader_spec.rb
209
+ - spec/git_helper/merge_request_spec.rb
210
+ - spec/git_helper/local_code_spec.rb