git_helper 3.3.1 → 3.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +32 -9
  4. data/Guardfile +3 -1
  5. data/README.md +4 -4
  6. data/Rakefile +2 -0
  7. data/bin/git-helper +18 -13
  8. data/lib/git_helper.rb +6 -2
  9. data/lib/git_helper/change_remote.rb +15 -6
  10. data/lib/git_helper/checkout_default.rb +2 -0
  11. data/lib/git_helper/clean_branches.rb +2 -0
  12. data/lib/git_helper/code_request.rb +33 -19
  13. data/lib/git_helper/empty_commit.rb +2 -0
  14. data/lib/git_helper/forget_local_commits.rb +2 -0
  15. data/lib/git_helper/git_config_reader.rb +3 -5
  16. data/lib/git_helper/gitlab_client.rb +2 -0
  17. data/lib/git_helper/local_code.rb +18 -8
  18. data/lib/git_helper/merge_request.rb +90 -70
  19. data/lib/git_helper/new_branch.rb +3 -1
  20. data/lib/git_helper/octokit_client.rb +2 -0
  21. data/lib/git_helper/pull_request.rb +97 -66
  22. data/lib/git_helper/setup.rb +52 -32
  23. data/lib/git_helper/version.rb +3 -1
  24. data/spec/git_helper/change_remote_spec.rb +24 -24
  25. data/spec/git_helper/checkout_default_spec.rb +2 -0
  26. data/spec/git_helper/clean_branches_spec.rb +2 -0
  27. data/spec/git_helper/code_request_spec.rb +30 -28
  28. data/spec/git_helper/empty_commit_spec.rb +2 -0
  29. data/spec/git_helper/forget_local_commits_spec.rb +2 -0
  30. data/spec/git_helper/git_config_reader_spec.rb +4 -2
  31. data/spec/git_helper/gitlab_client_spec.rb +2 -0
  32. data/spec/git_helper/local_code_spec.rb +2 -0
  33. data/spec/git_helper/merge_request_spec.rb +24 -23
  34. data/spec/git_helper/new_branch_spec.rb +10 -8
  35. data/spec/git_helper/octokit_client_spec.rb +2 -0
  36. data/spec/git_helper/pull_request_spec.rb +20 -18
  37. data/spec/git_helper/setup_spec.rb +34 -26
  38. data/spec/spec_helper.rb +4 -1
  39. metadata +34 -9
  40. data/lib/git_helper/highline_cli.rb +0 -33
  41. data/spec/git_helper/highline_cli_spec.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be948f58bc902f2e3036bfc3379279afcc74012af9cb56ee1b1f8586ba9c0fa2
4
- data.tar.gz: c4f8655fcaef1db1fba03ebb731932da6d185bb89c46ebc366781309b76ebd1d
3
+ metadata.gz: 982626ad7f16046c76d280d10894a5be74f37e806d014403a9df4163a953d2ec
4
+ data.tar.gz: 9467e130453d7b70a8b15fd76540ae03a59f52185bc124b1ed5eb8cfc582bdce
5
5
  SHA512:
6
- metadata.gz: d19cf35a128b640a265aa89f229022fd7be3629e6e8ae5f6f08504494b1ccc5231af4ff1e39fbd3014ddb78e8757dd1a9413110872bdd7c8da8ae86525e7776a
7
- data.tar.gz: d50eb1904c56c2269c139f7275321eef5516c70de6973fb2b11f8ea0f6681f5db5389f3f629c8b16718a7390442031e4999d8620a3814647b64dae340c01b8d1
6
+ metadata.gz: f7830ff9ad946fcecb8c530e4b92c84cfb15a47bc1a1804c8419765149ca92af43d25d1614d09cd26187abde62c7215e6927c370058406d9c9071a2bdcf2464f
7
+ data.tar.gz: 5f2f68d661a2395afaa08c567aeae1b8649b9d98728902a52cd64672419ec6f8cda8b93d961d50ae94a45c22db79b8e897c94d720716ace0e1cee78131c006da
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_helper (3.3.1)
4
+ git_helper (3.3.6)
5
5
  gitlab (~> 4.16)
