git_helper 3.0.1 → 3.1.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +23 -15
- data/Guardfile +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/bin/git-helper +3 -3
- data/lib/git_helper.rb +6 -1
- data/lib/git_helper/git_config_reader.rb +0 -2
- data/lib/git_helper/gitlab_client.rb +0 -2
- data/lib/git_helper/highline_cli.rb +0 -2
- data/lib/git_helper/local_code.rb +9 -9
- data/lib/git_helper/octokit_client.rb +0 -2
- data/lib/git_helper/version.rb +1 -1
- data/spec/git_helper/change_remote_spec.rb +17 -15
- data/spec/git_helper/code_request_spec.rb +19 -17
- data/spec/git_helper/git_config_reader_spec.rb +9 -7
- data/spec/git_helper/highline_cli_spec.rb +38 -36
- data/spec/git_helper/local_code_spec.rb +61 -26
- data/spec/git_helper/merge_request_spec.rb +34 -27
- data/spec/git_helper/pull_request_spec.rb +34 -27
- data/spec/spec_helper.rb +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 59ea066ec1e5cc797d676571c908c55fcc6de186590f5f1d1f14bb5f3ebfe1c5
|
|
4
|
+
data.tar.gz: 31c8412273b1e46d5f181e7a01bac5b10858f848293fe287c357f768e41ab90e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 16b7f3b1a77e5a2cae432fcddc556425a18ce88ae6a7147814810af49e42ebe61ca1a82daf691165ef62f7315b10442fcf8c3b458440075b8b767090b5fe560b
|
|
7
|
+
data.tar.gz: dd940ec200f5275c5f07b1b91c5e504bc545b177580ab6c059e64d988438001b186ced83af14a2022e14f9526a0d69fe01989eabd7290bf5378de3560ede5968
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
git_helper (3.0.
|
|
4
|
+
git_helper (3.0.1)
|
|
5
5
|
gitlab (~> 4.16)
|
|
6
6
|
gli (~> 2.13)
|
|
7
7
|
highline (~> 2.0)
|
|
@@ -13,9 +13,13 @@ GEM
|
|
|
13
13
|
addressable (2.7.0)
|
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
|
15
15
|
coderay (1.1.3)
|
|
16
|
+
concurrent-ruby (1.1.7)
|
|
16
17
|
diff-lcs (1.4.4)
|
|
17
|
-
|
|
18
|
+
faker (2.14.0)
|
|
19
|
+
i18n (>= 1.6, < 2)
|
|
20
|
+
faraday (1.1.0)
|
|
18
21
|
multipart-post (>= 1.2, < 3)
|
|
22
|
+
ruby2_keywords
|
|
19
23
|
ffi (1.13.1)
|
|
20
24
|
formatador (0.2.5)
|
|
21
25
|
gitlab (4.16.1)
|
|
@@ -40,6 +44,8 @@ GEM
|
|
|
40
44
|
httparty (0.18.1)
|
|
41
45
|
mime-types (~> 3.0)
|
|
42
46
|
multi_xml (>= 0.5.2)
|
|
47
|
+
i18n (1.8.5)
|
|
48
|
+
concurrent-ruby (~> 1.0)
|
|
43
49
|
listen (3.2.1)
|
|
44
50
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
45
51
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
@@ -47,14 +53,14 @@ GEM
|
|
|
47
53
|
method_source (1.0.0)
|
|
48
54
|
mime-types (3.3.1)
|
|
49
55
|
mime-types-data (~> 3.2015)
|
|
50
|
-
mime-types-data (3.2020.
|
|
56
|
+
mime-types-data (3.2020.1104)
|
|
51
57
|
multi_xml (0.6.0)
|
|
52
58
|
multipart-post (2.1.1)
|
|
53
59
|
nenv (0.3.0)
|
|
54
60
|
notiffany (0.1.3)
|
|
55
61
|
nenv (~> 0.1)
|
|
56
62
|
shellany (~> 0.0)
|
|
57
|
-
octokit (4.
|
|
63
|
+
octokit (4.19.0)
|
|
58
64
|
faraday (>= 0.9)
|
|
59
65
|
sawyer (~> 0.8.0, >= 0.5.3)
|
|
60
66
|
pry (0.13.1)
|
|
@@ -65,19 +71,20 @@ GEM
|
|
|
65
71
|
rb-fsevent (0.10.4)
|
|
66
72
|
rb-inotify (0.10.1)
|
|
67
73
|
ffi (~> 1.0)
|
|
68
|
-
rspec (3.
|
|
69
|
-
rspec-core (~> 3.
|
|
70
|
-
rspec-expectations (~> 3.
|
|
71
|
-
rspec-mocks (~> 3.
|
|
72
|
-
rspec-core (3.
|
|
73
|
-
rspec-support (~> 3.
|
|
74
|
-
rspec-expectations (3.
|
|
74
|
+
rspec (3.10.0)
|
|
75
|
+
rspec-core (~> 3.10.0)
|
|
76
|
+
rspec-expectations (~> 3.10.0)
|
|
77
|
+
rspec-mocks (~> 3.10.0)
|
|
78
|
+
rspec-core (3.10.0)
|
|
79
|
+
rspec-support (~> 3.10.0)
|
|
80
|
+
rspec-expectations (3.10.0)
|
|
75
81
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
|
-
rspec-support (~> 3.
|
|
77
|
-
rspec-mocks (3.
|
|
82
|
+
rspec-support (~> 3.10.0)
|
|
83
|
+
rspec-mocks (3.10.0)
|
|
78
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
79
|
-
rspec-support (~> 3.
|
|
80
|
-
rspec-support (3.
|
|
85
|
+
rspec-support (~> 3.10.0)
|
|
86
|
+
rspec-support (3.10.0)
|
|
87
|
+
ruby2_keywords (0.0.2)
|
|
81
88
|
sawyer (0.8.2)
|
|
82
89
|
addressable (>= 2.3.5)
|
|
83
90
|
faraday (> 0.8, < 2.0)
|
|
@@ -92,6 +99,7 @@ PLATFORMS
|
|
|
92
99
|
|
|
93
100
|
DEPENDENCIES
|
|
94
101
|
bundler (~> 2.1)
|
|
102
|
+
faker
|
|
95
103
|
git_helper!
|
|
96
104
|
guard-rspec (~> 4.3)
|
|
97
105
|
rake (~> 13.0)
|
data/Guardfile
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# git_helper [](https://codeclimate.com/github/emmasax4/git_helper/maintainability) ](https://codeclimate.com/github/emmasax4/git_helper/maintainability) 
|
|
2
2
|
|
|
3
3
|
## Gem Usage
|
|
4
4
|
|
data/Rakefile
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/git-helper
CHANGED
|
@@ -27,7 +27,7 @@ command 'change-remote' do |c|
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
desc
|
|
30
|
+
desc 'Checks out the default branch of a repo based on the local remote branches.'
|
|
31
31
|
command 'checkout-default' do |c|
|
|
32
32
|
c.action do |global_options, options, args|
|
|
33
33
|
GitHelper::CheckoutDefault.new.execute
|
|
@@ -41,14 +41,14 @@ command 'clean-branches' do |c|
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
desc
|
|
44
|
+
desc 'Creates an empty commit with a basic commit message.'
|
|
45
45
|
command 'empty-commit' do |c|
|
|
46
46
|
c.action do |global_options, options, args|
|
|
47
47
|
GitHelper::EmptyCommit.new.execute
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
desc
|
|
51
|
+
desc 'Reset your local git commits to origin/HEAD.'
|
|
52
52
|
command 'forget-local-commits' do |c|
|
|
53
53
|
c.action do |global_options, options, args|
|
|
54
54
|
GitHelper::ForgetLocalCommits.new.execute
|
data/lib/git_helper.rb
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
require 'yaml'
|
|
2
|
+
require 'gitlab'
|
|
3
|
+
require 'highline'
|
|
4
|
+
require 'octokit'
|
|
5
|
+
|
|
6
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + '/**/*.rb'].each do |file|
|
|
2
7
|
require_relative file
|
|
3
8
|
end
|
|
4
9
|
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
module GitHelper
|
|
2
2
|
class LocalCode
|
|
3
3
|
def checkout_default
|
|
4
|
-
system(
|
|
4
|
+
system('git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")')
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def forget_local_commits
|
|
8
|
-
system(
|
|
9
|
-
system(
|
|
8
|
+
system('git pull')
|
|
9
|
+
system('git reset --hard origin/HEAD')
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def empty_commit
|
|
13
|
-
system(
|
|
13
|
+
system('git commit --allow-empty -m \"Empty commit\"')
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def clean_branches
|
|
17
|
-
system(
|
|
18
|
-
system(
|
|
19
|
-
system(
|
|
20
|
-
system(
|
|
17
|
+
system('git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")')
|
|
18
|
+
system('git pull')
|
|
19
|
+
system('git fetch -p')
|
|
20
|
+
system('git branch -vv | grep "origin/.*: gone]" | awk "{print \$1}" | grep -v "*" | xargs git branch -D')
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def new_branch(branch_name)
|
|
24
|
-
system(
|
|
24
|
+
system('git pull')
|
|
25
25
|
system("git branch --no-track #{branch_name}")
|
|
26
26
|
system("git checkout #{branch_name}")
|
|
27
27
|
system("git push --set-upstream origin #{branch_name}")
|
data/lib/git_helper/version.rb
CHANGED
|
@@ -2,22 +2,24 @@ require 'spec_helper'
|
|
|
2
2
|
require 'git_helper'
|
|
3
3
|
|
|
4
4
|
describe GitHelper::ChangeRemote do
|
|
5
|
-
let(:remote1) {
|
|
5
|
+
let(:remote1) { "git@github.com:#{old_owner}/#{project}.git" }
|
|
6
|
+
let(:project) { Faker::Lorem.word }
|
|
7
|
+
let(:cli) { double(:highline_cli, process_directory_remotes?: true) }
|
|
8
|
+
let(:old_owner) { Faker::Internet.username }
|
|
9
|
+
let(:new_owner) { Faker::Internet.username }
|
|
10
|
+
let(:directory_entries) { [ '.', '..', project, Faker::Lorem.word, Faker::Lorem.word ] }
|
|
11
|
+
|
|
6
12
|
let(:local_code) do
|
|
7
13
|
double(:local_code,
|
|
8
14
|
remotes: [remote1],
|
|
9
|
-
remote_name:
|
|
15
|
+
remote_name: Faker::Lorem.word,
|
|
10
16
|
ssh_remote?: true,
|
|
11
17
|
https_remote?: false,
|
|
12
|
-
remote_project:
|
|
18
|
+
remote_project: project,
|
|
13
19
|
remote_source: 'github.com',
|
|
14
20
|
change_remote: true
|
|
15
21
|
)
|
|
16
22
|
end
|
|
17
|
-
let(:cli) { double(:highline_cli, process_directory_remotes?: true) }
|
|
18
|
-
let(:old_owner) { 'github-username-old' }
|
|
19
|
-
let(:new_owner) { 'github-username-new' }
|
|
20
|
-
let(:directory_entries) { [ '.', '..', 'project-1', 'project-2', 'project-3' ] }
|
|
21
23
|
|
|
22
24
|
subject { GitHelper::ChangeRemote.new(old_owner, new_owner) }
|
|
23
25
|
|
|
@@ -28,9 +30,9 @@ describe GitHelper::ChangeRemote do
|
|
|
28
30
|
|
|
29
31
|
describe '#execute' do
|
|
30
32
|
before do
|
|
31
|
-
allow(Dir).to receive(:pwd).and_return(
|
|
33
|
+
allow(Dir).to receive(:pwd).and_return("/Users/#{Faker::Name.first_name}/#{project}")
|
|
32
34
|
allow(Dir).to receive(:entries).and_return(directory_entries)
|
|
33
|
-
allow(File).to receive(:join).and_return(
|
|
35
|
+
allow(File).to receive(:join).and_return("/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
|
|
34
36
|
allow(File).to receive(:directory?).and_return(true)
|
|
35
37
|
allow(subject).to receive(:process_dir)
|
|
36
38
|
end
|
|
@@ -59,13 +61,13 @@ describe GitHelper::ChangeRemote do
|
|
|
59
61
|
it 'should definitely look in the file structure' do
|
|
60
62
|
expect(Dir).to receive(:chdir)
|
|
61
63
|
expect(File).to receive(:exist?)
|
|
62
|
-
subject.send(:process_dir,
|
|
64
|
+
subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
context 'when the user says to process the directory' do
|
|
66
68
|
it 'should call to process the git repository at least once' do
|
|
67
69
|
expect(subject).to receive(:process_git_repository).at_least(:once)
|
|
68
|
-
subject.send(:process_dir,
|
|
70
|
+
subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
|
|
@@ -74,7 +76,7 @@ describe GitHelper::ChangeRemote do
|
|
|
74
76
|
|
|
75
77
|
it 'should not call to process the directory' do
|
|
76
78
|
expect(subject).not_to receive(:process_git_repository)
|
|
77
|
-
subject.send(:process_dir,
|
|
79
|
+
subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
|
|
78
80
|
end
|
|
79
81
|
end
|
|
80
82
|
end
|
|
@@ -97,7 +99,7 @@ describe GitHelper::ChangeRemote do
|
|
|
97
99
|
end
|
|
98
100
|
|
|
99
101
|
context 'when the remote does not include the old owner' do
|
|
100
|
-
let(:remote1) {
|
|
102
|
+
let(:remote1) { "git@github.com:#{new_owner}/#{project}.git" }
|
|
101
103
|
|
|
102
104
|
it 'should not call to process the remote' do
|
|
103
105
|
expect(subject).not_to receive(:process_remote)
|
|
@@ -136,10 +138,10 @@ describe GitHelper::ChangeRemote do
|
|
|
136
138
|
let(:local_code) do
|
|
137
139
|
double(:local_code,
|
|
138
140
|
remotes: [remote1],
|
|
139
|
-
remote_name:
|
|
141
|
+
remote_name: Faker::Lorem.word,
|
|
140
142
|
ssh_remote?: false,
|
|
141
143
|
https_remote?: false,
|
|
142
|
-
remote_project:
|
|
144
|
+
remote_project: project,
|
|
143
145
|
remote_source: 'github.com',
|
|
144
146
|
change_remote: true
|
|
145
147
|
)
|
|
@@ -3,8 +3,10 @@ require 'git_helper'
|
|
|
3
3
|
|
|
4
4
|
describe GitHelper::CodeRequest do
|
|
5
5
|
let(:highline_cli) { double(:highline_cli) }
|
|
6
|
-
let(:local_code) { double(:local_code, project_name:
|
|
6
|
+
let(:local_code) { double(:local_code, project_name: Faker::Lorem.word, branch: Faker::Lorem.word) }
|
|
7
7
|
let(:process_project) { double(:process_project, create: :created, merge: :merged) }
|
|
8
|
+
let(:base_branch) { Faker::Lorem.word }
|
|
9
|
+
let(:title) { Faker::Lorem.sentence }
|
|
8
10
|
|
|
9
11
|
subject { GitHelper::CodeRequest.new }
|
|
10
12
|
|
|
@@ -15,8 +17,8 @@ describe GitHelper::CodeRequest do
|
|
|
15
17
|
|
|
16
18
|
describe '#create' do
|
|
17
19
|
before do
|
|
18
|
-
allow(subject).to receive(:base_branch).and_return(
|
|
19
|
-
allow(subject).to receive(:new_code_request_title).and_return(
|
|
20
|
+
allow(subject).to receive(:base_branch).and_return(base_branch)
|
|
21
|
+
allow(subject).to receive(:new_code_request_title).and_return(title)
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
it 'should call to process the project' do
|
|
@@ -31,8 +33,8 @@ describe GitHelper::CodeRequest do
|
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
it 'should call base_branch and new_code_request_title' do
|
|
34
|
-
expect(subject).to receive(:base_branch).and_return(
|
|
35
|
-
expect(subject).to receive(:new_code_request_title).and_return(
|
|
36
|
+
expect(subject).to receive(:base_branch).and_return(base_branch)
|
|
37
|
+
expect(subject).to receive(:new_code_request_title).and_return(title)
|
|
36
38
|
allow(subject).to receive(:process_project).and_return(process_project)
|
|
37
39
|
allow(process_project).to receive(:create)
|
|
38
40
|
subject.create
|
|
@@ -132,7 +134,7 @@ describe GitHelper::CodeRequest do
|
|
|
132
134
|
|
|
133
135
|
context 'when response is neither' do
|
|
134
136
|
it 'should raise an error' do
|
|
135
|
-
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return(
|
|
137
|
+
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return(Faker::Lorem.word)
|
|
136
138
|
expect(subject).to receive(:exit)
|
|
137
139
|
subject.send(:ask_for_clarification)
|
|
138
140
|
end
|
|
@@ -171,28 +173,28 @@ describe GitHelper::CodeRequest do
|
|
|
171
173
|
it 'should call the default branch' do
|
|
172
174
|
expect(subject).to receive(:default_branch)
|
|
173
175
|
allow(highline_cli).to receive(:base_branch_default?).at_least(:once)
|
|
174
|
-
allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(
|
|
176
|
+
allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
|
|
175
177
|
subject.send(:base_branch)
|
|
176
178
|
end
|
|
177
179
|
|
|
178
180
|
it 'should ask the CLI to ask the user' do
|
|
179
181
|
allow(subject).to receive(:default_branch)
|
|
180
182
|
expect(highline_cli).to receive(:base_branch_default?).at_least(:once)
|
|
181
|
-
allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(
|
|
183
|
+
allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
|
|
182
184
|
subject.send(:base_branch)
|
|
183
185
|
end
|
|
184
186
|
|
|
185
187
|
context 'if the user says no' do
|
|
186
|
-
it
|
|
188
|
+
it 'definitely asks for the users base branch' do
|
|
187
189
|
allow(subject).to receive(:default_branch)
|
|
188
190
|
expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(false)
|
|
189
|
-
expect(highline_cli).to receive(:base_branch).at_least(:once).and_return(
|
|
191
|
+
expect(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
|
|
190
192
|
subject.send(:base_branch)
|
|
191
193
|
end
|
|
192
194
|
end
|
|
193
195
|
|
|
194
196
|
context 'if the user says yes' do
|
|
195
|
-
it
|
|
197
|
+
it 'does not ask for the users base branch' do
|
|
196
198
|
allow(subject).to receive(:default_branch)
|
|
197
199
|
expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(true)
|
|
198
200
|
expect(highline_cli).not_to receive(:base_branch)
|
|
@@ -203,7 +205,7 @@ describe GitHelper::CodeRequest do
|
|
|
203
205
|
|
|
204
206
|
describe '#autogenerated_title' do
|
|
205
207
|
it 'should generate a title based on the branch' do
|
|
206
|
-
expect(subject).to receive(:local_branch).and_return(
|
|
208
|
+
expect(subject).to receive(:local_branch).and_return(Faker::Lorem.word)
|
|
207
209
|
expect(local_code).to receive(:generate_title)
|
|
208
210
|
subject.send(:autogenerated_title)
|
|
209
211
|
end
|
|
@@ -213,28 +215,28 @@ describe GitHelper::CodeRequest do
|
|
|
213
215
|
it 'should call autogenerated title method' do
|
|
214
216
|
expect(subject).to receive(:autogenerated_title)
|
|
215
217
|
allow(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
|
|
216
|
-
allow(highline_cli).to receive(:title).at_least(:once).and_return(
|
|
218
|
+
allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
|
|
217
219
|
subject.send(:new_code_request_title)
|
|
218
220
|
end
|
|
219
221
|
|
|
220
222
|
it 'should ask the CLI to ask the user' do
|
|
221
223
|
allow(subject).to receive(:autogenerated_title)
|
|
222
224
|
expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
|
|
223
|
-
allow(highline_cli).to receive(:title).at_least(:once).and_return(
|
|
225
|
+
allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
|
|
224
226
|
subject.send(:new_code_request_title)
|
|
225
227
|
end
|
|
226
228
|
|
|
227
229
|
context 'if the user says no' do
|
|
228
|
-
it
|
|
230
|
+
it 'definitely asks for the users title' do
|
|
229
231
|
allow(subject).to receive(:autogenerated_title)
|
|
230
232
|
expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(false)
|
|
231
|
-
expect(highline_cli).to receive(:title).at_least(:once).and_return(
|
|
233
|
+
expect(highline_cli).to receive(:title).at_least(:once).and_return(title)
|
|
232
234
|
subject.send(:new_code_request_title)
|
|
233
235
|
end
|
|
234
236
|
end
|
|
235
237
|
|
|
236
238
|
context 'if the user says yes to original title' do
|
|
237
|
-
it
|
|
239
|
+
it 'does not ask for the users chosen title' do
|
|
238
240
|
allow(subject).to receive(:autogenerated_title)
|
|
239
241
|
expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(true)
|
|
240
242
|
expect(highline_cli).not_to receive(:title)
|
|
@@ -2,13 +2,14 @@ require 'spec_helper'
|
|
|
2
2
|
require 'git_helper'
|
|
3
3
|
|
|
4
4
|
describe GitHelper::GitConfigReader do
|
|
5
|
-
let(:github_token) {
|
|
6
|
-
let(:gitlab_token) {
|
|
5
|
+
let(:github_token) { Faker::Internet.password(max_length: 10) }
|
|
6
|
+
let(:gitlab_token) { Faker::Internet.password(max_length: 10) }
|
|
7
|
+
|
|
7
8
|
let(:config_file) {
|
|
8
9
|
{
|
|
9
|
-
github_user:
|
|
10
|
+
github_user: Faker::Internet.username,
|
|
10
11
|
github_token: github_token,
|
|
11
|
-
gitlab_user:
|
|
12
|
+
gitlab_user: Faker::Internet.username,
|
|
12
13
|
gitlab_token: gitlab_token
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -48,13 +49,14 @@ describe GitHelper::GitConfigReader do
|
|
|
48
49
|
|
|
49
50
|
describe '#git_config_file_path' do
|
|
50
51
|
it 'should look in the current directory' do
|
|
51
|
-
expect(Dir).to receive(:pwd).and_return(
|
|
52
|
+
expect(Dir).to receive(:pwd).and_return("/Users/#{Faker::Name.first_name}/#{Faker::Lorem.word}")
|
|
52
53
|
subject.send(:git_config_file_path)
|
|
53
54
|
end
|
|
54
55
|
|
|
55
56
|
it 'should return the base path with the git config file at the end' do
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
user = Faker::Name.first_name
|
|
58
|
+
allow(Dir).to receive(:pwd).and_return("/Users/#{user}/#{Faker::Lorem.word}")
|
|
59
|
+
expect(subject.send(:git_config_file_path)).to eq("/Users/#{user}/.git_helper/config.yml")
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
end
|
|
@@ -12,7 +12,7 @@ describe GitHelper::HighlineCli do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
describe '#new_branch_name' do
|
|
15
|
-
it
|
|
15
|
+
it 'should ask the subjects ask method' do
|
|
16
16
|
expect(subject).to receive(:ask).with('New branch name?')
|
|
17
17
|
subject.new_branch_name
|
|
18
18
|
end
|
|
@@ -23,34 +23,34 @@ describe GitHelper::HighlineCli do
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
describe '#process_directory_remotes' do
|
|
26
|
-
it
|
|
26
|
+
it 'should ask the subjects ask method' do
|
|
27
27
|
expect(subject).to receive(:ask).and_return('y')
|
|
28
|
-
subject.process_directory_remotes?(
|
|
28
|
+
subject.process_directory_remotes?(Faker::Lorem.word)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it 'should be a boolean at the end' do
|
|
32
32
|
allow(subject).to receive(:ask).and_return('y')
|
|
33
|
-
expect([true, false]).to include(subject.process_directory_remotes?(
|
|
33
|
+
expect([true, false]).to include(subject.process_directory_remotes?(Faker::Lorem.word))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it 'should come out as a true boolean if somebody responds y' do
|
|
37
37
|
allow(subject).to receive(:ask).and_return('y')
|
|
38
|
-
expect(subject.process_directory_remotes?(
|
|
38
|
+
expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(true)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
it 'should come out as a false boolean if somebody responds n' do
|
|
42
42
|
allow(subject).to receive(:ask).and_return('n')
|
|
43
|
-
expect(subject.process_directory_remotes?(
|
|
43
|
+
expect(subject.process_directory_remotes?(Faker::Lorem.word)).to eq(false)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it 'should come out as true if somebody presses enter' do
|
|
47
47
|
allow(subject).to receive(:ask).and_return('')
|
|
48
|
-
expect(subject.accept_autogenerated_title?(
|
|
48
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.word)).to eq(true)
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
describe '#conflicting_remote_clarification' do
|
|
53
|
-
it
|
|
53
|
+
it 'should ask the subjects ask method' do
|
|
54
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
55
|
subject.conflicting_remote_clarification
|
|
56
56
|
end
|
|
@@ -61,7 +61,7 @@ describe GitHelper::HighlineCli do
|
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
describe '#title' do
|
|
64
|
-
it
|
|
64
|
+
it 'should ask the subjects ask method' do
|
|
65
65
|
expect(subject).to receive(:ask).with('Title?')
|
|
66
66
|
subject.title
|
|
67
67
|
end
|
|
@@ -72,7 +72,7 @@ describe GitHelper::HighlineCli do
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
describe '#base_branch' do
|
|
75
|
-
it
|
|
75
|
+
it 'should ask the subjects ask method' do
|
|
76
76
|
expect(subject).to receive(:ask).with('Base branch?')
|
|
77
77
|
subject.base_branch
|
|
78
78
|
end
|
|
@@ -83,92 +83,94 @@ describe GitHelper::HighlineCli do
|
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
describe '#code_request_id' do
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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)
|
|
89
91
|
end
|
|
90
92
|
|
|
91
93
|
it 'should come out a string' do
|
|
92
|
-
expect(subject.code_request_id(
|
|
94
|
+
expect(subject.code_request_id(phrase)).to be_a(String)
|
|
93
95
|
end
|
|
94
96
|
end
|
|
95
97
|
|
|
96
98
|
describe '#accept_autogenerated_title' do
|
|
97
|
-
it
|
|
99
|
+
it 'should ask the subjects ask method' do
|
|
98
100
|
expect(subject).to receive(:ask).and_return('y')
|
|
99
|
-
subject.accept_autogenerated_title?(
|
|
101
|
+
subject.accept_autogenerated_title?(Faker::Lorem.sentence)
|
|
100
102
|
end
|
|
101
103
|
|
|
102
104
|
it 'should be a boolean at the end' do
|
|
103
105
|
allow(subject).to receive(:ask).and_return('y')
|
|
104
|
-
expect([true, false]).to include(subject.accept_autogenerated_title?(
|
|
106
|
+
expect([true, false]).to include(subject.accept_autogenerated_title?(Faker::Lorem.sentence))
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
it 'should come out as a true boolean if somebody responds y' do
|
|
108
110
|
allow(subject).to receive(:ask).and_return('y')
|
|
109
|
-
expect(subject.accept_autogenerated_title?(
|
|
111
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
|
110
112
|
end
|
|
111
113
|
|
|
112
114
|
it 'should come out as a true boolean if somebody responds n' do
|
|
113
115
|
allow(subject).to receive(:ask).and_return('n')
|
|
114
|
-
expect(subject.accept_autogenerated_title?(
|
|
116
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
|
|
115
117
|
end
|
|
116
118
|
|
|
117
119
|
it 'should come out as a true boolean if somebody responds yes' do
|
|
118
120
|
allow(subject).to receive(:ask).and_return('yes')
|
|
119
|
-
expect(subject.accept_autogenerated_title?(
|
|
121
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
|
120
122
|
end
|
|
121
123
|
|
|
122
124
|
it 'should come out as a false boolean if somebody responds no' do
|
|
123
125
|
allow(subject).to receive(:ask).and_return('no')
|
|
124
|
-
expect(subject.accept_autogenerated_title?(
|
|
126
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(false)
|
|
125
127
|
end
|
|
126
128
|
|
|
127
129
|
it 'should come out as true if somebody presses enter' do
|
|
128
130
|
allow(subject).to receive(:ask).and_return('')
|
|
129
|
-
expect(subject.accept_autogenerated_title?(
|
|
131
|
+
expect(subject.accept_autogenerated_title?(Faker::Lorem.sentence)).to eq(true)
|
|
130
132
|
end
|
|
131
133
|
end
|
|
132
134
|
|
|
133
135
|
describe '#base_branch_default' do
|
|
134
|
-
it
|
|
136
|
+
it 'should ask the subjects ask method' do
|
|
135
137
|
expect(subject).to receive(:ask).and_return('y')
|
|
136
|
-
subject.base_branch_default?(
|
|
138
|
+
subject.base_branch_default?(Faker::Lorem.word)
|
|
137
139
|
end
|
|
138
140
|
|
|
139
141
|
it 'should be a boolean at the end' do
|
|
140
142
|
allow(subject).to receive(:ask).and_return('y')
|
|
141
|
-
expect([true, false]).to include(subject.base_branch_default?(
|
|
143
|
+
expect([true, false]).to include(subject.base_branch_default?(Faker::Lorem.word))
|
|
142
144
|
end
|
|
143
145
|
|
|
144
146
|
it 'should come out as a true boolean if somebody responds y' do
|
|
145
147
|
allow(subject).to receive(:ask).and_return('y')
|
|
146
|
-
expect(subject.base_branch_default?(
|
|
148
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
|
147
149
|
end
|
|
148
150
|
|
|
149
151
|
it 'should come out as a true boolean if somebody responds n' do
|
|
150
152
|
allow(subject).to receive(:ask).and_return('n')
|
|
151
|
-
expect(subject.base_branch_default?(
|
|
153
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
|
|
152
154
|
end
|
|
153
155
|
|
|
154
156
|
it 'should come out as a true boolean if somebody responds yes' do
|
|
155
157
|
allow(subject).to receive(:ask).and_return('yes')
|
|
156
|
-
expect(subject.base_branch_default?(
|
|
158
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
|
157
159
|
end
|
|
158
160
|
|
|
159
161
|
it 'should come out as a false boolean if somebody responds no' do
|
|
160
162
|
allow(subject).to receive(:ask).and_return('no')
|
|
161
|
-
expect(subject.base_branch_default?(
|
|
163
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(false)
|
|
162
164
|
end
|
|
163
165
|
|
|
164
166
|
it 'should come out as true if somebody presses enter' do
|
|
165
167
|
allow(subject).to receive(:ask).and_return('')
|
|
166
|
-
expect(subject.base_branch_default?(
|
|
168
|
+
expect(subject.base_branch_default?(Faker::Lorem.word)).to eq(true)
|
|
167
169
|
end
|
|
168
170
|
end
|
|
169
171
|
|
|
170
172
|
describe '#merge_method' do
|
|
171
|
-
it
|
|
173
|
+
it 'should ask the subjects ask_options method' do
|
|
172
174
|
expect(subject).to receive(:ask_options).and_return(3)
|
|
173
175
|
subject.merge_method(['1', '2', '3'])
|
|
174
176
|
end
|
|
@@ -180,7 +182,7 @@ describe GitHelper::HighlineCli do
|
|
|
180
182
|
end
|
|
181
183
|
|
|
182
184
|
describe '#template_to_apply' do
|
|
183
|
-
it
|
|
185
|
+
it 'should ask the subjects ask_options method' do
|
|
184
186
|
expect(subject).to receive(:ask_options).and_return(3)
|
|
185
187
|
subject.template_to_apply(['option1', 'option2', 'option3'], 'example type')
|
|
186
188
|
end
|
|
@@ -194,22 +196,22 @@ describe GitHelper::HighlineCli do
|
|
|
194
196
|
describe '#ask' do
|
|
195
197
|
it 'should ask the highline client ask'do
|
|
196
198
|
expect(highline_client).to receive(:ask)
|
|
197
|
-
subject.send(:ask,
|
|
199
|
+
subject.send(:ask, Faker::Lorem.sentence)
|
|
198
200
|
end
|
|
199
201
|
|
|
200
202
|
it 'should return a string' do
|
|
201
|
-
expect(subject.send(:ask,
|
|
203
|
+
expect(subject.send(:ask, Faker::Lorem.sentence)).to be_a(String)
|
|
202
204
|
end
|
|
203
205
|
end
|
|
204
206
|
|
|
205
207
|
describe '#ask_options' do
|
|
206
208
|
it 'should ask the highline client ask'do
|
|
207
209
|
expect(highline_client).to receive(:ask)
|
|
208
|
-
subject.send(:ask_options,
|
|
210
|
+
subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])
|
|
209
211
|
end
|
|
210
212
|
|
|
211
213
|
it 'should return an integer' do
|
|
212
|
-
expect(subject.send(:ask_options,
|
|
214
|
+
expect(subject.send(:ask_options, Faker::Lorem.sentence, ['1', '2', '3'])).to be_a(Integer)
|
|
213
215
|
end
|
|
214
216
|
end
|
|
215
217
|
end
|
|
@@ -4,11 +4,24 @@ require 'git_helper'
|
|
|
4
4
|
describe GitHelper::LocalCode do
|
|
5
5
|
let(:response) { double(:response, readline: true, to_i: 5) }
|
|
6
6
|
let(:local_codeent) { double(:local_code, ask: response) }
|
|
7
|
-
let(:
|
|
8
|
-
let(:
|
|
9
|
-
let(:
|
|
10
|
-
let(:
|
|
7
|
+
let(:project_name) { Faker::Lorem.word }
|
|
8
|
+
let(:owner) { Faker::Name.first_name }
|
|
9
|
+
let(:ssh_remote) { "origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)" }
|
|
10
|
+
let(:https_remote) { "origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)" }
|
|
11
|
+
|
|
12
|
+
let(:github_remotes) do
|
|
13
|
+
[
|
|
14
|
+
"origin\tgit@github.com:#{owner}/#{project_name}.git (fetch)",
|
|
15
|
+
"origin\thttps://github.com/#{owner}/#{project_name}.git (fetch)"
|
|
16
|
+
]
|
|
17
|
+
end
|
|
11
18
|
|
|
19
|
+
let(:gitlab_remotes) do
|
|
20
|
+
[
|
|
21
|
+
"origin\tgit@gitlab.com:#{owner}/#{project_name}.git (fetch)",
|
|
22
|
+
"origin\thttps://gitlab.com/#{owner}/#{project_name}.git (fetch)"
|
|
23
|
+
]
|
|
24
|
+
end
|
|
12
25
|
|
|
13
26
|
subject { GitHelper::LocalCode.new }
|
|
14
27
|
|
|
@@ -51,13 +64,13 @@ describe GitHelper::LocalCode do
|
|
|
51
64
|
describe '#new_branch' do
|
|
52
65
|
it 'should make a system call' do
|
|
53
66
|
expect(subject).to receive(:system).exactly(4).times
|
|
54
|
-
subject.new_branch(
|
|
67
|
+
subject.new_branch(Faker::Lorem.word)
|
|
55
68
|
end
|
|
56
69
|
end
|
|
57
70
|
|
|
58
71
|
describe '#change_remote' do
|
|
59
72
|
it 'should return a string' do
|
|
60
|
-
expect(subject.change_remote(
|
|
73
|
+
expect(subject.change_remote(Faker::Lorem.word, Faker::Internet.url)).to be_a(String)
|
|
61
74
|
end
|
|
62
75
|
end
|
|
63
76
|
|
|
@@ -96,11 +109,11 @@ describe GitHelper::LocalCode do
|
|
|
96
109
|
|
|
97
110
|
describe '#remote_project' do
|
|
98
111
|
it 'should return just the plain project if ssh' do
|
|
99
|
-
expect(subject.remote_project(ssh_remote)).to eq(
|
|
112
|
+
expect(subject.remote_project(ssh_remote)).to eq(project_name)
|
|
100
113
|
end
|
|
101
114
|
|
|
102
115
|
it 'should return just the plain project if https' do
|
|
103
|
-
expect(subject.remote_project(https_remote)).to eq(
|
|
116
|
+
expect(subject.remote_project(https_remote)).to eq(project_name)
|
|
104
117
|
end
|
|
105
118
|
end
|
|
106
119
|
|
|
@@ -144,8 +157,8 @@ describe GitHelper::LocalCode do
|
|
|
144
157
|
end
|
|
145
158
|
|
|
146
159
|
it 'should equal this project name' do
|
|
147
|
-
allow_any_instance_of(String).to receive(:scan).and_return([[
|
|
148
|
-
expect(subject.project_name).to eq(
|
|
160
|
+
allow_any_instance_of(String).to receive(:scan).and_return([["#{owner}/#{project_name}"]])
|
|
161
|
+
expect(subject.project_name).to eq("#{owner}/#{project_name}")
|
|
149
162
|
end
|
|
150
163
|
end
|
|
151
164
|
|
|
@@ -190,43 +203,65 @@ describe GitHelper::LocalCode do
|
|
|
190
203
|
|
|
191
204
|
describe '#generate_title' do
|
|
192
205
|
it 'should return a title based on the branch' do
|
|
193
|
-
|
|
194
|
-
|
|
206
|
+
prefix = Faker::Lorem.word
|
|
207
|
+
word1 = Faker::Lorem.word
|
|
208
|
+
word2 = Faker::Lorem.word
|
|
209
|
+
description = [word1, word2].join('-')
|
|
210
|
+
branch = "#{prefix}-123-#{description}"
|
|
211
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
|
195
212
|
end
|
|
196
213
|
|
|
197
214
|
it 'should return a title based on the branch' do
|
|
198
|
-
|
|
199
|
-
|
|
215
|
+
prefix = Faker::Lorem.word
|
|
216
|
+
word1 = Faker::Lorem.word
|
|
217
|
+
word2 = Faker::Lorem.word
|
|
218
|
+
description = [word1, word2].join('_')
|
|
219
|
+
branch = "#{prefix}_123_#{description}"
|
|
220
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
|
200
221
|
end
|
|
201
222
|
|
|
202
223
|
it 'should return a title based on the branch' do
|
|
203
|
-
|
|
204
|
-
|
|
224
|
+
prefix = Faker::Lorem.word
|
|
225
|
+
word1 = Faker::Lorem.word
|
|
226
|
+
word2 = Faker::Lorem.word
|
|
227
|
+
description = [word1, word2].join('_')
|
|
228
|
+
branch = "#{prefix}-123_#{description}"
|
|
229
|
+
expect(subject.generate_title(branch)).to eq("#{prefix.upcase}-123 #{[word1.capitalize, word2].join(' ')}")
|
|
205
230
|
end
|
|
206
231
|
|
|
207
232
|
it 'should return a title based on the branch' do
|
|
208
|
-
|
|
209
|
-
|
|
233
|
+
word1 = Faker::Lorem.word
|
|
234
|
+
word2 = Faker::Lorem.word
|
|
235
|
+
branch = [word1, word2].join('_')
|
|
236
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
|
|
210
237
|
end
|
|
211
238
|
|
|
212
239
|
it 'should return a title based on the branch' do
|
|
213
|
-
|
|
214
|
-
|
|
240
|
+
word1 = Faker::Lorem.word
|
|
241
|
+
word2 = Faker::Lorem.word
|
|
242
|
+
branch = [word1, word2].join('-')
|
|
243
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2].join(' '))
|
|
215
244
|
end
|
|
216
245
|
|
|
217
246
|
it 'should return a title based on the branch' do
|
|
218
|
-
branch =
|
|
219
|
-
expect(subject.generate_title(branch)).to eq(
|
|
247
|
+
branch = Faker::Lorem.word
|
|
248
|
+
expect(subject.generate_title(branch)).to eq(branch.capitalize)
|
|
220
249
|
end
|
|
221
250
|
|
|
222
251
|
it 'should return a title based on the branch' do
|
|
223
|
-
|
|
224
|
-
|
|
252
|
+
word1 = Faker::Lorem.word
|
|
253
|
+
word2 = Faker::Lorem.word
|
|
254
|
+
word3 = Faker::Lorem.word
|
|
255
|
+
branch = [word1, word2, word3].join('_')
|
|
256
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
|
|
225
257
|
end
|
|
226
258
|
|
|
227
259
|
it 'should return a title based on the branch' do
|
|
228
|
-
|
|
229
|
-
|
|
260
|
+
word1 = Faker::Lorem.word
|
|
261
|
+
word2 = Faker::Lorem.word
|
|
262
|
+
word3 = Faker::Lorem.word
|
|
263
|
+
branch = [word1, word2, word3].join('-')
|
|
264
|
+
expect(subject.generate_title(branch)).to eq([word1.capitalize, word2, word3].join(' '))
|
|
230
265
|
end
|
|
231
266
|
end
|
|
232
267
|
end
|
|
@@ -2,20 +2,21 @@ require 'spec_helper'
|
|
|
2
2
|
require 'git_helper'
|
|
3
3
|
|
|
4
4
|
describe GitHelper::GitLabMergeRequest do
|
|
5
|
-
let(:local_code) { double(:local_code, read_template:
|
|
5
|
+
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
|
6
6
|
let(:highline_cli) { double(:highline_cli) }
|
|
7
7
|
let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
|
8
8
|
let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
|
|
9
|
+
|
|
9
10
|
let(:options) do
|
|
10
11
|
{
|
|
11
|
-
local_project:
|
|
12
|
-
local_branch:
|
|
12
|
+
local_project: Faker::Lorem.word,
|
|
13
|
+
local_branch: Faker::Lorem.word,
|
|
13
14
|
local_code: local_code,
|
|
14
15
|
cli: highline_cli
|
|
15
16
|
}
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
subject {
|
|
19
|
+
subject { described_class.new(options) }
|
|
19
20
|
|
|
20
21
|
before do
|
|
21
22
|
allow(GitHelper::GitLabClient).to receive(:new).and_return(gitlab_client)
|
|
@@ -27,7 +28,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
27
28
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
|
28
29
|
allow(subject).to receive(:new_mr_body).and_return('')
|
|
29
30
|
expect(gitlab_client_client).to receive(:create_merge_request)
|
|
30
|
-
subject.create({base_branch:
|
|
31
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
it 'should call various other methods' do
|
|
@@ -35,7 +36,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
35
36
|
expect(subject).to receive(:remove_source_branch).and_return(false)
|
|
36
37
|
expect(subject).to receive(:new_mr_body).and_return('')
|
|
37
38
|
allow(gitlab_client_client).to receive(:create_merge_request)
|
|
38
|
-
subject.create({base_branch:
|
|
39
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
it 'should catch the raised error if the creation does not work' do
|
|
@@ -43,35 +44,35 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
43
44
|
allow(subject).to receive(:remove_source_branch).and_return(false)
|
|
44
45
|
allow(subject).to receive(:new_mr_body).and_return('')
|
|
45
46
|
allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
|
|
46
|
-
expect(subject.create({base_branch:
|
|
47
|
+
expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
|
|
47
48
|
end
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
describe '#merge' do
|
|
51
52
|
it 'should call the gitlab client to merge' do
|
|
52
53
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
|
53
|
-
allow(subject).to receive(:mr_id).and_return(
|
|
54
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
|
54
55
|
expect(gitlab_client_client).to receive(:accept_merge_request)
|
|
55
56
|
subject.merge
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
it 'should call various other methods' do
|
|
59
60
|
expect(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title')).at_least(:once)
|
|
60
|
-
expect(subject).to receive(:mr_id).and_return(
|
|
61
|
+
expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
|
|
61
62
|
allow(gitlab_client_client).to receive(:accept_merge_request)
|
|
62
63
|
subject.merge
|
|
63
64
|
end
|
|
64
65
|
|
|
65
66
|
it 'should catch the raised error if the merge does not work' do
|
|
66
67
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
|
67
|
-
allow(subject).to receive(:mr_id).and_return(
|
|
68
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
|
68
69
|
allow(gitlab_client_client).to receive(:accept_merge_request).and_raise(StandardError)
|
|
69
70
|
expect(subject.merge).to eq(nil)
|
|
70
71
|
end
|
|
71
72
|
|
|
72
73
|
it 'should try to merge multiple times if the first merge errors' do
|
|
73
74
|
allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
|
|
74
|
-
allow(subject).to receive(:mr_id).and_return(
|
|
75
|
+
allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
|
|
75
76
|
expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil)).exactly(2).times
|
|
76
77
|
expect(subject.merge).to eq(nil)
|
|
77
78
|
end
|
|
@@ -105,40 +106,45 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
105
106
|
end
|
|
106
107
|
|
|
107
108
|
context 'if there is one template option' do
|
|
109
|
+
let(:template) { Faker::Lorem.word }
|
|
110
|
+
|
|
108
111
|
it 'should call the CLI to ask about a single template' do
|
|
109
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
|
112
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
|
110
113
|
expect(highline_cli).to receive(:apply_template?).and_return(true)
|
|
111
114
|
subject.send(:template_name_to_apply)
|
|
112
115
|
end
|
|
113
116
|
|
|
114
117
|
it 'should return the single template if the user says yes' do
|
|
115
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
|
118
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
|
116
119
|
allow(highline_cli).to receive(:apply_template?).and_return(true)
|
|
117
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
|
120
|
+
expect(subject.send(:template_name_to_apply)).to eq(template)
|
|
118
121
|
end
|
|
119
122
|
|
|
120
123
|
it 'should return nil if the user says no' do
|
|
121
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
|
124
|
+
allow(subject).to receive(:mr_template_options).and_return([template])
|
|
122
125
|
allow(highline_cli).to receive(:apply_template?).and_return(false)
|
|
123
126
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
|
124
127
|
end
|
|
125
128
|
end
|
|
126
129
|
|
|
127
130
|
context 'if there are multiple template options' do
|
|
131
|
+
let(:template1) { Faker::Lorem.word }
|
|
132
|
+
let(:template2) { Faker::Lorem.word }
|
|
133
|
+
|
|
128
134
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
|
129
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
|
130
|
-
expect(highline_cli).to receive(:template_to_apply).and_return(
|
|
135
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
|
136
|
+
expect(highline_cli).to receive(:template_to_apply).and_return(template1)
|
|
131
137
|
subject.send(:template_name_to_apply)
|
|
132
138
|
end
|
|
133
139
|
|
|
134
140
|
it 'should return the answer template if the user says yes' do
|
|
135
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
|
136
|
-
allow(highline_cli).to receive(:template_to_apply).and_return(
|
|
137
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
|
141
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
|
142
|
+
allow(highline_cli).to receive(:template_to_apply).and_return(template1)
|
|
143
|
+
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
|
138
144
|
end
|
|
139
145
|
|
|
140
146
|
it 'should return nil if the user says no' do
|
|
141
|
-
allow(subject).to receive(:mr_template_options).and_return([
|
|
147
|
+
allow(subject).to receive(:mr_template_options).and_return([template1, template2])
|
|
142
148
|
allow(highline_cli).to receive(:template_to_apply).and_return('None')
|
|
143
149
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
|
144
150
|
end
|
|
@@ -154,13 +160,14 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
154
160
|
|
|
155
161
|
describe '#mr_id' do
|
|
156
162
|
it 'should ask the CLI for the code request ID' do
|
|
157
|
-
expect(highline_cli).to receive(:code_request_id).and_return(
|
|
163
|
+
expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
|
158
164
|
subject.send(:mr_id)
|
|
159
165
|
end
|
|
160
166
|
|
|
161
167
|
it 'should equal an integer' do
|
|
162
|
-
|
|
163
|
-
expect(
|
|
168
|
+
pr_id = Faker::Number.number
|
|
169
|
+
expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
|
|
170
|
+
expect(subject.send(:mr_id)).to eq(pr_id)
|
|
164
171
|
end
|
|
165
172
|
end
|
|
166
173
|
|
|
@@ -198,12 +205,12 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
198
205
|
subject.send(:remove_source_branch)
|
|
199
206
|
end
|
|
200
207
|
|
|
201
|
-
it
|
|
208
|
+
it 'should return the existing projects setting if it exists' do
|
|
202
209
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: true))
|
|
203
210
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
|
204
211
|
end
|
|
205
212
|
|
|
206
|
-
it
|
|
213
|
+
it 'should return the existing projects setting if it exists' do
|
|
207
214
|
allow(subject).to receive(:existing_project).and_return(double(remove_source_branch_after_merge: false))
|
|
208
215
|
allow(highline_cli).to receive(:remove_source_branch?).and_return(true)
|
|
209
216
|
expect(subject.send(:remove_source_branch)).to eq(true)
|
|
@@ -219,7 +226,7 @@ describe GitHelper::GitLabMergeRequest do
|
|
|
219
226
|
|
|
220
227
|
describe '#existing_mr' do
|
|
221
228
|
it 'should call the gitlab client' do
|
|
222
|
-
allow(highline_cli).to receive(:code_request_id).and_return(
|
|
229
|
+
allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
|
223
230
|
expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
|
|
224
231
|
subject.send(:existing_mr)
|
|
225
232
|
end
|
|
@@ -2,14 +2,15 @@ require 'spec_helper'
|
|
|
2
2
|
require 'git_helper'
|
|
3
3
|
|
|
4
4
|
describe GitHelper::GitHubPullRequest do
|
|
5
|
-
let(:local_code) { double(:local_code, read_template:
|
|
5
|
+
let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
|
|
6
6
|
let(:highline_cli) { double(:highline_cli) }
|
|
7
7
|
let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
|
|
8
8
|
let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
|
|
9
|
+
|
|
9
10
|
let(:options) do
|
|
10
11
|
{
|
|
11
|
-
local_project:
|
|
12
|
-
local_branch:
|
|
12
|
+
local_project: Faker::Lorem.word,
|
|
13
|
+
local_branch: Faker::Lorem.word,
|
|
13
14
|
local_code: local_code,
|
|
14
15
|
cli: highline_cli
|
|
15
16
|
}
|
|
@@ -25,43 +26,43 @@ describe GitHelper::GitHubPullRequest do
|
|
|
25
26
|
it 'should call the octokit client to create' do
|
|
26
27
|
allow(subject).to receive(:new_pr_body).and_return('')
|
|
27
28
|
expect(octokit_client_client).to receive(:create_pull_request)
|
|
28
|
-
subject.create({base_branch:
|
|
29
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
it 'should call various other methods' do
|
|
32
33
|
expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
|
|
33
34
|
allow(octokit_client_client).to receive(:create_pull_request)
|
|
34
|
-
subject.create({base_branch:
|
|
35
|
+
subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
it 'should catch the raised error if the creation does not work' do
|
|
38
39
|
allow(subject).to receive(:new_pr_body).and_return('')
|
|
39
40
|
allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
|
|
40
|
-
expect(subject.create({base_branch:
|
|
41
|
+
expect(subject.create({base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word})).to eq(nil)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
describe '#merge' do
|
|
45
46
|
it 'should call the octokit client to merge' do
|
|
46
|
-
allow(subject).to receive(:existing_pr).and_return(double(title:
|
|
47
|
+
allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
|
|
47
48
|
allow(subject).to receive(:merge_method).and_return('rebase')
|
|
48
|
-
allow(subject).to receive(:pr_id).and_return(
|
|
49
|
+
allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
|
|
49
50
|
expect(octokit_client_client).to receive(:merge_pull_request)
|
|
50
51
|
subject.merge
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
it 'should call various other methods' do
|
|
54
|
-
expect(subject).to receive(:existing_pr).and_return(double(title:
|
|
55
|
+
expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
|
|
55
56
|
expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
|
|
56
|
-
expect(subject).to receive(:pr_id).and_return(
|
|
57
|
+
expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
|
|
57
58
|
allow(octokit_client_client).to receive(:merge_pull_request)
|
|
58
59
|
subject.merge
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
it 'should catch the raised error if the merge does not work' do
|
|
62
|
-
allow(subject).to receive(:existing_pr).and_return(double(title:
|
|
63
|
+
allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
|
|
63
64
|
allow(subject).to receive(:merge_method).and_return('rebase')
|
|
64
|
-
allow(subject).to receive(:pr_id).and_return(
|
|
65
|
+
allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
|
|
65
66
|
allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
|
|
66
67
|
expect(subject.merge).to eq(nil)
|
|
67
68
|
end
|
|
@@ -95,40 +96,45 @@ describe GitHelper::GitHubPullRequest do
|
|
|
95
96
|
end
|
|
96
97
|
|
|
97
98
|
context 'if there is one template option' do
|
|
99
|
+
let(:template) { Faker::Lorem.word }
|
|
100
|
+
|
|
98
101
|
it 'should call the CLI to ask about a single template' do
|
|
99
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
|
102
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
|
100
103
|
expect(highline_cli).to receive(:apply_template?).and_return(true)
|
|
101
104
|
subject.send(:template_name_to_apply)
|
|
102
105
|
end
|
|
103
106
|
|
|
104
107
|
it 'should return the single template if the user says yes' do
|
|
105
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
|
108
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
|
106
109
|
allow(highline_cli).to receive(:apply_template?).and_return(true)
|
|
107
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
|
110
|
+
expect(subject.send(:template_name_to_apply)).to eq(template)
|
|
108
111
|
end
|
|
109
112
|
|
|
110
113
|
it 'should return nil if the user says no' do
|
|
111
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
|
114
|
+
allow(subject).to receive(:pr_template_options).and_return([template])
|
|
112
115
|
allow(highline_cli).to receive(:apply_template?).and_return(false)
|
|
113
116
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
|
114
117
|
end
|
|
115
118
|
end
|
|
116
119
|
|
|
117
120
|
context 'if there are multiple template options' do
|
|
121
|
+
let(:template1) { Faker::Lorem.word }
|
|
122
|
+
let(:template2) { Faker::Lorem.word }
|
|
123
|
+
|
|
118
124
|
it 'should call the CLI to ask which of multiple templates to apply' do
|
|
119
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
|
120
|
-
expect(highline_cli).to receive(:template_to_apply).and_return(
|
|
125
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
|
126
|
+
expect(highline_cli).to receive(:template_to_apply).and_return(template1)
|
|
121
127
|
subject.send(:template_name_to_apply)
|
|
122
128
|
end
|
|
123
129
|
|
|
124
130
|
it 'should return the answer template if the user says yes' do
|
|
125
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
|
126
|
-
allow(highline_cli).to receive(:template_to_apply).and_return(
|
|
127
|
-
expect(subject.send(:template_name_to_apply)).to eq(
|
|
131
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
|
132
|
+
allow(highline_cli).to receive(:template_to_apply).and_return(template1)
|
|
133
|
+
expect(subject.send(:template_name_to_apply)).to eq(template1)
|
|
128
134
|
end
|
|
129
135
|
|
|
130
136
|
it 'should return nil if the user says no' do
|
|
131
|
-
allow(subject).to receive(:pr_template_options).and_return([
|
|
137
|
+
allow(subject).to receive(:pr_template_options).and_return([template1, template2])
|
|
132
138
|
allow(highline_cli).to receive(:template_to_apply).and_return('None')
|
|
133
139
|
expect(subject.send(:template_name_to_apply)).to eq(nil)
|
|
134
140
|
end
|
|
@@ -144,13 +150,14 @@ describe GitHelper::GitHubPullRequest do
|
|
|
144
150
|
|
|
145
151
|
describe '#pr_id' do
|
|
146
152
|
it 'should ask the CLI for the code request ID' do
|
|
147
|
-
expect(highline_cli).to receive(:code_request_id).and_return(
|
|
153
|
+
expect(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
|
148
154
|
subject.send(:pr_id)
|
|
149
155
|
end
|
|
150
156
|
|
|
151
157
|
it 'should equal an integer' do
|
|
152
|
-
|
|
153
|
-
expect(
|
|
158
|
+
pr_id = Faker::Number.number
|
|
159
|
+
expect(highline_cli).to receive(:code_request_id).and_return(pr_id)
|
|
160
|
+
expect(subject.send(:pr_id)).to eq(pr_id)
|
|
154
161
|
end
|
|
155
162
|
end
|
|
156
163
|
|
|
@@ -172,7 +179,7 @@ describe GitHelper::GitHubPullRequest do
|
|
|
172
179
|
expect(subject.send(:merge_method)).to be_a(String)
|
|
173
180
|
end
|
|
174
181
|
|
|
175
|
-
context
|
|
182
|
+
context 'if theres only one item' do
|
|
176
183
|
let(:project) { double(:project, allow_merge_commit: true, allow_squash_merge: false, allow_rebase_merge: false) }
|
|
177
184
|
|
|
178
185
|
it 'should not ask the CLI anything' do
|
|
@@ -231,7 +238,7 @@ describe GitHelper::GitHubPullRequest do
|
|
|
231
238
|
|
|
232
239
|
describe '#existing_pr' do
|
|
233
240
|
it 'should call the octokit client' do
|
|
234
|
-
allow(highline_cli).to receive(:code_request_id).and_return(
|
|
241
|
+
allow(highline_cli).to receive(:code_request_id).and_return(Faker::Number.number)
|
|
235
242
|
expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
|
|
236
243
|
subject.send(:existing_pr)
|
|
237
244
|
end
|
data/spec/spec_helper.rb
CHANGED
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.0
|
|
4
|
+
version: 3.1.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-
|
|
11
|
+
date: 2020-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gitlab
|
|
@@ -80,6 +80,20 @@ dependencies:
|
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '2.1'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: faker
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
83
97
|
- !ruby/object:Gem::Dependency
|
|
84
98
|
name: guard-rspec
|
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|