git_helper 3.0.0 → 3.2.0

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: 8e4c2767e4d4858d3ed4f8791d0dc82577e9fdf051aff59b1f6516c4f13bd4a4
4
- data.tar.gz: 686894c11b437666221793b475cdf81eb1c99437fcc1ee87aef6a3c07d33e9a4
3
+ metadata.gz: 4b64f4dd497458fd54078d7b1db018ba01273e432e6c0923d1cedad7613631b3
4
+ data.tar.gz: a6aace888903ea6d61846e8910b24c01e6c2b68a3370da904e89e2ca463118cb
5
5
  SHA512:
6
- metadata.gz: 32ba80af9ea352cd22c035ecb5e16c2315bae91c9f2b6b3f49a8d5518ffdc4bd533c9b38e6a8652798bd78672e439ba489d8e58346935f3d43ec21dbc3f248ab
7
- data.tar.gz: '093a11e7c9d46548ad0127d31c101a1fcf69e0aba7c7a1e4c1873dbebadb78bb2f3791175c3702b081fb36d788c1bb4cbe0149833ee58180f038269eeb1f2523'
6
+ metadata.gz: 6f696668e2a8e9180d4df1018c36b94cd8bdb288b73c31181dc6a3a9c92150849505a5363c02e862a13e8f239e51ca177c7bd678576d940e9ecd621e154e2de1
7
+ data.tar.gz: 91c19361c88d9f8b3bc8840f660ea23b14cbf56fe878317f57ab5964a124d5b6150bc97c082a1fcd343a8a5e99f4f65efbcb6858c75e19dddd6a7ee59f67dc41
data/Guardfile CHANGED
@@ -1,5 +1,5 @@
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
- watch('spec/spec_helper.rb') { "spec" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
5
  end
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) ![Develop](https://github.com/emmasax4/git_helper/workflows/Develop/badge.svg)
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)
2
2
 
3
3
  ## Gem Usage
4
4
 
@@ -9,13 +9,15 @@ gem install git_helper
9
9
  Some of the commands in this gem can be used without any additional configuration. However, others utilize special GitHub or GitLab configuration. To provide access tokens for this, create a `~/.git_helper/config.yml` file. The contents should look like this:
10
10
 
11
11
  ```
12
- :github_user: GITHUB-USERNAME
12
+ :github_user: GITHUB-USERNAME
13
13
  :github_token: GITHUB-TOKEN
14
- :gitlab_user: GITLAB-USERNAME
14
+ :gitlab_user: GITLAB-USERNAME
15
15
  :gitlab_token: GITLAB-TOKEN
16
16
  ```
17
17
 
18
- To view the help screen, run:
18
+ To create or see what access tokens you have, look [here for GitHub personal access tokens](https://github.com/settings/tokens) and [here for GitLab access tokens](https://gitlab.com/profile/personal_access_tokens). You could either have one set of tokens for each computer you use, or just have one set of tokens for all computers that you rotate periodically.
19
+
20
+ Once the gem is installed, run this to view the help screen:
19
21
  ```bash
20
22
  git-helper --help
21
23
  ```
@@ -32,7 +34,7 @@ As an additional option, you can set each of the following commands to be a git
32
34
  ```bash
33
35
  # As a Gem # As a Plugin
34
36
  git-helper clean-branches git clean-branches
35
- git-helper code-request --create git code-request --create
37
+ git-helper code-request git code-request
36
38
  ```
37
39
 
38
40
  To do this, download the `plugins.zip` file in the root of this directory. Unzip and place the contents in the appropriate location:
@@ -108,25 +110,21 @@ git-helper clean-branches
108
110
 
109
111
  ### `code-request`
110
112
 
111
- 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).
112
114
 
113
- 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:
114
116
 
115
117
  ```bash
116
- git-helper code-request -c
117
- # OR
118
- git-helper code-request -m
118
+ git-helper code-request
119
119
  ```
120
120
 
121
- 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.
122
122
 
123
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.
124
124
 
125
- Lastly, for GitHub, it'll ask the user to apply any code request templates found at any `*/pull_request_template.md` file or any file in `.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 `*/merge_request_template.md` file or any file in `.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. If a GitLab project automatically adds a template, then it may create a merge request with a default template anyway.
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.
126
126
 