6
6
  gli (~> 2.13)
7
- highline (~> 2.0)
7
+ highline_wrapper (~> 1.1)
8
8
  octokit (~> 4.18)
9
9
 
10
10
  GEM
@@ -12,22 +12,23 @@ GEM
12
12
  specs:
13
13
  addressable (2.7.0)
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
+ ast (2.4.2)
15
16
  coderay (1.1.3)
16
17
  concurrent-ruby (1.1.8)
17
18
  diff-lcs (1.4.4)
18
- faker (2.15.1)
19
+ faker (2.16.0)
19
20
  i18n (>= 1.6, < 2)
20
21
  faraday (1.3.0)
21
22
  faraday-net_http (~> 1.0)
22
23
  multipart-post (>= 1.2, < 3)
23
24
  ruby2_keywords
24
25
  faraday-net_http (1.0.1)
25
- ffi (1.14.2)
26
+ ffi (1.15.0)
26
27
  formatador (0.2.5)
27
28
  gitlab (4.17.0)
28
29
  httparty (~> 0.18)
29
30
  terminal-table (~> 1.5, >= 1.5.1)
30
- gli (2.19.2)
31
+ gli (2.20.0)
31
32
  guard (2.16.2)
32
33
  formatador (>= 0.2.4)
33
34
  listen (>= 2.7, < 4.0)
@@ -43,10 +44,12 @@ GEM
43
44
  guard-compat (~> 1.1)
44
45
  rspec (>= 2.99.0, < 4.0)
45
46
  highline (2.0.3)
47
+ highline_wrapper (1.1.0)
48
+ highline (~> 2.0)
46
49
  httparty (0.18.1)
47
50
  mime-types (~> 3.0)
48
51
  multi_xml (>= 0.5.2)
49
- i18n (1.8.8)
52
+ i18n (1.8.9)
50
53
  concurrent-ruby (~> 1.0)
51
54
  listen (3.4.1)
52
55
  rb-fsevent (~> 0.10, >= 0.10.3)
@@ -55,7 +58,7 @@ GEM
55
58
  method_source (1.0.0)
56
59
  mime-types (3.3.1)
57
60
  mime-types-data (~> 3.2015)
58
- mime-types-data (3.2020.1104)
61
+ mime-types-data (3.2021.0225)
59
62
  multi_xml (0.6.0)
60
63
  multipart-post (2.1.1)
61
64
  nenv (0.3.0)
@@ -65,14 +68,20 @@ GEM
65
68
  octokit (4.20.0)
66
69
  faraday (>= 0.9)
67
70
  sawyer (~> 0.8.0, >= 0.5.3)
71
+ parallel (1.20.1)
72
+ parser (3.0.0.0)
73
+ ast (~> 2.4.1)
68
74
  pry (0.14.0)
69
75
  coderay (~> 1.1)
70
76
  method_source (~> 1.0)
71
77
  public_suffix (4.0.6)
78
+ rainbow (3.0.0)
72
79
  rake (13.0.3)
73
80
  rb-fsevent (0.10.4)
74
81
  rb-inotify (0.10.1)
75
82
  ffi (~> 1.0)
83
+ regexp_parser (2.1.1)
84
+ rexml (3.2.4)
76
85
  rspec (3.10.0)
77
86
  rspec-core (~> 3.10.0)
78
87
  rspec-expectations (~> 3.10.0)
@@ -86,6 +95,18 @@ GEM
86
95
  diff-lcs (>= 1.2.0, < 2.0)
87
96
  rspec-support (~> 3.10.0)
88
97
  rspec-support (3.10.2)
98
+ rubocop (1.11.0)
99
+ parallel (~> 1.10)
100
+ parser (>= 3.0.0.0)
101
+ rainbow (>= 2.2.2, < 4.0)
102
+ regexp_parser (>= 1.8, < 3.0)
103
+ rexml
104
+ rubocop-ast (>= 1.2.0, < 2.0)
105
+ ruby-progressbar (~> 1.7)
106
+ unicode-display_width (>= 1.4.0, < 3.0)
107
+ rubocop-ast (1.4.1)
108
+ parser (>= 2.7.1.5)
109
+ ruby-progressbar (1.11.0)
89
110
  ruby2_keywords (0.0.4)
