git_helper 3.1.0 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59ea066ec1e5cc797d676571c908c55fcc6de186590f5f1d1f14bb5f3ebfe1c5
4
- data.tar.gz: 31c8412273b1e46d5f181e7a01bac5b10858f848293fe287c357f768e41ab90e
3
+ metadata.gz: '0278ec1bcdeffdfc4ff94dcb4853f0d0d9a37c99799d90ab04cb0b59af49d7aa'
4
+ data.tar.gz: ac395aad1492142aba911277e492eb49dd97345e40f81910eed0692618f973a7
5
5
  SHA512:
6
- metadata.gz: 16b7f3b1a77e5a2cae432fcddc556425a18ce88ae6a7147814810af49e42ebe61ca1a82daf691165ef62f7315b10442fcf8c3b458440075b8b767090b5fe560b
7
- data.tar.gz: dd940ec200f5275c5f07b1b91c5e504bc545b177580ab6c059e64d988438001b186ced83af14a2022e14f9526a0d69fe01989eabd7290bf5378de3560ede5968
6
+ metadata.gz: 73cedc8f831a0fea6543fe78fa877eeeba394a43c2f5bd038b65d30a71f6830964c40c23dc3aeb0c4056130d1ffe9ceb14c021eb181f2bd3007eaa9c2533e891
7
+ data.tar.gz: 14d32de16eaf5cd1579464afbaf6c1068514f1cbbaf7c94eeddc3d1fd44b224a94cb93f29f60ec4918d292a7fdde1c326068c0e093848a51dc36f4305599c458
data/Guardfile CHANGED
@@ -1,4 +1,4 @@
1
- guard :rspec, cmd: 'bundle exec rspec', all_on_start: true, all_after_pass: true do
1
+ guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
2
2
  watch(%r{^spec/.+_spec\.rb$})
3
3
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
4
  watch('spec/spec_helper.rb') { 'spec' }
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # git_helper [![Maintainability](https://api.codeclimate.com/v1/badges/d53da11f17c38cc81b5b/maintainability)](https://codeclimate.com/github/emmasax4/git_helper/maintainability) ![Default](https://github.com/emmasax4/git_helper/workflows/Default/badge.svg)
1
+ # git_helper [![Maintainability](https://api.codeclimate.com/v1/badges/bf27d608257c202930c4/maintainability)](https://codeclimate.com/github/emmahsax/git_helper/maintainability) [![Main](https://github.com/emmahsax/git_helper/actions/workflows/main.yml/badge.svg)](https://github.com/emmahsax/git_helper/actions/workflows/main.yml)
2
2
 
3
3
  ## Gem Usage
4
4
 
@@ -34,7 +34,7 @@ As an additional option, you can set each of the following commands to be a git
34
34
  ```bash
35
35
  # As a Gem # As a Plugin
36
36
  git-helper clean-branches git clean-branches
37
- git-helper code-request --create git code-request --create
37
+ git-helper code-request git code-request
38
38
  ```
39
39
 
40
40
  To do this, download the `plugins.zip` file in the root of this directory. Unzip and place the contents in the appropriate location:
@@ -70,7 +70,7 @@ alias gnb="git new-branch"
70
70
 
71
71
  And then, running `gnb` maps to `git new-branch`, which again routes to `git-helper new-branch`.
72
72
 