127
- 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.
128
-
129
- 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.
130
128
 
131
129
  ### `empty-commit`
132
130
 
@@ -144,6 +142,23 @@ This command is handy if you locally have a bunch of commits you wish to complet
144
142
  git-helper forget-local-commits
145
143
  ```
146
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
+
147
162
  ### `new-branch`
148
163
 
149
164
  This command is useful for making new branches in a repository on the command line. To run the command, run:
@@ -162,7 +177,7 @@ To submit a feature request, bug ticket, etc, please submit an official [GitHub
162
177
 
163
178
  To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/git_helper/security/policy).
164
179
 
165
- 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).
166
181
 
167
182
  ## Releasing
168
183
 
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -27,7 +27,7 @@ command 'change-remote' do |c|
27
27
  end
28
28
  end
29
29
 
30
- desc "Checks out the default branch of a repo based on the local remote branches."
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 "Creates an empty commit with a basic commit message."
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 "Reset your local git commits to origin/HEAD."
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
@@ -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
 
@@ -1,4 +1,9 @@
1
- Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + "/**/*.rb"].each do |file|
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,5 +1,3 @@
1
- require 'yaml'
2
-
3
1
  module GitHelper
4
2
  class GitConfigReader
5
3
  def gitlab_token
@@ -1,5 +1,3 @@
1
- require 'gitlab'
2
-
3
1
  module GitHelper
4
2
  class GitLabClient
5
3
  def client
@@ -1,5 +1,3 @@
1
- require 'highline'
2
-
3
1
  module GitHelper
4
2
  class HighlineCli
5
3
  def new_branch_name
@@ -1,27 +1,27 @@
1
1
  module GitHelper
2
2
  class LocalCode
3
3
  def checkout_default
4
- system("git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed \"s@^refs/remotes/origin/@@\")")
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("git pull")
9
- system("git reset --hard origin/HEAD")
8
+ system('git pull')
9
+ system('git reset --hard origin/HEAD')
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
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")
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("git pull")
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}")
@@ -85,16 +85,20 @@ module GitHelper
85
85
  `git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@" | tr -d "\n"`
86
86
  end
87
87
 
88
- def template_options(template_identifiers)
88
+ def template_options(identifiers)
89
89
  nested_templates = Dir.glob(
90
- File.join("**/#{template_identifiers[:nested_directory_name]}", "*.md"),
90
+ File.join("#{identifiers[:template_directory]}/#{identifiers[:nested_directory_name]}", '*.md'),
91
91
  File::FNM_DOTMATCH | File::FNM_CASEFOLD
92
92
  )
93
93
  non_nested_templates = Dir.glob(
94
- File.join("**", "#{template_identifiers[:non_nested_file_name]}.md"),
94
+ File.join(identifiers[:template_directory], "#{identifiers[:non_nested_file_name]}.md"),
95
95
  File::FNM_DOTMATCH | File::FNM_CASEFOLD
96
96
  )
97
- nested_templates.concat(non_nested_templates).uniq
97
+ root_templates = Dir.glob(
98
+ File.join('.', "#{identifiers[:non_nested_file_name]}.md"),
99
+ File::FNM_DOTMATCH | File::FNM_CASEFOLD
100
+ )
101
+ nested_templates.concat(non_nested_templates).concat(root_templates).uniq
98
102
  end
99
103
 
100
104
  def read_template(file_name)
@@ -97,6 +97,7 @@ module GitHelper
97
97
 
98
98
  private def mr_template_options
99
99
  @mr_template_options ||= local_code.template_options({
100
+ template_directory: '.gitlab',
100
101
  nested_directory_name: 'merge_request_templates',
101
102
  non_nested_file_name: 'merge_request_template'
102
103
  })
@@ -1,5 +1,3 @@
1
- require 'octokit'
2
-
3
1
  module GitHelper
4
2
  class OctokitClient
5
3
  def client
@@ -94,6 +94,7 @@ module GitHelper
94
94
 
95
95
  private def pr_template_options
96
96
  @pr_template_options ||= local_code.template_options({
97
+ template_directory: '.github',
97
98
  nested_directory_name: 'PULL_REQUEST_TEMPLATE',
98
99
  non_nested_file_name: 'pull_request_template'
99
100
  })
