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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +131 -0
- data/Guardfile +3 -1
- data/README.md +11 -6
- data/Rakefile +2 -0
- data/bin/git-helper +25 -13
- data/lib/git_helper.rb +5 -1
- data/lib/git_helper/change_remote.rb +11 -3
- data/lib/git_helper/checkout_default.rb +2 -0
- data/lib/git_helper/clean_branches.rb +2 -0
- data/lib/git_helper/code_request.rb +29 -15
- data/lib/git_helper/empty_commit.rb +2 -0
- data/lib/git_helper/forget_local_commits.rb +2 -0
- data/lib/git_helper/git_config_reader.rb +12 -6
- data/lib/git_helper/gitlab_client.rb +2 -0
- data/lib/git_helper/highline_cli.rb +15 -69
- data/lib/git_helper/local_code.rb +18 -8
- data/lib/git_helper/merge_request.rb +88 -68
- data/lib/git_helper/new_branch.rb +3 -1
- data/lib/git_helper/octokit_client.rb +2 -0
- data/lib/git_helper/pull_request.rb +95 -64
- data/lib/git_helper/setup.rb +116 -0
- data/lib/git_helper/version.rb +3 -1
- data/spec/git_helper/change_remote_spec.rb +19 -19
- data/spec/git_helper/checkout_default_spec.rb +2 -0
- data/spec/git_helper/clean_branches_spec.rb +2 -0
- data/spec/git_helper/code_request_spec.rb +27 -24
- data/spec/git_helper/empty_commit_spec.rb +2 -0
- data/spec/git_helper/forget_local_commits_spec.rb +2 -0
- data/spec/git_helper/git_config_reader_spec.rb +32 -4
- data/spec/git_helper/gitlab_client_spec.rb +2 -0
- data/spec/git_helper/highline_cli_spec.rb +21 -185
- data/spec/git_helper/local_code_spec.rb +2 -0
- data/spec/git_helper/merge_request_spec.rb +22 -21
- data/spec/git_helper/new_branch_spec.rb +4 -2
- data/spec/git_helper/octokit_client_spec.rb +2 -0
- data/spec/git_helper/pull_request_spec.rb +17 -15
- data/spec/git_helper/setup_spec.rb +180 -0
- data/spec/spec_helper.rb +3 -1
- metadata +22 -5
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'git_helper'
|
3
5
|
|
4
6
|
describe GitHelper::NewBranch do
|
5
7
|
let(:new_branch_name) { 'new-branch-name' }
|
6
8
|
let(:local_code) { double(:local_code, new_branch: :commit) }
|
7
|
-
let(:cli) { double(:highline_cli,
|
9
|
+
let(:cli) { double(:highline_cli, ask: new_branch_name) }
|
8
10
|
|
9
11
|
subject { GitHelper::NewBranch.new }
|
10
12
|
|
@@ -31,7 +33,7 @@ describe GitHelper::NewBranch do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'should ask the highline cli what the new branch name should be' do
|
34
|
-
expect(cli).to receive(:
|
36
|
+
expect(cli).to receive(:ask)
|
35
37
|
subject.execute
|
36
38
|
end
|
37
39
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'git_helper'
|
3
5
|
|
@@ -27,19 +29,19 @@ describe GitHelper::GitHubPullRequest do
|
|
27
29
|
it 'should call the octokit client to create' do
|
28
30
|
allow(subject).to receive(:new_pr_body).and_return('')
|
29
31
|
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})
|
32
|
+
subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'should call various other methods' do
|
34
36
|
expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
|
35
37
|
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})
|
38
|
+
subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'should catch the raised error if the creation does not work' do
|
40
42
|
allow(subject).to receive(:new_pr_body).and_return('')
|
41
43
|
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)
|
44
|
+
expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
@@ -101,19 +103,19 @@ describe GitHelper::GitHubPullRequest do
|
|
101
103
|
|
102
104
|
it 'should call the CLI to ask about a single template' do
|
103
105
|
allow(subject).to receive(:pr_template_options).and_return([template])
|
104
|
-
expect(highline_cli).to receive(:
|
106
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
105
107
|
subject.send(:template_name_to_apply)
|
106
108
|
end
|
107
109
|
|
108
110
|
it 'should return the single template if the user says yes' do
|
109
111
|
allow(subject).to receive(:pr_template_options).and_return([template])
|
110
|
-
allow(highline_cli).to receive(:
|
112
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
111
113
|
expect(subject.send(:template_name_to_apply)).to eq(template)
|
112
114
|
end
|
113
115
|
|
114
116
|
it 'should return nil if the user says no' do
|
115
117
|
allow(subject).to receive(:pr_template_options).and_return([template])
|
116
|
-
allow(highline_cli).to receive(:
|
118
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
117
119
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
118
120
|
end
|
119
121
|
end
|
@@ -124,19 +126,19 @@ describe GitHelper::GitHubPullRequest do
|
|
124
126
|
|
125
127
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
126
128
|
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
127
|
-
expect(highline_cli).to receive(:
|
129
|
+
expect(highline_cli).to receive(:ask_options).and_return(template1)
|
128
130
|
subject.send(:template_name_to_apply)
|
129
131
|
end
|
130
132
|
|
131
133
|
it 'should return the answer template if the user says yes' do
|
132
134
|
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
133
|
-
allow(highline_cli).to receive(:
|
135
|
+
allow(highline_cli).to receive(:ask_options).and_return(template1)
|
134
136
|
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
135
137
|
end
|
136
138
|
|
137
139
|
it 'should return nil if the user says no' do
|
138
140
|
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
139
|
-
allow(highline_cli).to receive(:
|
141
|
+
allow(highline_cli).to receive(:ask_options).and_return('None')
|
140
142
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
141
143
|
end
|
142
144
|
end
|
@@ -151,13 +153,13 @@ describe GitHelper::GitHubPullRequest do
|
|
151
153
|
|
152
154
|
describe '#pr_id' do
|
153
155
|
it 'should ask the CLI for the code request ID' do
|
154
|
-
expect(highline_cli).to receive(:
|
156
|
+
expect(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
155
157
|
subject.send(:pr_id)
|
156
158
|
end
|
157
159
|
|
158
160
|
it 'should equal an integer' do
|
159
161
|
pr_id = Faker::Number.number
|
160
|
-
expect(highline_cli).to receive(:
|
162
|
+
expect(highline_cli).to receive(:ask).and_return(pr_id)
|
161
163
|
expect(subject.send(:pr_id)).to eq(pr_id)
|
162
164
|
end
|
163
165
|
end
|
@@ -167,16 +169,16 @@ describe GitHelper::GitHubPullRequest do
|
|
167
169
|
|
168
170
|
before do
|
169
171
|
allow(subject).to receive(:existing_project).and_return(project)
|
170
|
-
allow(highline_cli).to receive(:
|
172
|
+
allow(highline_cli).to receive(:ask_options)
|
171
173
|
end
|
172
174
|
|
173
175
|
it 'should ask the CLI for the merge_method' do
|
174
|
-
expect(highline_cli).to receive(:
|
176
|
+
expect(highline_cli).to receive(:ask_options).and_return('merge')
|
175
177
|
subject.send(:merge_method)
|
176
178
|
end
|
177
179
|
|
178
180
|
it 'should be a string' do
|
179
|
-
allow(highline_cli).to receive(:
|
181
|
+
allow(highline_cli).to receive(:ask_options).and_return('merge')
|
180
182
|
expect(subject.send(:merge_method)).to be_a(String)
|
181
183
|
end
|
182
184
|
|
@@ -239,7 +241,7 @@ describe GitHelper::GitHubPullRequest do
|
|
239
241
|
|
240
242
|
describe '#existing_pr' do
|
241
243
|
it 'should call the octokit client' do
|
242
|
-
allow(highline_cli).to receive(:
|
244
|
+
allow(highline_cli).to receive(:ask).and_return(Faker::Number.number)
|
243
245
|
expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
|
244
246
|
subject.send(:existing_pr)
|
245
247
|
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'git_helper'
|
5
|
+
|
6
|
+
describe GitHelper::Setup do
|
7
|
+
let(:response) { double(:response, readline: true, to_s: Faker::Lorem.sentence) }
|
8
|
+
let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
|
12
|
+
allow(subject).to receive(:puts)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
GitHelper::Setup.instance_variable_set('@highline', nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#execute' do
|
20
|
+
it 'should ask a question if the config file exists' do
|
21
|
+
allow(File).to receive(:exists?).and_return(true)
|
22
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
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 call to create or update the config file' do
|
29
|
+
allow(File).to receive(:exists?).and_return(true)
|
30
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
31
|
+
expect(subject).to receive(:create_or_update_config_file).and_return(true)
|
32
|
+
allow(subject).to receive(:create_or_update_plugin_files)
|
33
|
+
subject.execute
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should skip if the user opts not to continue' do
|
37
|
+
allow(File).to receive(:exists?).and_return(true)
|
38
|
+
allow(subject).to receive(:config_file_exists?).and_return(true)
|
39
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
40
|
+
expect(subject).not_to receive(:create_or_update_config_file)
|
41
|
+
expect(subject).not_to receive(:create_or_update_plugin_files)
|
42
|
+
subject.execute
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#create_or_update_config_file' do
|
47
|
+
it 'should generate the file based on the answers to the questions' do
|
48
|
+
expect(subject).to receive(:generate_file_contents)
|
49
|
+
allow(File).to receive(:open).and_return(nil)
|
50
|
+
subject.send(:create_or_update_config_file)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should open the file for writing' do
|
54
|
+
allow(subject).to receive(:generate_file_contents)
|
55
|
+
expect(File).to receive(:open).and_return(nil)
|
56
|
+
subject.send(:create_or_update_config_file)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#config_file_exists?' do
|
61
|
+
it 'should return true if the file exists' do
|
62
|
+
allow(File).to receive(:exist?).and_return(true)
|
63
|
+
expect(subject.send(:config_file_exists?)).to eq(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should return false if the file does not exist' do
|
67
|
+
allow(File).to receive(:exist?).and_return(false)
|
68
|
+
expect(subject.send(:config_file_exists?)).to eq(false)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#ask_question' do
|
73
|
+
it 'should use highline to ask a question' do
|
74
|
+
expect(highline_cli).to receive(:ask).and_return(Faker::Lorem.word)
|
75
|
+
subject.send(:ask_question, Faker::Lorem.sentence)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should recurse if the highline client gets an empty string' do
|
79
|
+
allow(highline_cli).to receive(:ask).and_return('', Faker::Lorem.word)
|
80
|
+
expect(subject).to receive(:ask_question).at_least(:twice).and_call_original
|
81
|
+
subject.send(:ask_question, Faker::Lorem.sentence)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should return the answer if it is given' do
|
85
|
+
answer = Faker::Lorem.sentence
|
86
|
+
allow(highline_cli).to receive(:ask).and_return(answer)
|
87
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#generate_file_contents' do
|
92
|
+
it 'should ask two yes/no questions' do
|
93
|
+
expect(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(false)
|
94
|
+
subject.send(:generate_file_contents)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should ask two additional questions for each time the user says yes' do
|
98
|
+
allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true, false)
|
99
|
+
expect(subject).to receive(:ask_question).exactly(2).times.and_return(Faker::Lorem.word)
|
100
|
+
subject.send(:generate_file_contents)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should ask four additional questions for each time the user says yes' do
|
104
|
+
allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
|
105
|
+
expect(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
|
106
|
+
subject.send(:generate_file_contents)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should return a string no matter what' do
|
110
|
+
allow(highline_cli).to receive(:ask_yes_no).exactly(2).times.and_return(true)
|
111
|
+
allow(subject).to receive(:ask_question).exactly(4).times.and_return(Faker::Lorem.word)
|
112
|
+
expect(subject.send(:generate_file_contents)).to be_a(String)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#create_or_update_plugin_files' do
|
117
|
+
let(:plugins) do
|
118
|
+
[
|
119
|
+
{
|
120
|
+
name: 'plugin-file-one'
|
121
|
+
},
|
122
|
+
{
|
123
|
+
name: 'plugin-file-two'
|
124
|
+
}
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:plugins_json) do
|
129
|
+
"[
|
130
|
+
{
|
131
|
+
\"name\": \"plugin-file-one\"
|
132
|
+
},
|
133
|
+
{
|
134
|
+
\"name\": \"plugin-file-two\"
|
135
|
+
}
|
136
|
+
]"
|
137
|
+
end
|
138
|
+
|
139
|
+
before do
|
140
|
+
allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_token).and_return(Faker::Internet.password)
|
141
|
+
allow_any_instance_of(GitHelper::GitConfigReader).to receive(:github_user).and_return(Faker::Internet.username)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should create the directory if it does not exist' do
|
145
|
+
allow(File).to receive(:exist?).and_return(false)
|
146
|
+
allow(File).to receive(:open).and_return(nil)
|
147
|
+
expect(Dir).to receive(:mkdir)
|
148
|
+
allow(subject).to receive(:`).and_return(plugins_json)
|
149
|
+
allow(JSON).to receive(:parse).and_return(plugins)
|
150
|
+
subject.send(:create_or_update_plugin_files)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should not create the directory if it already exists' do
|
154
|
+
allow(File).to receive(:exist?).and_return(true)
|
155
|
+
allow(File).to receive(:open).and_return(nil)
|
156
|
+
expect(Dir).not_to receive(:mkdir)
|
157
|
+
allow(subject).to receive(:`).and_return(plugins_json)
|
158
|
+
allow(JSON).to receive(:parse).and_return(plugins)
|
159
|
+
subject.send(:create_or_update_plugin_files)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should curl the GitHub API' do
|
163
|
+
allow(Dir).to receive(:mkdir).and_return(true)
|
164
|
+
allow(File).to receive(:exists?).and_return(true)
|
165
|
+
allow(File).to receive(:open).and_return(nil)
|
166
|
+
allow(subject).to receive(:`).and_return(plugins_json)
|
167
|
+
expect(JSON).to receive(:parse).with(plugins_json).and_return(plugins)
|
168
|
+
subject.send(:create_or_update_plugin_files)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should go through the loop for each plugin' do
|
172
|
+
allow(Dir).to receive(:mkdir).and_return(true)
|
173
|
+
allow(File).to receive(:exists?).and_return(true)
|
174
|
+
allow(File).to receive(:open).and_return(nil)
|
175
|
+
expect(subject).to receive(:`).exactly(3).times
|
176
|
+
allow(JSON).to receive(:parse).and_return(plugins)
|
177
|
+
subject.send(:create_or_update_plugin_files)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faker'
|
2
4
|
|
3
5
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
@@ -33,7 +35,7 @@ RSpec.configure do |config|
|
|
33
35
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
36
|
end
|
35
37
|
|
36
|
-
config.filter_run :
|
38
|
+
config.filter_run focus: true
|
37
39
|
config.run_all_when_everything_filtered = true
|
38
40
|
|
39
41
|
# rspec-mocks config goes here. You can use an alternate test double
|
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.2
|
4
|
+
version: 3.3.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: 2021-01
|
11
|
+
date: 2021-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitlab
|
@@ -136,16 +136,30 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.9'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: A set of GitHub and GitLab workflow scripts to provide a smoother development
|
140
154
|
process for your git projects.
|
141
155
|
email:
|
142
|
-
- emma.sax4@gmail.com
|
143
156
|
executables:
|
144
157
|
- git-helper
|
145
158
|
extensions: []
|
146
159
|
extra_rdoc_files: []
|
147
160
|
files:
|
148
161
|
- Gemfile
|
162
|
+
- Gemfile.lock
|
149
163
|
- Guardfile
|
150
164
|
- LICENSE
|
151
165
|
- README.md
|
@@ -166,6 +180,7 @@ files:
|
|
166
180
|
- lib/git_helper/new_branch.rb
|
167
181
|
- lib/git_helper/octokit_client.rb
|
168
182
|
- lib/git_helper/pull_request.rb
|
183
|
+
- lib/git_helper/setup.rb
|
169
184
|
- lib/git_helper/version.rb
|
170
185
|
- plugins.zip
|
171
186
|
- spec/git_helper/change_remote_spec.rb
|
@@ -182,8 +197,9 @@ files:
|
|
182
197
|
- spec/git_helper/new_branch_spec.rb
|
183
198
|
- spec/git_helper/octokit_client_spec.rb
|
184
199
|
- spec/git_helper/pull_request_spec.rb
|
200
|
+
- spec/git_helper/setup_spec.rb
|
185
201
|
- spec/spec_helper.rb
|
186
|
-
homepage: https://github.com/
|
202
|
+
homepage: https://github.com/emmahsax/git_helper
|
187
203
|
licenses:
|
188
204
|
- MIT
|
189
205
|
metadata: {}
|
@@ -195,7 +211,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
195
211
|
requirements:
|
196
212
|
- - ">="
|
197
213
|
- !ruby/object:Gem::Version
|
198
|
-
version: '
|
214
|
+
version: '2.5'
|
199
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
216
|
requirements:
|
201
217
|
- - ">="
|
@@ -222,3 +238,4 @@ test_files:
|
|
222
238
|
- spec/git_helper/new_branch_spec.rb
|
223
239
|
- spec/git_helper/octokit_client_spec.rb
|
224
240
|
- spec/git_helper/pull_request_spec.rb
|
241
|
+
- spec/git_helper/setup_spec.rb
|