git_helper 3.1.2 → 3.3.0

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.
@@ -4,13 +4,14 @@ require 'git_helper'
4
4
  describe GitHelper::NewBranch do
5
5
  let(:new_branch_name) { 'new-branch-name' }
6
6
  let(:local_code) { double(:local_code, new_branch: :commit) }
7
- let(:cli) { double(:highline_cli, new_branch_name: new_branch_name) }
7
+ let(:cli) { double(:highline_cli, ask: new_branch_name) }
8
8
 
9
9
  subject { GitHelper::NewBranch.new }
10
10
 
11
11
  before do
12
12
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
13
13
  allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
14
+ allow(subject).to receive(:puts)
14
15
  end
15
16
 
16
17
  it 'should call GitHelper::LocalCode' do
@@ -30,7 +31,7 @@ describe GitHelper::NewBranch do
30
31
  end
31
32
 
32
33
  it 'should ask the highline cli what the new branch name should be' do
33
- expect(cli).to receive(:new_branch_name)
34
+ expect(cli).to receive(:ask)
34
35
  subject.execute
35
36
  end
36
37
  end
@@ -20,18 +20,19 @@ describe GitHelper::GitHubPullRequest do
20
20
 
21
21
  before do
22
22
  allow(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
23
+ allow(subject).to receive(:puts)
23
24
  end
24
25
 
25
26
  describe '#create' do
26
27
  it 'should call the octokit client to create' do
27
28
  allow(subject).to receive(:new_pr_body).and_return('')
28
- expect(octokit_client_client).to receive(:create_pull_request)
29
+ expect(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
29
30
  subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
30
31
  end
31
32
 
32
33
  it 'should call various other methods' do
33
34
  expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
34
- allow(octokit_client_client).to receive(:create_pull_request)
35
+ allow(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
35
36
  subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
36
37
  end
37
38
 
@@ -47,7 +48,7 @@ describe GitHelper::GitHubPullRequest do
47
48
  allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
48
49
  allow(subject).to receive(:merge_method).and_return('rebase')
49
50
  allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
50
- expect(octokit_client_client).to receive(:merge_pull_request)
51
+ expect(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
51
52
  subject.merge
52
53
  end
53
54
 
@@ -55,7 +56,7 @@ describe GitHelper::GitHubPullRequest do
55
56
  expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
56
57
  expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
57
58
  expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
58
- allow(octokit_client_client).to receive(:merge_pull_request)
59
+ allow(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
59
60
  subject.merge
60
61
  end
61
62
 
@@ -100,19 +101,19 @@ describe GitHelper::GitHubPullRequest do
100
101
 
101
102
  it 'should call the CLI to ask about a single template' do
102
103
  allow(subject).to receive(:pr_template_options).and_return([template])
103
- expect(highline_cli).to receive(:apply_template?).and_return(true)
104
+ expect(highline_cli).to receive(:ask_yes_no).and_return(true)
104
105
  subject.send(:template_name_to_apply)
105
106
  end
106
107
 
107
108
  it 'should return the single template if the user says yes' do
108
109
  allow(subject).to receive(:pr_template_options).and_return([template])
109
- allow(highline_cli).to receive(:apply_template?).and_return(true)
110
+ allow(highline_cli).to receive(:ask_yes_no).and_return(true)
110
111
  expect(subject.send(:template_name_to_apply)).to eq(template)
111
112
  end
112
113
 
113
114
  it 'should return nil if the user says no' do
114
115
  allow(subject).to receive(:pr_template_options).and_return([template])
115
- allow(highline_cli).to receive(:apply_template?).and_return(false)
116
+ allow(highline_cli).to receive(:ask_yes_no).and_return(false)
116
117
  expect(subject.send(:template_name_to_apply)).to eq(nil)
117
118
  end
118
119
  end
@@ -123,19 +124,19 @@ describe GitHelper::GitHubPullRequest do
123
124
 
124
125
  it 'should call the CLI to ask which of multiple templates to apply' do
125
126
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
126
- expect(highline_cli).to receive(:template_to_apply).and_return(template1)
127
+ expect(highline_cli).to receive(:ask_options).and_return(template1)
127
128
  subject.send(:template_name_to_apply)
128
129
  end
129
130
 
130
131
  it 'should return the answer template if the user says yes' do
131
132
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
132
- allow(highline_cli).to receive(:template_to_apply).and_return(template1)
133
+ allow(highline_cli).to receive(:ask_options).and_return(template1)
133
134
  expect(subject.send(:template_name_to_apply)).to eq(template1)
134
135
  end
135
136
 
136
137
  it 'should return nil if the user says no' do
137
138
  allow(subject).to receive(:pr_template_options).and_return([template1, template2])
138
- allow(highline_cli).to receive(:template_to_apply).and_return('None')
139
+ allow(highline_cli).to receive(:ask_options).and_return('None')
139
140
  expect(subject.send(:template_name_to_apply)).to eq(nil)
140
141
  end
141
142
  end
@@ -150,13 +151,13 @@ describe GitHelper::GitHubPullRequest do
150
151
 
151
152
  describe '#pr_id' do
152
153
  it 'should ask the CLI for the code request ID' do
153
- expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
154
+ expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
154
155
  subject.send(:pr_id)
155
156
  end
156
157
 
157
158
  it 'should equal an integer' do
158
159
  pr_id = Faker::Number.number
159
- expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
160
+ expect(highline_cli).to receive(:ask).and_return(pr_id)
160
161
  expect(subject.send(:pr_id)).to eq(pr_id)
161
162
  end
162
163
  end
@@ -166,16 +167,16 @@ describe GitHelper::GitHubPullRequest do
166
167
 
167
168
  before do
168
169
  allow(subject).to receive(:existing_project).and_return(project)
169
- allow(highline_cli).to receive(:merge_method)
170
+ allow(highline_cli).to receive(:ask_options)
170
171
  end
171
172
 
172
173
  it 'should ask the CLI for the merge_method' do
173
- expect(highline_cli).to receive(:merge_method).and_return('merge')
174
+ expect(highline_cli).to receive(:ask_options).and_return('merge')
174
175
  subject.send(:merge_method)
175
176
  end
176
177
 
177
178
  it 'should be a string' do
178
- allow(highline_cli).to receive(:merge_method).and_return('merge')
179
+ allow(highline_cli).to receive(:ask_options).and_return('merge')
179
180
  expect(subject.send(:merge_method)).to be_a(String)
180
181
  end
181
182
 
@@ -238,7 +239,7 @@ describe GitHelper::GitHubPullRequest do
238
239
 
239
240
  describe '#existing_pr' do
240
241
  it 'should call the octokit client' do
241
- allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
242
+ allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
242
243
  expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
243
244
  subject.send(:existing_pr)
244
245
  end
@@ -0,0 +1,170 @@
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
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.1.2
4
+ version: 3.3.0
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-12-07 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.1'
75
+ version: '2.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.1'
82
+ version: '2.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faker
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2.15'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2.15'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: guard-rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,6 @@ dependencies:
139
139
  description: A set of GitHub and GitLab workflow scripts to provide a smoother development
140
140
  process for your git projects.
141
141
  email:
142
- - emma.sax4@gmail.com
143
142
  executables:
144
143
  - git-helper
145
144
  extensions: []
@@ -167,6 +166,7 @@ files:
167
166
  - lib/git_helper/new_branch.rb
168
167
  - lib/git_helper/octokit_client.rb
169
168
  - lib/git_helper/pull_request.rb
169
+ - lib/git_helper/setup.rb
170
170
  - lib/git_helper/version.rb
171
171
  - plugins.zip
172
172
  - spec/git_helper/change_remote_spec.rb
@@ -183,8 +183,9 @@ files:
183
183
  - spec/git_helper/new_branch_spec.rb
184
184
  - spec/git_helper/octokit_client_spec.rb
185
185
  - spec/git_helper/pull_request_spec.rb
186
+ - spec/git_helper/setup_spec.rb
186
187
  - spec/spec_helper.rb
187
- homepage: https://github.com/emmasax4/git_helper
188
+ homepage: https://github.com/emmahsax/git_helper
188
189
  licenses:
189
190
  - MIT
190
191
  metadata: {}
@@ -203,23 +204,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  - !ruby/object:Gem::Version
204
205
  version: '0'
205
206
  requirements: []
206
- rubygems_version: 3.1.4
207
+ rubygems_version: 3.2.3
207
208
  signing_key:
208
209
  specification_version: 4
209
210
  summary: A set of GitHub and GitLab workflow scripts.
210
211
  test_files:
211
212
  - spec/spec_helper.rb
212
- - spec/git_helper/octokit_client_spec.rb
213
- - spec/git_helper/new_branch_spec.rb
214
- - spec/git_helper/forget_local_commits_spec.rb
215
- - spec/git_helper/clean_branches_spec.rb
216
213
  - spec/git_helper/change_remote_spec.rb
217
214
  - spec/git_helper/checkout_default_spec.rb
218
- - spec/git_helper/pull_request_spec.rb
219
- - spec/git_helper/gitlab_client_spec.rb
215
+ - spec/git_helper/clean_branches_spec.rb
220
216
  - spec/git_helper/code_request_spec.rb
221
217
  - spec/git_helper/empty_commit_spec.rb
222
- - spec/git_helper/highline_cli_spec.rb
218
+ - spec/git_helper/forget_local_commits_spec.rb
223
219
  - spec/git_helper/git_config_reader_spec.rb
224
- - spec/git_helper/merge_request_spec.rb
220
+ - spec/git_helper/gitlab_client_spec.rb
221
+ - spec/git_helper/highline_cli_spec.rb
225
222
  - spec/git_helper/local_code_spec.rb
223
+ - spec/git_helper/merge_request_spec.rb
224
+ - spec/git_helper/new_branch_spec.rb
225
+ - spec/git_helper/octokit_client_spec.rb
226
+ - spec/git_helper/pull_request_spec.rb
227
+ - spec/git_helper/setup_spec.rb