@@ -1,3 +1,3 @@
1
1
  module GitHelper
2
- VERSION = '3.0.0'
2
+ VERSION = '3.2.0'
3
3
  end
Binary file
@@ -2,35 +2,38 @@ require 'spec_helper'
2
2
  require 'git_helper'
3
3
 
4
4
  describe GitHelper::ChangeRemote do
5
- let(:remote1) { 'git@github.com:github-username-old/project-1.git' }
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: 'origin',
15
+ remote_name: Faker::Lorem.word,
10
16
  ssh_remote?: true,
11
17
  https_remote?: false,
12
- remote_project: 'project-1',
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
 
24
26
  before do
25
27
  allow(GitHelper::HighlineCli).to receive(:new).and_return(cli)
26
28
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
29
+ allow(subject).to receive(:puts)
27
30
  end
28
31
 
29
32
  describe '#execute' do
30
33
  before do
31
- allow(Dir).to receive(:pwd).and_return('/Users/firstname/lastname/path/to/project')
34
+ allow(Dir).to receive(:pwd).and_return("/Users/#{Faker::Name.first_name}/#{project}")
32
35
  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')
36
+ allow(File).to receive(:join).and_return("/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
34
37
  allow(File).to receive(:directory?).and_return(true)
35
38
  allow(subject).to receive(:process_dir)
36
39
  end
@@ -59,13 +62,13 @@ describe GitHelper::ChangeRemote do
59
62
  it 'should definitely look in the file structure' do
60
63
  expect(Dir).to receive(:chdir)
61
64
  expect(File).to receive(:exist?)
62
- subject.send(:process_dir, '/Users/firstname/lastname/path/to/project', '/Users/firstname/lastname/path/to/project/project-1')
65
+ subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
63
66
  end
64
67
 
65
68
  context 'when the user says to process the directory' do
66
69
  it 'should call to process the git repository at least once' do
67
70
  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')
71
+ subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
69
72
  end
70
73
  end
71
74
 
@@ -74,7 +77,7 @@ describe GitHelper::ChangeRemote do
74
77
 
75
78
  it 'should not call to process the directory' do
76
79
  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')
80
+ subject.send(:process_dir, "/Users/#{Faker::Name.first_name}/#{project}", "/Users/#{Faker::Name.first_name}/#{project}/#{Faker::Lorem.word}")
78
81
  end
79
82
  end
80
83
  end
@@ -97,7 +100,7 @@ describe GitHelper::ChangeRemote do
97
100
  end
98
101
 
99
102
  context 'when the remote does not include the old owner' do
100
- let(:remote1) { 'git@github.com:github-username-new/project-1.git' }
103
+ let(:remote1) { "git@github.com:#{new_owner}/#{project}.git" }
101
104
 
102
105
  it 'should not call to process the remote' do
103
106
  expect(subject).not_to receive(:process_remote)
@@ -136,10 +139,10 @@ describe GitHelper::ChangeRemote do
136
139
  let(:local_code) do
137
140
  double(:local_code,
138
141
  remotes: [remote1],
139
- remote_name: 'origin',
142
+ remote_name: Faker::Lorem.word,
140
143
  ssh_remote?: false,
141
144
  https_remote?: false,
142
- remote_project: 'project-1',
145
+ remote_project: project,
143
146
  remote_source: 'github.com',
144
147
  change_remote: true
145
148
  )
@@ -3,20 +3,23 @@ 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: 'name', branch: 'branch') }
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
 
11
13
  before do
12
14
  allow(GitHelper::LocalCode).to receive(:new).and_return(local_code)
13
15
  allow(GitHelper::HighlineCli).to receive(:new).and_return(highline_cli)
16
+ allow(subject).to receive(:puts)
14
17
  end
15
18
 
16
19
  describe '#create' do
17
20
  before do
18
- allow(subject).to receive(:base_branch).and_return('base')
19
- allow(subject).to receive(:new_code_request_title).and_return('Title')
21
+ allow(subject).to receive(:base_branch).and_return(base_branch)
22
+ allow(subject).to receive(:new_code_request_title).and_return(title)
20
23
  end
21
24
 
22
25
  it 'should call to process the project' do
@@ -31,8 +34,8 @@ describe GitHelper::CodeRequest do
31
34
  end