90
111
  sawyer (0.8.2)
91
112
  addressable (>= 2.3.5)
@@ -97,15 +118,17 @@ GEM
97
118
  unicode-display_width (1.7.0)
98
119
 
99
120
  PLATFORMS
100
- x86_64-darwin-19
121
+ x86_64-darwin-20
101
122
 
102
123
  DEPENDENCIES
103
124
  bundler (~> 2.2)
104
125
  faker (~> 2.15)
105
126
  git_helper!
106
127
  guard-rspec (~> 4.3)
128
+ pry (~> 0.13)
107
129
  rake (~> 13.0)
108
130
  rspec (~> 3.9)
131
+ rubocop (~> 1.10)
109
132
 
110
133
  BUNDLED WITH
111
- 2.2.9
134
+ 2.2.14
data/Guardfile CHANGED
@@ -1,4 +1,6 @@
1
- guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
2
4
  watch(%r{^spec/.+_spec\.rb$})
3
5
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
6
  watch('spec/spec_helper.rb') { 'spec' }
data/README.md CHANGED
@@ -1,4 +1,4 @@
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)
1
+ # git_helper [![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
 
@@ -115,7 +115,7 @@ git-helper clean-branches
115
115
 
116
116
  ### `code-request`
117
117
 
118
- 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).
118
+ 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).
119
119
 
120
120
  After setup is complete, you can call the command like this:
121
121
 
@@ -149,7 +149,7 @@ git-helper forget-local-commits
149
149
 
150
150
  ### `merge-code-request`
151
151
 
152
- 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).
152
+ 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).
153
153
 
154
154
  After setup is complete, you can call the proper command like this:
155
155
 
@@ -166,7 +166,7 @@ For GitLab, the command will use whatever squash/source branch deletion/etc sett
166
166
 
167
167
  ### `new-branch`
168
168
 
169
- This command is useful for making new branches in a repository on the command line. To run the command, run:
169
+ This command is useful for making new branches in a repository on the command-line. To run the command, run:
170
170
 
