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,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitHelper
|
2
4
|
class NewBranch
|
3
5
|
def execute(new_branch_name = nil)
|
4
|
-
branch_name = new_branch_name || GitHelper::HighlineCli.new.
|
6
|
+
branch_name = new_branch_name || GitHelper::HighlineCli.new.ask('New branch name?')
|
5
7
|
puts "Attempting to create a new branch: #{branch_name}"
|
6
8
|
GitHelper::LocalCode.new.new_branch(branch_name)
|
7
9
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitHelper
|
2
4
|
class GitHubPullRequest
|
3
5
|
attr_accessor :local_repo, :local_branch, :local_code, :cli, :base_branch, :new_pr_title
|
@@ -9,67 +11,79 @@ module GitHelper
|
|
9
11
|
@cli = options[:cli]
|
10
12
|
end
|
11
13
|
|
14
|
+
# rubocop:disable Metrics/MethodLength
|
15
|
+
# rubocop:disable Metrics/AbcSize
|
12
16
|
def create(options)
|
13
17
|
@base_branch = options[:base_branch]
|
14
18
|
@new_pr_title = options[:new_title]
|
15
19
|
|
16
|
-
|
17
|
-
new_pr_body
|
20
|
+
new_pr_body
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
puts "Creating pull request: #{new_pr_title}"
|
23
|
+
pr = octokit_client.create_pull_request(
|
24
|
+
local_repo,
|
25
|
+
base_branch,
|
26
|
+
local_branch,
|
27
|
+
new_pr_title,
|
28
|
+
new_pr_body
|
29
|
+
)
|
30
|
+
puts "Pull request successfully created: #{pr.html_url}"
|
31
|
+
rescue Octokit::UnprocessableEntity => e
|
32
|
+
puts 'Could not create pull request:'
|
33
|
+
if e.message.include?('pull request already exists')
|
34
|
+
puts ' A pull request already exists for this branch'
|
35
|
+
elsif e.message.include?('No commits between')
|
36
|
+
puts ' No commits have been pushed to GitHub'
|
37
|
+
else
|
33
38
|
puts e.message
|
34
39
|
end
|
40
|
+
rescue StandardError => e
|
41
|
+
puts 'Could not create pull request:'
|
42
|
+
puts e.message
|
35
43
|
end
|
44
|
+
# rubocop:enable Metrics/AbcSize
|
45
|
+
# rubocop:enable Metrics/MethodLength
|
36
46
|
|
47
|
+
# rubocop:disable Metrics/MethodLength
|
48
|
+
# rubocop:disable Metrics/AbcSize
|
37
49
|
def merge
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
rescue Exception => e
|
69
|
-
puts 'Could not merge pull request:'
|
50
|
+
pr_id
|
51
|
+
merge_method
|
52
|
+
|
53
|
+
puts "Merging pull request: #{pr_id}"
|
54
|
+
merge = octokit_client.merge_pull_request(
|
55
|
+
local_repo,
|
56
|
+
pr_id,
|
57
|
+
existing_pr.title,
|
58
|
+
{ merge_method: merge_method }
|
59
|
+
)
|
60
|
+
puts "Pull request successfully merged: #{merge.sha}"
|
61
|
+
rescue Octokit::NotFound
|
62
|
+
puts 'Could not merge pull request:'
|
63
|
+
puts " Could not a locate a pull request to merge with ID #{pr_id}"
|
64
|
+
rescue Octokit::MethodNotAllowed => e
|
65
|
+
puts 'Could not merge pull request:'
|
66
|
+
if e.message.include?('405 - Required status check')
|
67
|
+
puts ' A required status check has not passed'
|
68
|
+
elsif e.message.include?('405 - Base branch was modified')
|
69
|
+
puts ' The base branch has been modified'
|
70
|
+
elsif e.message.include?('405 - Pull Request is not mergeable')
|
71
|
+
puts ' The pull request is not mergeable'
|
72
|
+
elsif e.message.include?('405 - Rebase merges are not allowed on this repository')
|
73
|
+
puts ' Rebase merges are not allowed on this repository'
|
74
|
+
elsif e.message.include?('405 - Merge commits are not allowed on this repository')
|
75
|
+
puts ' Merge commits are not allowed on this repository'
|
76
|
+
elsif e.message.include?('405 - Squash commits are not allowed on this repository')
|
77
|
+
puts ' Squash merges are not allowed on this repository'
|
78
|
+
else
|
70
79
|
puts e.message
|
71
80
|
end
|
81
|
+
rescue StandardError => e
|
82
|
+
puts 'Could not merge pull request:'
|
83
|
+
puts e.message
|
72
84
|
end
|
85
|
+
# rubocop:enable Metrics/AbcSize
|
86
|
+
# rubocop:enable Metrics/MethodLength
|
73
87
|
|
74
88
|
private def new_pr_body
|
75
89
|
@new_pr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
|
@@ -77,39 +91,56 @@ module GitHelper
|
|
77
91
|
|
78
92
|
private def template_name_to_apply
|
79
93
|
return @template_name_to_apply if @template_name_to_apply
|
94
|
+
|
80
95
|
@template_name_to_apply = nil
|
81
96
|
|
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
|
97
|
+
determine_template unless pr_template_options.empty?
|
91
98
|
|
92
99
|
@template_name_to_apply
|
93
100
|
end
|
94
101
|
|
102
|
+
# rubocop:disable Metrics/MethodLength
|
103
|
+
private def determine_template
|
104
|
+
if pr_template_options.count == 1
|
105
|
+
apply_single_template = cli.ask_yes_no(
|
106
|
+
"Apply the pull request template from #{pr_template_options.first}? (y/n)"
|
107
|
+
)
|
108
|
+
@template_name_to_apply = pr_template_options.first if apply_single_template
|
109
|
+
else
|
110
|
+
response = cli.ask_options(
|
111
|
+
'Which pull request template should be applied?', pr_template_options << 'None'
|
112
|
+
)
|
113
|
+
@template_name_to_apply = response unless response == 'None'
|
114
|
+
end
|
115
|
+
end
|
116
|
+
# rubocop:enable Metrics/MethodLength
|
117
|
+
|
95
118
|
private def pr_template_options
|
96
|
-
@pr_template_options ||= local_code.template_options(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
119
|
+
@pr_template_options ||= local_code.template_options(
|
120
|
+
{
|
121
|
+
template_directory: '.github',
|
122
|
+
nested_directory_name: 'PULL_REQUEST_TEMPLATE',
|
123
|
+
non_nested_file_name: 'pull_request_template'
|
124
|
+
}
|
125
|
+
)
|
101
126
|
end
|
102
127
|
|
103
128
|
private def pr_id
|
104
|
-
@pr_id ||= cli.
|
129
|
+
@pr_id ||= cli.ask('Pull Request ID?')
|
105
130
|
end
|
106
131
|
|
107
132
|
private def merge_method
|
108
|
-
@merge_method ||=
|
133
|
+
@merge_method ||=
|
134
|
+
if merge_options.length == 1
|
135
|
+
merge_options.first
|
136
|
+
else
|
137
|
+
cli.ask_options('Merge method?', merge_options)
|
138
|
+
end
|
109
139
|
end
|
110
140
|
|
111
141
|
private def merge_options
|
112
142
|
return @merge_options if @merge_options
|
143
|
+
|
113
144
|
merge_options = []
|
114
145
|
merge_options << 'merge' if existing_project.allow_merge_commit
|
115
146
|
merge_options << 'squash' if existing_project.allow_squash_merge
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitHelper
|
4
|
+
class Setup
|
5
|
+
def execute
|
6
|
+
execute_config_file
|
7
|
+
execute_plugins
|
8
|
+
end
|
9
|
+
|
10
|
+
private def execute_config_file
|
11
|
+
if config_file_exists?
|
12
|
+
answer = highline.ask_yes_no(
|
13
|
+
"It looks like the #{config_file} file already exists. Do you wish to replace it? (y/n)"
|
14
|
+
)
|
15
|
+
puts
|
16
|
+
else
|
17
|
+
answer = true
|
18
|
+
end
|
19
|
+
|
20
|
+
create_or_update_config_file if answer
|
21
|
+
end
|
22
|
+
|
23
|
+
private def execute_plugins
|
24
|
+
answer = highline.ask_yes_no(
|
25
|
+
'Do you wish to set up the Git Helper plugins? (y/n) (This process will ' \
|
26
|
+
'attempt to use your GitHub personal access token to authenticate)'
|
27
|
+
)
|
28
|
+
|
29
|
+
return unless answer
|
30
|
+
|
31
|
+
create_or_update_plugin_files
|
32
|
+
puts "\nNow add this line to your ~/.bash_profile:\n" \
|
33
|
+
' export PATH=/path/to/computer/home/.git_helper/plugins:$PATH'
|
34
|
+
puts "\nDone!"
|
35
|
+
end
|
36
|
+
|
37
|
+
private def create_or_update_config_file
|
38
|
+
contents = generate_file_contents
|
39
|
+
puts "\nCreating or updating your #{config_file} file..."
|
40
|
+
File.open(config_file, 'w') { |file| file.puts contents }
|
41
|
+
puts "\nDone!\n\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
private def config_file_exists?
|
45
|
+
File.exist?(config_file)
|
46
|
+
end
|
47
|
+
|
48
|
+
# rubocop:disable Metrics/MethodLength
|
49
|
+
private def generate_file_contents
|
50
|
+
file_contents = ''.dup
|
51
|
+
|
52
|
+
if highline.ask_yes_no('Do you wish to set up GitHub credentials? (y/n)')
|
53
|
+
file_contents << ":github_user: #{ask_question('GitHub username?')}\n"
|
54
|
+
file_contents << ':github_token: ' \
|
55
|
+
"#{ask_question('GitHub personal access token? (Navigate to https://github.com/settings/tokens ' \
|
56
|
+
'to create a new personal access token)')}\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
if highline.ask_yes_no("\nDo you wish to set up GitLab credentials? (y/n)")
|
60
|
+
file_contents << ":gitlab_user: #{ask_question('GitLab username?')}\n"
|
61
|
+
file_contents << ':gitlab_token: ' \
|
62
|
+
"#{ask_question(
|
63
|
+
'GitLab personal access token? (Navigate to https://gitlab.com/-/profile/personal_access_tokens' \
|
64
|
+
' to create a new personal access token)'
|
65
|
+
)}\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
file_contents.strip
|
69
|
+
end
|
70
|
+
# rubocop:enable Metrics/MethodLength
|
71
|
+
|
72
|
+
private def ask_question(prompt)
|
73
|
+
answer = highline.ask("\n#{prompt}")
|
74
|
+
|
75
|
+
if answer.empty?
|
76
|
+
puts "\nThis question is required."
|
77
|
+
ask_question(prompt)
|
78
|
+
else
|
79
|
+
answer
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# rubocop:disable Metrics/MethodLength
|
84
|
+
# rubocop:disable Metrics/AbcSize
|
85
|
+
private def create_or_update_plugin_files
|
86
|
+
plugins_dir = "#{Dir.pwd.scan(%r{\A/\w*/\w*/}).first}.git_helper/plugins"
|
87
|
+
plugins_url = 'https://api.github.com/repos/emmahsax/git_helper/contents/plugins'
|
88
|
+
header = 'Accept: application/vnd.github.v3.raw'
|
89
|
+
token = git_config_reader.github_token
|
90
|
+
user = git_config_reader.github_user
|
91
|
+
|
92
|
+
Dir.mkdir(plugins_dir) unless File.exist?(plugins_dir)
|
93
|
+
|
94
|
+
all_plugins = JSON.parse(`curl -s -u #{user}:#{token} -H "#{header}" -L "#{plugins_url}"`)
|
95
|
+
|
96
|
+
all_plugins.each do |plugin|
|
97
|
+
plugin_content = `curl -s -u #{user}:#{token} -H "#{header}" -L "#{plugins_url}/#{plugin['name']}"`
|
98
|
+
File.open("#{plugins_dir}/#{plugin['name']}", 'w') { |file| file.puts plugin_content }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
# rubocop:enable Metrics/MethodLength
|
102
|
+
# rubocop:enable Metrics/AbcSize
|
103
|
+
|
104
|
+
private def config_file
|
105
|
+
git_config_reader.git_config_file_path
|
106
|
+
end
|
107
|
+
|
108
|
+
private def git_config_reader
|
109
|
+
@git_config_reader ||= GitHelper::GitConfigReader.new
|
110
|
+
end
|
111
|
+
|
112
|
+
private def highline
|
113
|
+
@highline ||= GitHelper::HighlineCli.new
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/git_helper/version.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'git_helper'
|
3
5
|
|
4
6
|
describe GitHelper::ChangeRemote do
|
5
7
|
let(:remote1) { "git@github.com:#{old_owner}/#{project}.git" }
|
6
8
|
let(:project) { Faker::Lorem.word }
|
7
|
-
let(:cli) { double(:highline_cli,
|
9
|
+
let(:cli) { double(:highline_cli, ask_yes_no: true) }
|
8
10
|
let(:old_owner) { Faker::Internet.username }
|
9
11
|
let(:new_owner) { Faker::Internet.username }
|
10
|
-
let(:directory_entries) { [
|
12
|
+
let(:directory_entries) { ['.', '..', project, Faker::Lorem.word, Faker::Lorem.word] }
|
11
13
|
|
12
14
|
let(:local_code) do
|
13
15
|
double(:local_code,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
)
|
16
|
+
remotes: [remote1],
|
17
|
+
remote_name: Faker::Lorem.word,
|
18
|
+
ssh_remote?: true,
|
19
|
+
https_remote?: false,
|
20
|
+
remote_project: project,
|
21
|
+
remote_source: 'github.com',
|
22
|
+
change_remote: true)
|
22
23
|
end
|
23
24
|
|
24
25
|
subject { GitHelper::ChangeRemote.new(old_owner, new_owner) }
|
@@ -73,7 +74,7 @@ describe GitHelper::ChangeRemote do
|
|
73
74
|
end
|
74
75
|
|
75
76
|
context 'when the user says not to process the directory' do
|
76
|
-
let(:cli) { double(:highline_cli,
|
77
|
+
let(:cli) { double(:highline_cli, ask_yes_no: false) }
|
77
78
|
|
78
79
|
it 'should not call to process the directory' do
|
79
80
|
expect(subject).not_to receive(:process_git_repository)
|
@@ -138,14 +139,13 @@ describe GitHelper::ChangeRemote do
|
|
138
139
|
context 'https remote' do
|
139
140
|
let(:local_code) do
|
140
141
|
double(:local_code,
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
)
|
142
|
+
remotes: [remote1],
|
143
|
+
remote_name: Faker::Lorem.word,
|
144
|
+
ssh_remote?: false,
|
145
|
+
https_remote?: false,
|
146
|
+
remote_project: project,
|
147
|
+
remote_source: 'github.com',
|
148
|
+
change_remote: true)
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'should ask if the remote is SSH' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'git_helper'
|
3
5
|
|
@@ -101,19 +103,19 @@ describe GitHelper::CodeRequest do
|
|
101
103
|
|
102
104
|
describe '#ask_for_clarification' do
|
103
105
|
it 'should ask the CLI' do
|
104
|
-
expect(highline_cli).to receive(:
|
106
|
+
expect(highline_cli).to receive(:ask).and_return('github')
|
105
107
|
subject.send(:ask_for_clarification)
|
106
108
|
end
|
107
109
|
|
108
110
|
context 'when response is github' do
|
109
111
|
it 'should return github_pull_request' do
|
110
|
-
allow(highline_cli).to receive(:
|
112
|
+
allow(highline_cli).to receive(:ask).and_return('github')
|
111
113
|
expect(subject).to receive(:github_pull_request)
|
112
114
|
subject.send(:ask_for_clarification)
|
113
115
|
end
|
114
116
|
|
115
117
|
it 'should return github_pull_request' do
|
116
|
-
allow(highline_cli).to receive(:
|
118
|
+
allow(highline_cli).to receive(:ask).and_return('Github')
|
117
119
|
expect(subject).to receive(:github_pull_request)
|
118
120
|
subject.send(:ask_for_clarification)
|
119
121
|
end
|
@@ -121,21 +123,22 @@ describe GitHelper::CodeRequest do
|
|
121
123
|
|
122
124
|
context 'when response is gitlab' do
|
123
125
|
it 'should return gitlab_merge_request' do
|
124
|
-
allow(highline_cli).to receive(:
|
126
|
+
allow(highline_cli).to receive(:ask).and_return('gitlab')
|
125
127
|
expect(subject).to receive(:gitlab_merge_request)
|
126
128
|
subject.send(:ask_for_clarification)
|
127
129
|
end
|
128
130
|
|
129
131
|
it 'should return gitlab_merge_request' do
|
130
|
-
allow(highline_cli).to receive(:
|
132
|
+
allow(highline_cli).to receive(:ask).and_return('Gitlab')
|
131
133
|
expect(subject).to receive(:gitlab_merge_request)
|
132
134
|
subject.send(:ask_for_clarification)
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
138
|
+
# Unfortunately this test sometimes fails... just rerun the tests if it does
|
136
139
|
context 'when response is neither' do
|
137
140
|
it 'should raise an error' do
|
138
|
-
allow(highline_cli).to receive(:
|
141
|
+
allow(highline_cli).to receive(:ask).and_return(Faker::Lorem.word)
|
139
142
|
expect(subject).to receive(:exit)
|
140
143
|
subject.send(:ask_for_clarification)
|
141
144
|
end
|
@@ -173,23 +176,23 @@ describe GitHelper::CodeRequest do
|
|
173
176
|
describe '#base_branch' do
|
174
177
|
it 'should call the default branch' do
|
175
178
|
expect(subject).to receive(:default_branch)
|
176
|
-
allow(highline_cli).to receive(:
|
177
|
-
allow(highline_cli).to receive(:
|
179
|
+
allow(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
180
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
|
178
181
|
subject.send(:base_branch)
|
179
182
|
end
|
180
183
|
|
181
184
|
it 'should ask the CLI to ask the user' do
|
182
185
|
allow(subject).to receive(:default_branch)
|
183
|
-
expect(highline_cli).to receive(:
|
184
|
-
allow(highline_cli).to receive(:
|
186
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
187
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
|
185
188
|
subject.send(:base_branch)
|
186
189
|
end
|
187
190
|
|
188
191
|
context 'if the user says no' do
|
189
192
|
it 'definitely asks for the users base branch' do
|
190
193
|
allow(subject).to receive(:default_branch)
|
191
|
-
expect(highline_cli).to receive(:
|
192
|
-
expect(highline_cli).to receive(:
|
194
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(false)
|
195
|
+
expect(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
|
193
196
|
subject.send(:base_branch)
|
194
197
|
end
|
195
198
|
end
|
@@ -197,7 +200,7 @@ describe GitHelper::CodeRequest do
|
|
197
200
|
context 'if the user says yes' do
|
198
201
|
it 'does not ask for the users base branch' do
|
199
202
|
allow(subject).to receive(:default_branch)
|
200
|
-
expect(highline_cli).to receive(:
|
203
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(true)
|
201
204
|
expect(highline_cli).not_to receive(:base_branch)
|
202
205
|
subject.send(:base_branch)
|
203
206
|
end
|
@@ -215,32 +218,32 @@ describe GitHelper::CodeRequest do
|
|
215
218
|
describe '#new_code_request_title' do
|
216
219
|
it 'should call autogenerated title method' do
|
217
220
|
expect(subject).to receive(:autogenerated_title)
|
218
|
-
allow(highline_cli).to receive(:
|
219
|
-
allow(highline_cli).to receive(:
|
221
|
+
allow(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
222
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(title)
|
220
223
|
subject.send(:new_code_request_title)
|
221
224
|
end
|
222
225
|
|
223
226
|
it 'should ask the CLI to ask the user' do
|
224
|
-
allow(subject).to receive(:autogenerated_title)
|
225
|
-
expect(highline_cli).to receive(:
|
226
|
-
allow(highline_cli).to receive(:
|
227
|
+
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
228
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once)
|
229
|
+
allow(highline_cli).to receive(:ask).at_least(:once).and_return(title)
|
227
230
|
subject.send(:new_code_request_title)
|
228
231
|
end
|
229
232
|
|
230
233
|
context 'if the user says no' do
|
231
234
|
it 'definitely asks for the users title' do
|
232
|
-
allow(subject).to receive(:autogenerated_title)
|
233
|
-
expect(highline_cli).to receive(:
|
234
|
-
expect(highline_cli).to receive(:
|
235
|
+
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
236
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(false)
|
237
|
+
expect(highline_cli).to receive(:ask).at_least(:once).and_return(title)
|
235
238
|
subject.send(:new_code_request_title)
|
236
239
|
end
|
237
240
|
end
|
238
241
|
|
239
242
|
context 'if the user says yes to original title' do
|
240
243
|
it 'does not ask for the users chosen title' do
|
241
|
-
allow(subject).to receive(:autogenerated_title)
|
242
|
-
expect(highline_cli).to receive(:
|
243
|
-
expect(highline_cli).not_to receive(:
|
244
|
+
allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
|
245
|
+
expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(true)
|
246
|
+
expect(highline_cli).not_to receive(:ask)
|
244
247
|
subject.send(:new_code_request_title)
|
245
248
|
end
|
246
249
|
end
|