git_helper 1.3.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -13
- data/README.md +42 -47
- data/Rakefile +1 -37
- data/bin/git-helper +10 -28
- data/lib/git_helper.rb +3 -5
- data/lib/git_helper/change_remote.rb +53 -40
- data/lib/git_helper/checkout_default.rb +1 -1
- data/lib/git_helper/clean_branches.rb +1 -4
- data/lib/git_helper/code_request.rb +95 -0
- data/lib/git_helper/empty_commit.rb +1 -1
- data/lib/git_helper/forget_local_commits.rb +7 -0
- data/lib/git_helper/git_config_reader.rb +1 -1
- data/lib/git_helper/gitlab_client.rb +0 -1
- data/lib/git_helper/highline_cli.rb +20 -15
- data/lib/git_helper/local_code.rb +75 -23
- data/lib/git_helper/merge_request.rb +45 -74
- data/lib/git_helper/new_branch.rb +2 -13
- data/lib/git_helper/octokit_client.rb +0 -1
- data/lib/git_helper/pull_request.rb +34 -69
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +173 -0
- data/spec/git_helper/checkout_default_spec.rb +19 -0
- data/spec/git_helper/clean_branches_spec.rb +19 -0
- data/spec/git_helper/code_request_spec.rb +259 -0
- data/spec/git_helper/empty_commit_spec.rb +19 -0
- data/spec/git_helper/forget_local_commits_spec.rb +19 -0
- data/spec/git_helper/git_config_reader_spec.rb +60 -0
- data/spec/git_helper/gitlab_client_spec.rb +26 -0
- data/spec/git_helper/highline_cli_spec.rb +215 -0
- data/spec/git_helper/local_code_spec.rb +232 -0
- data/spec/git_helper/merge_request_spec.rb +234 -0
- data/spec/git_helper/new_branch_spec.rb +44 -0
- data/spec/git_helper/octokit_client_spec.rb +26 -0
- data/spec/git_helper/pull_request_spec.rb +246 -0
- data/spec/spec_helper.rb +0 -7
- metadata +41 -24
@@ -1,20 +1,9 @@
|
|
1
|
-
require_relative './highline_cli.rb'
|
2
|
-
require_relative './local_code.rb'
|
3
|
-
|
4
1
|
module GitHelper
|
5
2
|
class NewBranch
|
6
3
|
def execute(new_branch_name = nil)
|
7
|
-
branch_name = new_branch_name ||
|
4
|
+
branch_name = new_branch_name || GitHelper::HighlineCli.new.new_branch_name
|
8
5
|
puts "Attempting to create a new branch: #{branch_name}"
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
private def cli
|
13
|
-
@cli ||= GitHelper::HighlineCli.new
|
14
|
-
end
|
15
|
-
|
16
|
-
private def local_code
|
17
|
-
@local_code ||= GitHelper::LocalCode.new
|
6
|
+
GitHelper::LocalCode.new.new_branch(branch_name)
|
18
7
|
end
|
19
8
|
end
|
20
9
|
end
|
@@ -1,14 +1,19 @@
|
|
1
|
-
require_relative './octokit_client.rb'
|
2
|
-
require_relative './highline_cli.rb'
|
3
|
-
require_relative './local_code.rb'
|
4
|
-
|
5
1
|
module GitHelper
|
6
2
|
class GitHubPullRequest
|
7
|
-
|
3
|
+
attr_accessor :local_repo, :local_branch, :local_code, :cli, :base_branch, :new_pr_title
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@local_repo = options[:local_project]
|
7
|
+
@local_branch = options[:local_branch]
|
8
|
+
@local_code = options[:local_code]
|
9
|
+
@cli = options[:cli]
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(options)
|
13
|
+
@base_branch = options[:base_branch]
|
14
|
+
@new_pr_title = options[:new_title]
|
15
|
+
|
8
16
|
begin
|
9
|
-
# Ask these questions right away
|
10
|
-
base_branch
|
11
|
-
new_pr_title
|
12
17
|
new_pr_body
|
13
18
|
|
14
19
|
puts "Creating pull request: #{new_pr_title}"
|
@@ -31,7 +36,6 @@ module GitHelper
|
|
31
36
|
|
32
37
|
def merge
|
33
38
|
begin
|
34
|
-
# Ask these questions right away
|
35
39
|
pr_id
|
36
40
|
merge_method
|
37
41
|
|
@@ -67,31 +71,37 @@ module GitHelper
|
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
70
|
-
private def
|
71
|
-
@
|
74
|
+
private def new_pr_body
|
75
|
+
@new_pr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
|
72
76
|
end
|
73
77
|
|
74
|
-
private def
|
75
|
-
@
|
76
|
-
|
78
|
+
private def template_name_to_apply
|
79
|
+
return @template_name_to_apply if @template_name_to_apply
|
80
|
+
@template_name_to_apply = nil
|
77
81
|
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
unless pr_template_options.empty?
|
83
|
+
if pr_template_options.count == 1
|
84
|
+
apply_single_template = cli.apply_template?(pr_template_options.first, 'pull')
|
85
|
+
@template_name_to_apply = pr_template_options.first if apply_single_template
|
86
|
+
else
|
87
|
+
response = cli.template_to_apply(pr_template_options, 'pull')
|
88
|
+
@template_name_to_apply = response unless response == 'None'
|
89
|
+
end
|
90
|
+
end
|
81
91
|
|
82
|
-
|
83
|
-
@default_branch ||= local_code.default_branch(local_repo, octokit_client, :octokit)
|
92
|
+
@template_name_to_apply
|
84
93
|
end
|
85
94
|
|
86
95
|
private def pr_template_options
|
87
96
|
@pr_template_options ||= local_code.template_options({
|
88
|
-
|
89
|
-
|
97
|
+
template_directory: '.github',
|
98
|
+
nested_directory_name: 'PULL_REQUEST_TEMPLATE',
|
99
|
+
non_nested_file_name: 'pull_request_template'
|
90
100
|
})
|
91
101
|
end
|
92
102
|
|
93
103
|
private def pr_id
|
94
|
-
@pr_id ||= cli.
|
104
|
+
@pr_id ||= cli.code_request_id('Pull')
|
95
105
|
end
|
96
106
|
|
97
107
|
private def merge_method
|
@@ -107,61 +117,16 @@ module GitHelper
|
|
107
117
|
@merge_options = merge_options
|
108
118
|
end
|
109
119
|
|
110
|
-
private def
|
111
|
-
@
|
112
|
-
autogenerated_title
|
113
|
-
else
|
114
|
-
cli.title
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
private def base_branch
|
119
|
-
@base_branch ||= if cli.base_branch_default?(default_branch)
|
120
|
-
default_branch
|
121
|
-
else
|
122
|
-
cli.base_branch
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
private def new_pr_body
|
127
|
-
@new_pr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
|
128
|
-
end
|
129
|
-
|
130
|
-
private def template_name_to_apply
|
131
|
-
return @template_name_to_apply if @template_name_to_apply
|
132
|
-
@template_name_to_apply = nil
|
133
|
-
|
134
|
-
unless pr_template_options.empty?
|
135
|
-
if pr_template_options.count == 1
|
136
|
-
apply_single_template = cli.apply_template?(pr_template_options.first)
|
137
|
-
@template_name_to_apply = pr_template_options.first if apply_single_template
|
138
|
-
else
|
139
|
-
response = cli.template_to_apply(pr_template_options, 'pull')
|
140
|
-
@template_name_to_apply = response unless response == "None"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
@template_name_to_apply
|
120
|
+
private def existing_project
|
121
|
+
@existing_project ||= octokit_client.repository(local_repo)
|
145
122
|
end
|
146
123
|
|
147
124
|
private def existing_pr
|
148
125
|
@existing_pr ||= octokit_client.pull_request(local_repo, pr_id)
|
149
126
|
end
|
150
127
|
|
151
|
-
private def existing_project
|
152
|
-
@existing_project ||= octokit_client.repository(local_repo)
|
153
|
-
end
|
154
|
-
|
155
128
|
private def octokit_client
|
156
129
|
@octokit_client ||= GitHelper::OctokitClient.new.client
|
157
130
|
end
|
158
|
-
|
159
|
-
private def cli
|
160
|
-
@cli ||= GitHelper::HighlineCli.new
|
161
|
-
end
|
162
|
-
|
163
|
-
private def local_code
|
164
|
-
@local_code ||= GitHelper::LocalCode.new
|
165
|
-
end
|
166
131
|
end
|
167
132
|
end
|
data/lib/git_helper/version.rb
CHANGED
data/plugins.zip
ADDED
Binary file
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::ChangeRemote do
|
5
|
+
let(:remote1) { 'git@github.com:github-username-old/project-1.git' }
|
6
|
+
let(:local_code) do
|
7
|
+
double(:local_code,
|
8
|
+
remotes: [remote1],
|
9
|
+
remote_name: 'origin',
|
10
|
+
ssh_remote?: true,
|
11
|
+
https_remote?: false,
|
12
|
+
remote_project: 'project-1',
|
13
|
+
remote_source: 'github.com',
|
14
|
+
change_remote: true
|
15
|
+
)
|
16
|
+
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
|
+
|
22
|
+
subject { GitHelper::ChangeRemote.new(old_owner, new_owner) }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
|
26
|
+
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#execute' do
|
30
|
+
before do
|
31
|
+
allow(Dir).to receive(:pwd).and_return('/Users/firstname/lastname/path/to/project')
|
32
|
+
allow(Dir).to receive(:entries).and_return(directory_entries)
|
33
|
+
allow(File).to receive(:join).and_return('/Users/firstname/lastname/path/to/project/project-1')
|
34
|
+
allow(File).to receive(:directory?).and_return(true)
|
35
|
+
allow(subject).to receive(:process_dir)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should call to process at least one directory' do
|
39
|
+
expect(subject).to receive(:process_dir).at_least(:once)
|
40
|
+
subject.execute
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should definitely look in the file structure' do
|
44
|
+
expect(Dir).to receive(:pwd)
|
45
|
+
expect(Dir).to receive(:entries)
|
46
|
+
expect(File).to receive(:join)
|
47
|
+
expect(File).to receive(:directory?)
|
48
|
+
subject.execute
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#process_dir' do
|
53
|
+
before do
|
54
|
+
allow(Dir).to receive(:chdir).and_return(nil)
|
55
|
+
allow(File).to receive(:exist?).and_return(true)
|
56
|
+
allow(subject).to receive(:process_git_repository)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should definitely look in the file structure' do
|
60
|
+
expect(Dir).to receive(:chdir)
|
61
|
+
expect(File).to receive(:exist?)
|
62
|
+
subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when the user says to process the directory' do
|
66
|
+
it 'should call to process the git repository at least once' do
|
67
|
+
expect(subject).to receive(:process_git_repository).at_least(:once)
|
68
|
+
subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when the user says not to process the directory' do
|
73
|
+
let(:cli) { double(:highline_cli, process_directory_remotes?: false) }
|
74
|
+
|
75
|
+
it 'should not call to process the directory' do
|
76
|
+
expect(subject).not_to receive(:process_git_repository)
|
77
|
+
subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#process_git_repository' do
|
83
|
+
before do
|
84
|
+
allow(subject).to receive(:process_remote).and_return(nil)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should call local_code' do
|
88
|
+
expect(GitHelper::LocalCode).to receive(:new)
|
89
|
+
subject.send(:process_git_repository)
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when the remote includes the old owner' do
|
93
|
+
it 'should call to process the remote' do
|
94
|
+
expect(subject).to receive(:process_remote)
|
95
|
+
subject.send(:process_git_repository)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when the remote does not include the old owner' do
|
100
|
+
let(:remote1) { 'git@github.com:github-username-new/project-1.git' }
|
101
|
+
|
102
|
+
it 'should not call to process the remote' do
|
103
|
+
expect(subject).not_to receive(:process_remote)
|
104
|
+
subject.send(:process_git_repository)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#process_remote' do
|
110
|
+
it 'should always get the remote name' do
|
111
|
+
expect(local_code).to receive(:remote_name)
|
112
|
+
subject.send(:process_remote, remote1)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should always attempt to change the remote' do
|
116
|
+
expect(local_code).to receive(:change_remote)
|
117
|
+
subject.send(:process_remote, remote1)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should attempt to get the remote repo exactly once' do
|
121
|
+
expect(local_code).to receive(:remote_project).exactly(:once)
|
122
|
+
subject.send(:process_remote, remote1)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should attempt to get the remote source exactly once' do
|
126
|
+
expect(local_code).to receive(:remote_source).exactly(:once)
|
127
|
+
subject.send(:process_remote, remote1)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should ask if the remote is SSH' do
|
131
|
+
expect(local_code).to receive(:ssh_remote?)
|
132
|
+
subject.send(:process_remote, remote1)
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'https remote' do
|
136
|
+
let(:local_code) do
|
137
|
+
double(:local_code,
|
138
|
+
remotes: [remote1],
|
139
|
+
remote_name: 'origin',
|
140
|
+
ssh_remote?: false,
|
141
|
+
https_remote?: false,
|
142
|
+
remote_project: 'project-1',
|
143
|
+
remote_source: 'github.com',
|
144
|
+
change_remote: true
|
145
|
+
)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should ask if the remote is SSH' do
|
149
|
+
expect(local_code).to receive(:ssh_remote?)
|
150
|
+
subject.send(:process_remote, remote1)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'should ask if the remote is https' do
|
154
|
+
expect(local_code).to receive(:https_remote?)
|
155
|
+
subject.send(:process_remote, remote1)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#local_code' do
|
161
|
+
it 'should create a new local code instance' do
|
162
|
+
expect(GitHelper::LocalCode).to receive(:new)
|
163
|
+
subject.send(:local_code)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '#cli' do
|
168
|
+
it 'should create a new highline CLI instance' do
|
169
|
+
expect(GitHelper::HighlineCli).to receive(:new)
|
170
|
+
subject.send(:cli)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::CheckoutDefault do
|
5
|
+
let(:local_code) { double(:local_code, checkout_default: :done) }
|
6
|
+
|
7
|
+
subject { GitHelper::CheckoutDefault.new }
|
8
|
+
|
9
|
+
it 'should call GitHelper::LocalCode' do
|
10
|
+
expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
11
|
+
subject.execute
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should call the checkout_default method from the local code class' do
|
15
|
+
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
16
|
+
expect(local_code).to receive(:checkout_default)
|
17
|
+
subject.execute
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::CleanBranches do
|
5
|
+
let(:local_code) { double(:local_code, clean_branches: :commit) }
|
6
|
+
|
7
|
+
subject { GitHelper::CleanBranches.new }
|
8
|
+
|
9
|
+
it 'should call GitHelper::LocalCode' do
|
10
|
+
expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
11
|
+
subject.execute
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should call the clean_branches method from the local code class' do
|
15
|
+
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
16
|
+
expect(local_code).to receive(:clean_branches)
|
17
|
+
subject.execute
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'git_helper'
|
3
|
+
|
4
|
+
describe GitHelper::CodeRequest do
|
5
|
+
let(:highline_cli) { double(:highline_cli) }
|
6
|
+
let(:local_code) { double(:local_code, project_name: 'name', branch: 'branch') }
|
7
|
+
let(:process_project) { double(:process_project, create: :created, merge: :merged) }
|
8
|
+
|
9
|
+
subject { GitHelper::CodeRequest.new }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
13
|
+
allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#create' do
|
17
|
+
before do
|
18
|
+
allow(subject).to receive(:base_branch).and_return('base')
|
19
|
+
allow(subject).to receive(:new_code_request_title).and_return('Title')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should call to process the project' do
|
23
|
+
expect(subject).to receive(:process_project).and_return(process_project)
|
24
|
+
subject.create
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should call create' do
|
28
|
+
allow(subject).to receive(:process_project).and_return(process_project)
|
29
|
+
expect(process_project).to receive(:create)
|
30
|
+
subject.create
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should call base_branch and new_code_request_title' do
|
34
|
+
expect(subject).to receive(:base_branch).and_return('base')
|
35
|
+
expect(subject).to receive(:new_code_request_title).and_return('Title')
|
36
|
+
allow(subject).to receive(:process_project).and_return(process_project)
|
37
|
+
allow(process_project).to receive(:create)
|
38
|
+
subject.create
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#merge' do
|
43
|
+
it 'should call to process the project' do
|
44
|
+
expect(subject).to receive(:process_project).and_return(process_project)
|
45
|
+
subject.merge
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should call merge' do
|
49
|
+
allow(subject).to receive(:process_project).and_return(process_project)
|
50
|
+
expect(process_project).to receive(:merge)
|
51
|
+
subject.merge
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#process_project' do
|
56
|
+
it 'should call the local code to see if it is a github or gitlab project' do
|
57
|
+
expect(local_code).to receive(:gitlab_project?).and_return(false)
|
58
|
+
expect(local_code).to receive(:github_repo?).and_return(true)
|
59
|
+
subject.send(:process_project)
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when github and gitlab remotes are found' do
|
63
|
+
it 'should ask for clarification' do
|
64
|
+
allow(local_code).to receive(:gitlab_project?).and_return(true)
|
65
|
+
allow(local_code).to receive(:github_repo?).and_return(true)
|
66
|
+
expect(subject).to receive(:ask_for_clarification)
|
67
|
+
subject.send(:process_project)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when github' do
|
72
|
+
it 'should call the github_pull_request' do
|
73
|
+
allow(local_code).to receive(:gitlab_project?).and_return(false)
|
74
|
+
allow(local_code).to receive(:github_repo?).and_return(true)
|
75
|
+
expect(subject).to receive(:github_pull_request)
|
76
|
+
subject.send(:process_project)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when gitlab' do
|
81
|
+
it 'should call the gitlab_merge_request' do
|
82
|
+
allow(local_code).to receive(:gitlab_project?).and_return(true)
|
83
|
+
allow(local_code).to receive(:github_repo?).and_return(false)
|
84
|
+
expect(subject).to receive(:gitlab_merge_request)
|
85
|
+
subject.send(:process_project)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when no github or gitlab remotes are found' do
|
90
|
+
it 'should raise error' do
|
91
|
+
allow(local_code).to receive(:gitlab_project?).and_return(false)
|
92
|
+
allow(local_code).to receive(:github_repo?).and_return(false)
|
93
|
+
expect(subject).to receive(:exit)
|
94
|
+
subject.send(:process_project)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#ask_for_clarification' do
|
100
|
+
it 'should ask the CLI' do
|
101
|
+
expect(highline_cli).to receive(:conflicting_remote_clarification).and_return('github')
|
102
|
+
subject.send(:ask_for_clarification)
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when response is github' do
|
106
|
+
it 'should return github_pull_request' do
|
107
|
+
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('github')
|
108
|
+
expect(subject).to receive(:github_pull_request)
|
109
|
+
subject.send(:ask_for_clarification)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return github_pull_request' do
|
113
|
+
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('Github')
|
114
|
+
expect(subject).to receive(:github_pull_request)
|
115
|
+
subject.send(:ask_for_clarification)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when response is gitlab' do
|
120
|
+
it 'should return gitlab_merge_request' do
|
121
|
+
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('gitlab')
|
122
|
+
expect(subject).to receive(:gitlab_merge_request)
|
123
|
+
subject.send(:ask_for_clarification)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should return gitlab_merge_request' do
|
127
|
+
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('Gitlab')
|
128
|
+
expect(subject).to receive(:gitlab_merge_request)
|
129
|
+
subject.send(:ask_for_clarification)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when response is neither' do
|
134
|
+
it 'should raise an error' do
|
135
|
+
allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('huh?')
|
136
|
+
expect(subject).to receive(:exit)
|
137
|
+
subject.send(:ask_for_clarification)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#github_pull_request' do
|
143
|
+
it 'should call the GitHelper::GitHubPullRequest' do
|
144
|
+
expect(GitHelper::GitHubPullRequest).to receive(:new)
|
145
|
+
subject.send(:github_pull_request)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe '#gitlab_merge_request' do
|
150
|
+
it 'should call the GitHelper::GitLabMergeRequest' do
|
151
|
+
expect(GitHelper::GitLabMergeRequest).to receive(:new)
|
152
|
+
subject.send(:gitlab_merge_request)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#local_project' do
|
157
|
+
it 'should call the name of the local_code' do
|
158
|
+
expect(local_code).to receive(:project_name)
|
159
|
+
subject.send(:local_project)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#default_branch' do
|
164
|
+
it 'should call the name of the local_code' do
|
165
|
+
expect(local_code).to receive(:default_branch)
|
166
|
+
subject.send(:default_branch)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '#base_branch' do
|
171
|
+
it 'should call the default branch' do
|
172
|
+
expect(subject).to receive(:default_branch)
|
173
|
+
allow(highline_cli).to receive(:base_branch_default?).at_least(:once)
|
174
|
+
allow(highline_cli).to receive(:base_branch).at_least(:once).and_return('base')
|
175
|
+
subject.send(:base_branch)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should ask the CLI to ask the user' do
|
179
|
+
allow(subject).to receive(:default_branch)
|
180
|
+
expect(highline_cli).to receive(:base_branch_default?).at_least(:once)
|
181
|
+
allow(highline_cli).to receive(:base_branch).at_least(:once).and_return('base')
|
182
|
+
subject.send(:base_branch)
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'if the user says no' do
|
186
|
+
it "definitely asks for the user's base branch" do
|
187
|
+
allow(subject).to receive(:default_branch)
|
188
|
+
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('base')
|
190
|
+
subject.send(:base_branch)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'if the user says yes' do
|
195
|
+
it "does not ask for the user's base branch" do
|
196
|
+
allow(subject).to receive(:default_branch)
|
197
|
+
expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(true)
|
198
|
+
expect(highline_cli).not_to receive(:base_branch)
|
199
|
+
subject.send(:base_branch)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '#autogenerated_title' do
|
205
|
+
it 'should generate a title based on the branch' do
|
206
|
+
expect(subject).to receive(:local_branch).and_return('branch')
|
207
|
+
expect(local_code).to receive(:generate_title)
|
208
|
+
subject.send(:autogenerated_title)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe '#new_code_request_title' do
|
213
|
+
it 'should call autogenerated title method' do
|
214
|
+
expect(subject).to receive(:autogenerated_title)
|
215
|
+
allow(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
|
216
|
+
allow(highline_cli).to receive(:title).at_least(:once).and_return('Title')
|
217
|
+
subject.send(:new_code_request_title)
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should ask the CLI to ask the user' do
|
221
|
+
allow(subject).to receive(:autogenerated_title)
|
222
|
+
expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
|
223
|
+
allow(highline_cli).to receive(:title).at_least(:once).and_return('Title')
|
224
|
+
subject.send(:new_code_request_title)
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'if the user says no' do
|
228
|
+
it "definitely asks for the user's title" do
|
229
|
+
allow(subject).to receive(:autogenerated_title)
|
230
|
+
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('Title')
|
232
|
+
subject.send(:new_code_request_title)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
context 'if the user says yes to original title' do
|
237
|
+
it "does not ask for the user's chosen title" do
|
238
|
+
allow(subject).to receive(:autogenerated_title)
|
239
|
+
expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(true)
|
240
|
+
expect(highline_cli).not_to receive(:title)
|
241
|
+
subject.send(:new_code_request_title)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#local_code' do
|
247
|
+
it 'should call the octokit client' do
|
248
|
+
expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
|
249
|
+
subject.send(:local_code)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
describe '#cli' do
|
254
|
+
it 'should call the octokit client' do
|
255
|
+
expect(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
|
256
|
+
subject.send(:cli)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|