32
35
 
33
36
  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')
37
+ expect(subject).to receive(:base_branch).and_return(base_branch)
38
+ expect(subject).to receive(:new_code_request_title).and_return(title)
36
39
  allow(subject).to receive(:process_project).and_return(process_project)
37
40
  allow(process_project).to receive(:create)
38
41
  subject.create
@@ -132,7 +135,7 @@ describe GitHelper::CodeRequest do
132
135
 
133
136
  context 'when response is neither' do
134
137
  it 'should raise an error' do
135
- allow(highline_cli).to receive(:conflicting_remote_clarification).and_return('huh?')
138
+ allow(highline_cli).to receive(:conflicting_remote_clarification).and_return(Faker::Lorem.word)
136
139
  expect(subject).to receive(:exit)
137
140
  subject.send(:ask_for_clarification)
138
141
  end
@@ -171,28 +174,28 @@ describe GitHelper::CodeRequest do
171
174
  it 'should call the default branch' do
172
175
  expect(subject).to receive(:default_branch)
173
176
  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')
177
+ allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
175
178
  subject.send(:base_branch)
176
179
  end
177
180
 
178
181
  it 'should ask the CLI to ask the user' do
179
182
  allow(subject).to receive(:default_branch)
180
183
  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')
184
+ allow(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
182
185
  subject.send(:base_branch)
183
186
  end
184
187
 
185
188
  context 'if the user says no' do
186
- it "definitely asks for the user's base branch" do
189
+ it 'definitely asks for the users base branch' do
187
190
  allow(subject).to receive(:default_branch)
188
191
  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')
192
+ expect(highline_cli).to receive(:base_branch).at_least(:once).and_return(base_branch)
190
193
  subject.send(:base_branch)
191
194
  end
192
195
  end
193
196
 
194
197
  context 'if the user says yes' do
195
- it "does not ask for the user's base branch" do
198
+ it 'does not ask for the users base branch' do
196
199
  allow(subject).to receive(:default_branch)
197
200
  expect(highline_cli).to receive(:base_branch_default?).at_least(:once).and_return(true)
198
201
  expect(highline_cli).not_to receive(:base_branch)
@@ -203,7 +206,7 @@ describe GitHelper::CodeRequest do
203
206
 
204
207
  describe '#autogenerated_title' do
205
208
  it 'should generate a title based on the branch' do
206
- expect(subject).to receive(:local_branch).and_return('branch')
209
+ expect(subject).to receive(:local_branch).and_return(Faker::Lorem.word)
207
210
  expect(local_code).to receive(:generate_title)
208
211
  subject.send(:autogenerated_title)
209
212
  end
@@ -213,28 +216,28 @@ describe GitHelper::CodeRequest do
213
216
  it 'should call autogenerated title method' do
214
217
  expect(subject).to receive(:autogenerated_title)
215
218
  allow(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
216
- allow(highline_cli).to receive(:title).at_least(:once).and_return('Title')
219
+ allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
217
220
  subject.send(:new_code_request_title)
218
221
  end
219
222
 
220
223
  it 'should ask the CLI to ask the user' do
221
224
  allow(subject).to receive(:autogenerated_title)
222
225
  expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once)
223
- allow(highline_cli).to receive(:title).at_least(:once).and_return('Title')
226
+ allow(highline_cli).to receive(:title).at_least(:once).and_return(title)
224
227
  subject.send(:new_code_request_title)
225
228
  end
226
229
 
227
230
  context 'if the user says no' do
228
- it "definitely asks for the user's title" do
231
+ it 'definitely asks for the users title' do
229
232
  allow(subject).to receive(:autogenerated_title)
230
233
  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')
234
+ expect(highline_cli).to receive(:title).at_least(:once).and_return(title)
232
235
  subject.send(:new_code_request_title)
233
236
  end
234
237
  end
235
238
 
236
239
  context 'if the user says yes to original title' do
237
- it "does not ask for the user's chosen title" do
240
+ it 'does not ask for the users chosen title' do
238
241
  allow(subject).to receive(:autogenerated_title)
239
242
  expect(highline_cli).to receive(:accept_autogenerated_title?).at_least(:once).and_return(true)
240
243
  expect(highline_cli).not_to receive(:title)