73
- For a full list of the git aliases I prefer to use, check out my [Git Aliases gist](https://gist.github.com/emmasax4/e8744fe253fba1f00a621c01a2bf68f5).
73
+ For a full list of the git aliases I prefer to use, check out my [Git Aliases gist](https://gist.github.com/emmahsax/e8744fe253fba1f00a621c01a2bf68f5).
74
74
 
75
75
  If you're going to make using git workflows easier, might as well provide lots of options 😃.
76
76
 
@@ -110,25 +110,21 @@ git-helper clean-branches
110
110
 
111
111
  ### `code-request`
112
112
 
113
- This command can be used to handily make new GitHub/GitLab pull/merge requests and to merge those requests from the command line. The command uses either the [`Octokit::Client`](https://octokit.github.io/octokit.rb/Octokit/Client.html) or [`Gitlab` client](https://github.com/NARKOZ/gitlab) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage).
113
+ This command can be used to handily make new GitHub/GitLab pull/merge requests from the command line. The command uses either the [`Octokit::Client`](https://octokit.github.io/octokit.rb/Octokit/Client.html) or [`Gitlab` client](https://github.com/NARKOZ/gitlab) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage).
114
114
 
115
- After setup is complete, you can call the file, and send in a flag indicating whether to create a code request, `-c`, or to merge a code request, `-m`.
115
+ After setup is complete, you can call the command like this:
116
116
 
117
117
  ```bash
118
- git-helper code-request -c
119
- # OR
120
- git-helper code-request -m
118
+ git-helper code-request
121
119
  ```
122
120
 
123
- If you're trying to create a code request, the command will provide an autogenerated code request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the code request. You can respond 'yes' or 'no'. If you respond 'no', you can provide your own code request title.
121
+ The command will provide an autogenerated code request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the code request. You can respond 'yes' or 'no'. If you respond 'no', you can provide your own code request title.
124
122
 
125
123
  The command will also ask you if the default branch of the repository is the proper base branch to use. You can say 'yes' or 'no'. If you respond 'no', then you can give the command your chosen base base.
126
124
 
127
- Lastly, for GitHub, it'll ask the user to apply any pull request templates found at `.github/pull_request_template.md`, `./pull_request_template.md`, or `.github/PULL_REQUEST_TEMPLATE/*.md`. Applying any template is optional, and a user can make an empty pull request if they desire. For GitLab, it'll ask the user to apply any merge request templates found at any `.gitlab/merge_request_template.md`, `./merge_request_template.md`, or `.gitlab/merge_request_templates/*.md`. Applying any template is optional, and from the command's standpoint, a user can make an empty merge request if they desire (although GitLab may still add a merge request template if the project itself requires one). When searching for templates, the code ignores cases, so the file could be named with all capital letters or all lowercase letters.
128
-
129
- If you're requesting to merge a code request, the command will ask you the number ID of the code request you wish to merge. For GitHub, the command will also ask you what type of merge to do: regular merging, squashing, or rebasing. The commit message to use during the merge/squash/rebase will be the title of the pull request. For GitLab, the command will also ask you what type of merge to do: regular merging or squashing. The commit message to use during the merge/squash will be the title of the merge request.
125
+ If your project uses GitLab, the command will potentially ask you if you'd like to delete the source branch upon merge. If the project defaults to deleting the source branch, then the script will use that selection, and the value can be changed for a specific MR either over the API or in the browser. If the project just provides source branch deletion as on option, then it'll ask the user. It also will probably ask you if you'd like to squash the MR upon merge. If the project requires or prevents squashing, then whatever answer you give will be _*ignored*_. This is unfortunate, but is here due to limited API functionality.
130
126
 
131
- If you're getting stuck, you can run the command with a `--help` flag instead, to get some more information.
127
+ Lastly, it'll ask about code request templates. For GitHub, it'll ask the user to apply any pull request templates found at `.github/pull_request_template.md`, `./pull_request_template.md`, or `.github/PULL_REQUEST_TEMPLATE/*.md`. Applying any template is optional, and a user can make an empty pull request if they desire. For GitLab, it'll ask the user to apply any merge request templates found at any `.gitlab/merge_request_template.md`, `./merge_request_template.md`, or `.gitlab/merge_request_templates/*.md`. Applying any template is optional, and from the command's standpoint, a user can make an empty merge request if they desire (although GitLab may still add a merge request template if the project itself requires one). When searching for templates, the code ignores cases, so the file could be named with all capital letters or all lowercase letters.
132
128
 
133
129
  ### `empty-commit`
134
130
 
@@ -146,6 +142,23 @@ This command is handy if you locally have a bunch of commits you wish to complet
146
142
  git-helper forget-local-commits
147
143
  ```
148
144
 
145
+ ### `merge-code-request`
146
+
147
+ This command can be used to merge pull/merge requests from the command line. The command uses either the [`Octokit::Client`](https://octokit.github.io/octokit.rb/Octokit/Client.html) or [`Gitlab` client](https://github.com/NARKOZ/gitlab) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage).
148
+
149
+ After setup is complete, you can call the proper command like this:
150
+
151
+ ```bash
152
+ git-helper merge-code-request
153
+ ```
154
+
155
+ The command will ask you the number ID of the code request you wish to merge.
156
+
157
+ If using GitHub _and_ the repository allows multiple types of merges (merge/squash/rebase), then the command will ask the user what type of merge to do. It'll only let users select a type of merge the repository allows. If a repository only allows one type of merging, then the command will automatically use that. The commit message to use during the merge/squash/rebase will be the title of the pull request.
158
+
159
+ For GitLab, the command will use whatever squash/source branch deletion/etc settings are already set on the merge request, so make sure you click the proper checkboxes in the MR manually or over the API before running this command. The commit message to use during the merge/squash will be the title of the merge request.
160
+
161
+
149
162
  ### `new-branch`
150
163
 
151
164
  This command is useful for making new branches in a repository on the command line. To run the command, run:
@@ -160,11 +173,11 @@ The command either accepts a branch name right away or it will ask you for the n
160
173
 
161
174
  ## Contributing
162
175
 
163
- To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmasax4/git_helper/issues/new).
176
+ To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/git_helper/issues/new).
164
177
 
165
- To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/git_helper/security/policy).
178
+ To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmahsax/git_helper/security/policy).
166
179
 
167
- This repository does have a standard [Code of Conduct](https://github.com/emmasax4/git_helper/blob/main/.github/code_of_conduct.md).
180
+ When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
168
181
 
169
182
  ## Releasing
170
183
 
@@ -172,7 +185,7 @@ To make a new release of this gem:
172
185
 
173
186
  1. Merge the pull request via the big green button
174
187
  2. Run `git tag vX.X.X` and `git push --tag`
175
- 3. Make a new release [here](https://github.com/emmasax4/git_helper/releases/new)
188
+ 3. Make a new release [here](https://github.com/emmahsax/git_helper/releases/new)
176
189
  4. Run `gem build *.gemspec`
177
190
  5. Run `gem push *.gem` to push the new gem to RubyGems
178
191
  6. Run `rm *.gem` to clean up your local repository
data/bin/git-helper CHANGED
@@ -14,7 +14,7 @@ wrap_help_text :verbatim
14
14
  program_long_desc """
15
15
  DOCUMENTATION
16
16
  For documentation and help in setting up your Git configuration files,
17
- see Git Helper's GitHub repo: https://github.com/emmasax4/git_helper
17
+ see Git Helper's GitHub repo: https://github.com/emmahsax/git_helper
18
18
  """
19
19
 
20
20
  arg :old_owner
@@ -63,21 +63,17 @@ command 'new-branch' do |c|
63
63
  end
64
64
  end
65
65
 
66
- desc 'Create or merge a GitHub or GitLab pull/merge request from the current branch. The command will figure out whether your code project belongs to GitHub or GitLab'
67
- command 'code-request' do |c|
68
- c.switch [:c, :create], desc: 'Create a new pull/merge request'
69
- c.switch [:m, :merge], desc: 'Merge an existing pull/merge request'
70
-
66
+ desc 'Merge a GitHub/GitLab pull/merge request. The command will figure out whether your code project belongs to GitHub or GitLab.'
67
+ command 'merge-code-request' do |c|
71
68
  c.action do |global_options, options, args|
72
- raise ArgumentError, "You must specify an action (either '-m'/'--merge' or '-c'/'--create')" unless options[:create] || options[:merge]
73
-
74
- options = global_options.merge(options)
69
+ GitHelper::CodeRequest.new.merge
70
+ end
71
+ end
75
72
 
76
- if options[:create]
77
- GitHelper::CodeRequest.new.create
78
- elsif options[:merge]
79
- GitHelper::CodeRequest.new.merge
80
- end
73
+ desc 'Create a GitHub/GitLab pull/merge request from the current branch. The command will figure out whether your code project belongs to GitHub or GitLab.'
74
+ command 'code-request' do |c|
75
+ c.action do |global_options, options, args|
76
+ GitHelper::CodeRequest.new.create
81
77
  end
82
78
  end
83
79
 
@@ -23,7 +23,7 @@ module GitHelper
23
23
  Dir.chdir(current_dir)
24
24
 
25
25
  if File.exist?('.git')
26
- process_git_repository if cli.process_directory_remotes?(current_dir)
26
+ process_git_repository if cli.ask_yes_no("Found git directory: #{current_dir}. Do you wish to proceed in updating #{current_dir}'s remote URLs? (y/n)")
27
27
  end
28
28
 
29
29
  Dir.chdir(original_dir)
@@ -24,7 +24,7 @@ module GitHelper
24
24
  end
25
25
 
26
26
  private def ask_for_clarification
27
- resp = cli.conflicting_remote_clarification
27
+ resp = cli.ask('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').downcase
28
28
  if resp.include?('hub')
29
29
  github_pull_request
30
30
  elsif resp.include?('lab')
@@ -61,10 +61,10 @@ module GitHelper
61
61
  end
62
62
 
63
63
  private def base_branch
64
- @base_branch ||= if cli.base_branch_default?(default_branch)
64
+ @base_branch ||= if cli.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
65
65
  default_branch
66
66
  else
67
- cli.base_branch
67
+ cli.ask('Base branch?')
68
68
  end
69
69
  end
70
70
 
@@ -77,10 +77,11 @@ module GitHelper
77
77
  end
78
78
 
79
79
  private def new_code_request_title
80
- @new_code_request_title ||= if cli.accept_autogenerated_title?(autogenerated_title)
80
+ @new_code_request_title ||= if autogenerated_title &&
81
+ cli.ask_yes_no("Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)")
81
82
  autogenerated_title
82
83
  else
83
- cli.title
84
+ cli.ask('Title?')
84
85
  end
85
86
  end
86
87
 
@@ -1,85 +1,29 @@
1
1
  module GitHelper
2
2
  class HighlineCli
3
- def new_branch_name
4
- ask('New branch name?')
5
- end
6
-
7
- def process_directory_remotes?(directory)
8
- answer = ask("Found git directory: #{directory}. Do you wish to proceed in updating #{directory}'s remote URLs? (y/n)")
9
- answer.empty? ? true : !!(answer =~ /^y/i)
10
- end
11
-
12
- def conflicting_remote_clarification
13
- ask('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').downcase
14
- end
15
-
16
- def title
17
- ask('Title?')
18
- end
19
-
20
- def base_branch
21
- ask('Base branch?')
22
- end
23
-
24
- def code_request_id(request_type)
25
- ask("#{request_type} Request ID?")
26
- end
27
-
28
- def accept_autogenerated_title?(autogenerated_title)
29
- return false unless autogenerated_title
30
- answer = ask("Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)")
31
- answer.empty? ? true : !!(answer =~ /^y/i)
32
- end
33
-
34
- def base_branch_default?(default_branch)
35
- answer = ask("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
36
- answer.empty? ? true : !!(answer =~ /^y/i)
37
- end
38
-
39
- def squash_merge_request?
40
- answer = ask('Squash merge request? (y/n)')
41
- answer.empty? ? true : !!(answer =~ /^y/i)
42
- end
43
-
44
- def remove_source_branch?
45
- answer = ask('Remove source branch after merging? (y/n)')
46
- answer.empty? ? true : !!(answer =~ /^y/i)
47
- end
48
-
49
- def merge_method(merge_options)
50
- index = ask_options("Merge method?", merge_options)
51
- merge_options[index]
52
- end
53
-
54
- def apply_template?(template_file_name, request_type)
55
- answer = ask("Apply the #{request_type} request template from #{template_file_name}? (y/n)")
56
- answer.empty? ? true : !!(answer =~ /^y/i)
57
- end
58
-
59
- def template_to_apply(template_options, request_type)
60
- complete_options = template_options << 'None'
61
- index = ask_options("Which #{request_type} request template should be applied?", complete_options)
62
- complete_options[index]
3
+ def ask(prompt)
4
+ highline_client.ask(prompt) do |conf|
5
+ conf.readline = true
6
+ end.to_s
63
7
  end
64
8
 
65
- #######################
66
- ### GENERAL METHODS ###
67
- #######################
68
-
69
- private def ask(prompt)
70
- highline_client.ask(prompt) do |conf|
9
+ def ask_yes_no(prompt)
10
+ answer = highline_client.ask(prompt) do |conf|
71
11
  conf.readline = true
72
12
  end.to_s
13
+
14
+ answer.empty? ? true : !!(answer =~ /^y/i)
73
15
  end
74
16
 
75
- private def ask_options(prompt, choices)
17
+ def ask_options(prompt, choices)
76
18
  choices_as_string_options = ''
77
19
  choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
78
20
  compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
79
21
 
80
- highline_client.ask(compiled_prompt) do |conf|
22
+ index = highline_client.ask(compiled_prompt) do |conf|
81
23
  conf.readline = true
82
24
  end.to_i - 1
25
+
26
+ choices[index]
83
27
  end
84
28
 
85
29
  private def highline_client
@@ -10,7 +10,7 @@ module GitHelper
10
10
  end
11
11
 
12
12
  def empty_commit
13
- system('git commit --allow-empty -m \"Empty commit\"')
13
+ system('git commit --allow-empty -m "Empty commit"')
14
14
  end
15
15
 
16
16
  def clean_branches
@@ -84,10 +84,10 @@ module GitHelper
84
84
 
85
85
  unless mr_template_options.empty?
86
86
  if mr_template_options.count == 1
87
- apply_single_template = cli.apply_template?(mr_template_options.first, 'merge')
87
+ apply_single_template = cli.ask_yes_no("Apply the merge request template from #{mr_template_options.first}? (y/n)")
88
88
  @template_name_to_apply = mr_template_options.first if apply_single_template
89
89
  else
90
- response = cli.template_to_apply(mr_template_options, 'merge')
90
+ response = cli.ask_options("Which merge request template should be applied?", mr_template_options << 'None')
91
91
  @template_name_to_apply = response unless response == 'None'
92
92
  end
93
93
  end
@@ -104,15 +104,15 @@ module GitHelper
104
104
  end
105
105
 
106
106
  private def mr_id
107
- @mr_id ||= cli.code_request_id('Merge')
107
+ @mr_id ||= cli.ask('Merge Request ID?')
108
108
  end
109
109
 
110
110
  private def squash_merge_request
111
- @squash_merge_request ||= cli.squash_merge_request?
111
+ @squash_merge_request ||= cli.ask_yes_no('Squash merge request? (y/n)')
112
112
  end
113
113
 
114
114
  private def remove_source_branch
115
- @remove_source_branch ||= existing_project.remove_source_branch_after_merge || cli.remove_source_branch?
115
+ @remove_source_branch ||= existing_project.remove_source_branch_after_merge || cli.ask_yes_no('Remove source branch after merging? (y/n)')
116
116
  end
117
117
 
118
118
  private def existing_project
@@ -1,7 +1,7 @@
1
1
  module GitHelper
2
2
  class NewBranch
3
3
  def execute(new_branch_name = nil)
4
- branch_name = new_branch_name || GitHelper::HighlineCli.new.new_branch_name
4
+ branch_name = new_branch_name || GitHelper::HighlineCli.new.ask('New branch name?')
5
5
  puts "Attempting to create a new branch: #{branch_name}"
6
6
  GitHelper::LocalCode.new.new_branch(branch_name)
7
7
  end
@@ -81,10 +81,10 @@ module GitHelper
81
81
 
82
82
  unless pr_template_options.empty?
83
83
  if pr_template_options.count == 1
84
- apply_single_template = cli.apply_template?(pr_template_options.first, 'pull')
84
+ apply_single_template = cli.ask_yes_no("Apply the pull request template from #{pr_template_options.first}? (y/n)")
85
85
  @template_name_to_apply = pr_template_options.first if apply_single_template
86
86
  else
87
- response = cli.template_to_apply(pr_template_options, 'pull')
87
+ response = cli.ask_options("Which pull request template should be applied?", pr_template_options << 'None')
88
88
  @template_name_to_apply = response unless response == 'None'
89
89
  end
90
90
  end
@@ -101,11 +101,11 @@ module GitHelper
101
101
  end
102
102
 
103
103
  private def pr_id
104
- @pr_id ||= cli.code_request_id('Pull')
104
+ @pr_id ||= cli.ask('Pull Request ID?')
105
105
  end
106
106
 
107
107
  private def merge_method
108
- @merge_method ||= merge_options.length == 1 ? merge_options.first : cli.merge_method(merge_options)
108
+ @merge_method ||= merge_options.length == 1 ? merge_options.first : cli.ask_options('Merge method?', merge_options)
109
109
  end
110
110
 
111
111
  private def merge_options
@@ -1,3 +1,3 @@
1
1
  module GitHelper
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.2'
3
3
  end
data/plugins.zip CHANGED
Binary file
@@ -4,7 +4,7 @@ require 'git_helper'
4
4
  describe GitHelper::ChangeRemote do
5
5
  let(:remote1) { "git@github.com:#{old_owner}/#{project}.git" }
6
6
  let(:project) { Faker::Lorem.word }
7
- let(:cli) { double(:highline_cli, process_directory_remotes?: true) }
7
+ let(:cli) { double(:highline_cli, ask_yes_no: true) }
8
8
  let(:old_owner) { Faker::Internet.username }
9
9
  let(:new_owner) { Faker::Internet.username }
10
10
  let(:directory_entries) { [ '.', '..', project, Faker::Lorem.word, Faker::Lorem.word ] }
@@ -26,6 +26,7 @@ describe GitHelper::ChangeRemote do
26
26
  before do
27
27
  allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
28
28
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
29
+ allow(subject).to receive(:puts)
29
30
  end
30
31
 
31
32
  describe '#execute' do
@@ -72,7 +73,7 @@ describe GitHelper::ChangeRemote do
72
73
  end
73
74
 
74
75
  context 'when the user says not to process the directory' do
75
- let(:cli) { double(:highline_cli, process_directory_remotes?: false) }
76
+ let(:cli) { double(:highline_cli, ask_yes_no: false) }
76
77
 
77
78
  it 'should not call to process the directory' do
78
79
  expect(subject).not_to receive(:process_git_repository)
@@ -13,6 +13,7 @@ describe GitHelper::CodeRequest do
13
13
  before do
14
14
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
15
15
  allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
16
+ allow(subject).to receive(:puts)
16
17
  end
17
18
 
18
19
  describe '#create' do
@@ -100,19 +101,19 @@ describe GitHelper::CodeRequest do
100
101
 
101
102
  describe '#ask_for_clarification' do
102
103
  it 'should ask the CLI' do
103
- expect(highline_cli).to receive(:conflicting_remote_clarification).and_return('github')
104
+ expect(highline_cli).to receive(:ask).and_return('github')
104
105
  subject.send(:ask_for_clarification)
105
106
  end
106
107
 
107
108
  context 'when response is github' do
108
109
  it 'should return github_pull_request' do
109
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('github')
110
+ allow(highline_cli).to receive(:ask).and_return('github')
110
111
  expect(subject).to receive(:github_pull_request)
111
112
  subject.send(:ask_for_clarification)
112
113
  end
113
114
 
114
115
  it 'should return github_pull_request' do
115
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('Github')
116
+ allow(highline_cli).to receive(:ask).and_return('Github')
116
117
  expect(subject).to receive(:github_pull_request)
117
118
  subject.send(:ask_for_clarification)
118
119
  end
@@ -120,13 +121,13 @@ describe GitHelper::CodeRequest do
120
121
 
121
122
  context 'when response is gitlab' do
122
123
  it 'should return gitlab_merge_request' do
123
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('gitlab')
124
+ allow(highline_cli).to receive(:ask).and_return('gitlab')
124
125
  expect(subject).to receive(:gitlab_merge_request)
125
126
  subject.send(:ask_for_clarification)
126
127
  end
127
128
 
128
129
  it 'should return gitlab_merge_request' do
129
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('Gitlab')
130
+ allow(highline_cli).to receive(:ask).and_return('Gitlab')
130
131
  expect(subject).to receive(:gitlab_merge_request)
131
132
  subject.send(:ask_for_clarification)
132
133
  end
@@ -134,7 +135,7 @@ describe GitHelper::CodeRequest do
134
135
 
135
136
  context 'when response is neither' do
136
137
  it 'should raise an error' do
137
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return(Faker::Lorem.word)
138
+ allow(highline_cli).to receive(:ask).and_return(Faker::Lorem.word)
138
139
  expect(subject).to receive(:exit)
139
140
  subject.send(:ask_for_clarification)
140
141
  end
@@ -172,23 +173,23 @@ describe GitHelper::CodeRequest do
172
173
  describe '#base_branch' do
173
174
  it 'should call the default branch' do
174
175
  expect(subject).to receive(:default_branch)
175
- allow(highline_cli).to receive(:base_branch_default?).at_least(:once)
176
- allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
176
+ allow(highline_cli).to receive(:ask_yes_no).at_least(:once)
177
+ allow(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
177
178
  subject.send(:base_branch)
178
179
  end
179
180
 
180
181
  it 'should ask the CLI to ask the user' do
181
182
  allow(subject).to receive(:default_branch)
182
- expect(highline_cli).to receive(:base_branch_default?).at_least(:once)
183
- allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
183
+ expect(highline_cli).to receive(:ask_yes_no).at_least(:once)
184
+ allow(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
184
185
  subject.send(:base_branch)
185
186
  end
186
187
 
187
188
  context 'if the user says no' do
188
189
  it 'definitely asks for the users base branch' do
189
190
  allow(subject).to receive(:default_branch)
190
- expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(false)
191
- expect(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
191
+ expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(false)
192
+ expect(highline_cli).to receive(:ask).at_least(:once).and_return(base_branch)
192
193
  subject.send(:base_branch)
193
194
  end
194
195
  end
@@ -196,7 +197,7 @@ describe GitHelper::CodeRequest do
196
197
  context 'if the user says yes' do
197
198
  it 'does not ask for the users base branch' do
198
199
  allow(subject).to receive(:default_branch)
199
- expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(true)
200
+ expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(true)
200
201
  expect(highline_cli).not_to receive(:base_branch)
201
202
  subject.send(:base_branch)
202
203
  end
@@ -214,32 +215,32 @@ describe GitHelper::CodeRequest do
214
215
  describe '#new_code_request_title' do
215
216
  it 'should call autogenerated title method' do
216
217
  expect(subject).to receive(:autogenerated_title)
217
- allow(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
218
- allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
218
+ allow(highline_cli).to receive(:ask_yes_no).at_least(:once)
219
+ allow(highline_cli).to receive(:ask).at_least(:once).and_return(title)
219
220
  subject.send(:new_code_request_title)
220
221
  end
221
222
 
222
223
  it 'should ask the CLI to ask the user' do
223
- allow(subject).to receive(:autogenerated_title)
224
- expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
225
- allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
224
+ allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
225
+ expect(highline_cli).to receive(:ask_yes_no).at_least(:once)
226
+ allow(highline_cli).to receive(:ask).at_least(:once).and_return(title)
226
227
  subject.send(:new_code_request_title)
227
228
  end
228
229
 
229
230
  context 'if the user says no' do
230
231
  it 'definitely asks for the users title' do
231
- allow(subject).to receive(:autogenerated_title)
232
- expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(false)
233
- expect(highline_cli).to receive(:title).at_least(:once).and_return(title)
232
+ allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
233
+ expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(false)
234
+ expect(highline_cli).to receive(:ask).at_least(:once).and_return(title)
234
235
  subject.send(:new_code_request_title)
235
236
  end
236
237
  end
237
238
 
238
239
  context 'if the user says yes to original title' do
239
240
  it 'does not ask for the users chosen title' do
240
- allow(subject).to receive(:autogenerated_title)
241
- expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(true)
242
- expect(highline_cli).not_to receive(:title)
241
+ allow(subject).to receive(:autogenerated_title).and_return(Faker::Lorem.sentence)
242
+ expect(highline_cli).to receive(:ask_yes_no).at_least(:once).and_return(true)
243
+ expect(highline_cli).not_to receive(:ask)
243
244
  subject.send(:new_code_request_title)
244
245
  end
245
246
  end