171
171
  ```bash
172
172
  git-helper new-branch
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
data/bin/git-helper CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  require 'rubygems'
3
5
  require 'gli'
4
6
  require_relative '../lib/git_helper'
@@ -11,15 +13,15 @@ version GitHelper::VERSION
11
13
  autocomplete_commands false
12
14
  wrap_help_text :verbatim
13
15
 
14
- program_long_desc """
16
+ program_long_desc "
15
17
  DOCUMENTATION
16
18
  For documentation and help in setting up your Git configuration files,
17
19
  see Git Helper's GitHub repo: https://github.com/emmahsax/git_helper
18
- """
20
+ "
19
21
 
20
22
  desc 'Sets up Git Helper configs at ~/.git_helper/*'
21
23
  command 'setup' do |c|
22
- c.action do ||
24
+ c.action do
23
25
  GitHelper::Setup.new.execute
24
26
  end
25
27
  end
@@ -28,36 +30,37 @@ arg :old_owner
28
30
  arg :new_owner
29
31
  desc "Update a repository's remote URLs from an old GitHub owner to a new owner."
30
32
  command 'change-remote' do |c|
31
- c.action do |global_options, options, args|
33
+ c.action do |_global_options, _options, args|
32
34
  raise ArgumentError, 'You must specify an old owner and a new owner' unless args.count == 2
35
+
33
36
  GitHelper::ChangeRemote.new(args[0], args[1]).execute
34
37
  end
35
38
  end
36
39
 
37
40
  desc 'Checks out the default branch of a repo based on the local remote branches.'
38
41
  command 'checkout-default' do |c|
39
- c.action do |global_options, options, args|
42
+ c.action do |_global_options, _options, _args|
40
43
  GitHelper::CheckoutDefault.new.execute
41
44
  end
42
45
  end
43
46
 
44
47
  desc "Clean a repository's git branches."
45
48
  command 'clean-branches' do |c|
46
- c.action do |global_options, options, args|
49
+ c.action do |_global_options, _options, _args|
47
50
  GitHelper::CleanBranches.new.execute
48
51
  end
49
52
  end
50
53
 
51
54
  desc 'Creates an empty commit with a basic commit message.'
52
55
  command 'empty-commit' do |c|
53
- c.action do |global_options, options, args|
56
+ c.action do |_global_options, _options, _args|
54
57
  GitHelper::EmptyCommit.new.execute
55
58
  end
56
59
  end
57
60
 
58
61
  desc 'Reset your local git commits to origin/HEAD.'
59
62
  command 'forget-local-commits' do |c|
60
- c.action do |global_options, options, args|
63
+ c.action do |_global_options, _options, _args|
61
64
  GitHelper::ForgetLocalCommits.new.execute
62
65
  end
63
66
  end
@@ -65,21 +68,23 @@ end
65
68
  arg :new_branch_name, optional: true
66
69
  desc 'Create a new branch for features, bug fixes, or experimentation.'
67
70
  command 'new-branch' do |c|
68
- c.action do |global_options, options, args|
71
+ c.action do |_global_options, _options, args|
69
72
  GitHelper::NewBranch.new.execute(args[0])
70
73
  end
71
74
  end
72
75
 
73
- desc 'Merge a GitHub/GitLab pull/merge request. The command will figure out whether your code project belongs to GitHub or GitLab.'
76
+ desc 'Merge a GitHub/GitLab pull/merge request. The command will figure out whether your ' \
77
+ 'code project belongs to GitHub or GitLab.'
74
78
  command 'merge-code-request' do |c|
75
- c.action do |global_options, options, args|
79
+ c.action do |_global_options, _options, _args|
76
80
  GitHelper::CodeRequest.new.merge
77
81
  end
78
82
  end
79
83
 
80
- 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.'
84
+ desc 'Create a GitHub/GitLab pull/merge request from the current branch. The command will figure ' \
85
+ 'out whether your code project belongs to GitHub or GitLab.'
81
86
  command 'code-request' do |c|
82
- c.action do |global_options, options, args|
87
+ c.action do |_global_options, _options, _args|
83
88
  GitHelper::CodeRequest.new.create
84
89
  end
85
90
  end
data/lib/git_helper.rb CHANGED
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'gitlab'
3
- require 'highline'
5
+ require 'highline_wrapper'
4
6
  require 'octokit'
5
7
 
6
- Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + '/**/*.rb'].each do |file|
8
+ files = "#{File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper'))}/**/*.rb"
9
+
10
+ Dir[files].each do |file|
7
11
  require_relative file
8
12
  end
9
13
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class ChangeRemote
3
5
  attr_accessor :old_owner, :new_owner
@@ -11,7 +13,7 @@ module GitHelper
11
13
  original_dir = Dir.pwd
12
14
  nested_dirs = Dir.entries(original_dir).select do |entry|
13
15
  entry_dir = File.join(original_dir, entry)
14
- File.directory?(entry_dir) && !(entry == '.' || entry == '..')
16
+ File.directory?(entry_dir) && !['.', '..'].include?(entry)
15
17
  end
16
18
 
17
19
  nested_dirs.each do |nested_dir|
@@ -22,8 +24,11 @@ module GitHelper
22
24
  private def process_dir(current_dir, original_dir)
23
25
  Dir.chdir(current_dir)
24
26
 
25
- if File.exist?('.git')
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
+ if File.exist?('.git') && highline.ask_yes_no(
28
+ "Found git directory: #{current_dir}. Do you wish to proceed in updating #{current_dir}'s remote URLs? (y/n)",
29
+ { required: true }
30
+ )
31
+ process_git_repository
27
32
  end
28
33
 
29
34
  Dir.chdir(original_dir)
@@ -37,9 +42,11 @@ module GitHelper
37
42
  puts " Found remote is not pointing to #{old_owner}."
38
43
  end
39
44
  end
40
- puts "\n"
45
+ puts
41
46
  end
42
47
 
48
+ # rubocop:disable Metrics/AbcSize
49
+ # rubocop:disable Metrics/MethodLength
43
50
  private def process_remote(remote)
44
51
  remote_name = local_code.remote_name(remote)
45
52
 
@@ -56,13 +63,15 @@ module GitHelper
56
63
  puts " Changing the remote URL #{remote_name} to be '#{remote_url}'."
57
64
  local_code.change_remote(remote_name, remote_url)
58
65
  end
66
+ # rubocop:enable Metrics/MethodLength
67
+ # rubocop:enable Metrics/AbcSize
59
68
 
60
69
  private def local_code
61
70
  @local_code ||= GitHelper::LocalCode.new
62
71
  end
63
72
 
64
- private def cli
65
- @cli ||= GitHelper::HighlineCli.new
73
+ private def highline
74
+ @highline ||= HighlineWrapper.new
66
75
  end
67
76
  end
68
77
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class CheckoutDefault
3
5
  def execute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class CleanBranches
3
5
  def execute
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class CodeRequest
3
5
  def create
4
- process_project.create({
5
- base_branch: base_branch,
6
- new_title: new_code_request_title
7
- })
6
+ process_project.create(
7
+ {
8
+ base_branch: base_branch,
9
+ new_title: new_code_request_title
10
+ }
11
+ )
8
12
  end
9
13
 
10
14
  def merge
@@ -23,8 +27,14 @@ module GitHelper
23
27
  end
24
28
  end
25
29
 
30
+ # rubocop:disable Metrics/MethodLength
26
31
  private def ask_for_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
32
+ resp = highline.ask(
33
+ 'Found git remotes for both GitHub and GitLab. Would you like to proceed ' \
34
+ 'with GitLab or GitHub? (github/gitlab)',
35
+ { required: true }
36
+ ).downcase
37
+
28
38
  if resp.include?('hub')
29
39
  github_pull_request
30
40
  elsif resp.include?('lab')
@@ -34,6 +44,7 @@ module GitHelper
34
44
  exit
35
45
  end
36
46
  end
47
+ # rubocop:enable Metrics/MethodLength
37
48
 
38
49
  private def github_pull_request
39
50
  @github_pull_request ||= GitHelper::GitHubPullRequest.new(options)
@@ -48,7 +59,7 @@ module GitHelper
48
59
  local_project: local_project,
49
60
  local_branch: local_branch,
50
61
  local_code: local_code,
51
- cli: cli
62
+ highline: highline
52
63
  }
53
64
  end
54
65
 
@@ -61,11 +72,12 @@ module GitHelper
61
72
  end
62
73
 
63
74
  private def base_branch
64
- @base_branch ||= if cli.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
65
- default_branch
66
- else
67
- cli.ask('Base branch?')
68
- end
75
+ @base_branch ||=
76
+ if highline.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
77
+ default_branch
78
+ else
79
+ highline.ask('Base branch?', { required: true })
80
+ end
69
81
  end
70
82
 
71
83
  private def local_branch
@@ -77,16 +89,18 @@ module GitHelper
77
89
  end
78
90
 
79
91
  private def new_code_request_title
80
- @new_code_request_title ||= if autogenerated_title &&
81
- cli.ask_yes_no("Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)")
82
- autogenerated_title
83
- else
84
- cli.ask('Title?')
85
- end
92
+ @new_code_request_title ||=
93
+ if autogenerated_title && highline.ask_yes_no(
94
+ "Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)"
95
+ )
96
+ autogenerated_title
97
+ else
98
+ highline.ask('Title?', { required: true })
99
+ end
86
100
  end
87
101
 
88
- private def cli
89
- @cli ||= GitHelper::HighlineCli.new
102
+ private def highline
103
+ @highline ||= HighlineWrapper.new
90
104
  end
91
105
 
92
106
  private def local_code