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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +131 -0
  4. data/Guardfile +3 -1
  5. data/README.md +11 -6
  6. data/Rakefile +2 -0
  7. data/bin/git-helper +25 -13
  8. data/lib/git_helper.rb +5 -1
  9. data/lib/git_helper/change_remote.rb +11 -3
  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 +29 -15
  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 +12 -6
  16. data/lib/git_helper/gitlab_client.rb +2 -0
  17. data/lib/git_helper/highline_cli.rb +15 -69
  18. data/lib/git_helper/local_code.rb +18 -8
  19. data/lib/git_helper/merge_request.rb +88 -68
  20. data/lib/git_helper/new_branch.rb +3 -1
  21. data/lib/git_helper/octokit_client.rb +2 -0
  22. data/lib/git_helper/pull_request.rb +95 -64
  23. data/lib/git_helper/setup.rb +116 -0
  24. data/lib/git_helper/version.rb +3 -1
  25. data/spec/git_helper/change_remote_spec.rb +19 -19
  26. data/spec/git_helper/checkout_default_spec.rb +2 -0
  27. data/spec/git_helper/clean_branches_spec.rb +2 -0
  28. data/spec/git_helper/code_request_spec.rb +27 -24
  29. data/spec/git_helper/empty_commit_spec.rb +2 -0
  30. data/spec/git_helper/forget_local_commits_spec.rb +2 -0
  31. data/spec/git_helper/git_config_reader_spec.rb +32 -4
  32. data/spec/git_helper/gitlab_client_spec.rb +2 -0
  33. data/spec/git_helper/highline_cli_spec.rb +21 -185
  34. data/spec/git_helper/local_code_spec.rb +2 -0
  35. data/spec/git_helper/merge_request_spec.rb +22 -21
  36. data/spec/git_helper/new_branch_spec.rb +4 -2
  37. data/spec/git_helper/octokit_client_spec.rb +2 -0
  38. data/spec/git_helper/pull_request_spec.rb +17 -15
  39. data/spec/git_helper/setup_spec.rb +180 -0
  40. data/spec/spec_helper.rb +3 -1
  41. metadata +22 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b64f4dd497458fd54078d7b1db018ba01273e432e6c0923d1cedad7613631b3
4
- data.tar.gz: a6aace888903ea6d61846e8910b24c01e6c2b68a3370da904e89e2ca463118cb
3
+ metadata.gz: '02607381872b87e3390ddfe00db3a66da5b72698943abfc7af1fb556b69bc5fd'
4
+ data.tar.gz: 85ef4555a8f0be75248dc20895a62d3e7660276154c4cee638faceb7f0ff701a
5
5
  SHA512:
6
- metadata.gz: 6f696668e2a8e9180d4df1018c36b94cd8bdb288b73c31181dc6a3a9c92150849505a5363c02e862a13e8f239e51ca177c7bd678576d940e9ecd621e154e2de1
7
- data.tar.gz: 91c19361c88d9f8b3bc8840f660ea23b14cbf56fe878317f57ab5964a124d5b6150bc97c082a1fcd343a8a5e99f4f65efbcb6858c75e19dddd6a7ee59f67dc41
6
+ metadata.gz: 354f303f75c86aefa64b8af4378e0006aab40b322ad5fa5b3f18018e45625d5f0e2d57c5a2f6ff8eb5e38d60863f995ac55fdecfe995d922dfff0d5dc3db4a52
7
+ data.tar.gz: 2a946bf13c0b36ebe71ca352623aeb6c509a3a3ee2c565ed1e433380713afacd08fddfd69626ca22a88225a65f0f7f5d093f5bf25b58c3cbc2121ebf70d9529b
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 ADDED
@@ -0,0 +1,131 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_helper (3.3.1)
5
+ gitlab (~> 4.16)
6
+ gli (~> 2.13)
7
+ highline (~> 2.0)
8
+ octokit (~> 4.18)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.7.0)
14
+ public_suffix (>= 2.0.2, < 5.0)
15
+ ast (2.4.2)
16
+ coderay (1.1.3)
17
+ concurrent-ruby (1.1.8)
18
+ diff-lcs (1.4.4)
19
+ faker (2.15.1)
20
+ i18n (>= 1.6, < 2)
21
+ faraday (1.3.0)
22
+ faraday-net_http (~> 1.0)
23
+ multipart-post (>= 1.2, < 3)
24
+ ruby2_keywords
25
+ faraday-net_http (1.0.1)
26
+ ffi (1.14.2)
27
+ formatador (0.2.5)
28
+ gitlab (4.17.0)
29
+ httparty (~> 0.18)
30
+ terminal-table (~> 1.5, >= 1.5.1)
31
+ gli (2.19.2)
32
+ guard (2.16.2)
33
+ formatador (>= 0.2.4)
34
+ listen (>= 2.7, < 4.0)
35
+ lumberjack (>= 1.0.12, < 2.0)
36
+ nenv (~> 0.1)
37
+ notiffany (~> 0.0)
38
+ pry (>= 0.9.12)
39
+ shellany (~> 0.0)
40
+ thor (>= 0.18.1)
41
+ guard-compat (1.2.1)
42
+ guard-rspec (4.7.3)
43
+ guard (~> 2.1)
44
+ guard-compat (~> 1.1)
45
+ rspec (>= 2.99.0, < 4.0)
46
+ highline (2.0.3)
47
+ httparty (0.18.1)
48
+ mime-types (~> 3.0)
49
+ multi_xml (>= 0.5.2)
50
+ i18n (1.8.8)
51
+ concurrent-ruby (~> 1.0)
52
+ listen (3.4.1)
53
+ rb-fsevent (~> 0.10, >= 0.10.3)
54
+ rb-inotify (~> 0.9, >= 0.9.10)
55
+ lumberjack (1.2.8)
56
+ method_source (1.0.0)
57
+ mime-types (3.3.1)
58
+ mime-types-data (~> 3.2015)
59
+ mime-types-data (3.2020.1104)
60
+ multi_xml (0.6.0)
61
+ multipart-post (2.1.1)
62
+ nenv (0.3.0)
63
+ notiffany (0.1.3)
64
+ nenv (~> 0.1)
65
+ shellany (~> 0.0)
66
+ octokit (4.20.0)
67
+ faraday (>= 0.9)
68
+ sawyer (~> 0.8.0, >= 0.5.3)
69
+ parallel (1.20.1)
70
+ parser (3.0.0.0)
71
+ ast (~> 2.4.1)
72
+ pry (0.14.0)
73
+ coderay (~> 1.1)
74
+ method_source (~> 1.0)
75
+ public_suffix (4.0.6)
76
+ rainbow (3.0.0)
77
+ rake (13.0.3)
78
+ rb-fsevent (0.10.4)
79
+ rb-inotify (0.10.1)
80
+ ffi (~> 1.0)
81
+ regexp_parser (2.1.1)
82
+ rexml (3.2.4)
83
+ rspec (3.10.0)
84
+ rspec-core (~> 3.10.0)
85
+ rspec-expectations (~> 3.10.0)
86
+ rspec-mocks (~> 3.10.0)
87
+ rspec-core (3.10.1)
88
+ rspec-support (~> 3.10.0)
89
+ rspec-expectations (3.10.1)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.10.0)
92
+ rspec-mocks (3.10.2)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.10.0)
95
+ rspec-support (3.10.2)
96
+ rubocop (1.10.0)
97
+ parallel (~> 1.10)
98
+ parser (>= 3.0.0.0)
99
+ rainbow (>= 2.2.2, < 4.0)
100
+ regexp_parser (>= 1.8, < 3.0)
101
+ rexml
102
+ rubocop-ast (>= 1.2.0, < 2.0)
103
+ ruby-progressbar (~> 1.7)
104
+ unicode-display_width (>= 1.4.0, < 3.0)
105
+ rubocop-ast (1.4.1)
106
+ parser (>= 2.7.1.5)
107
+ ruby-progressbar (1.11.0)
108
+ ruby2_keywords (0.0.4)
109
+ sawyer (0.8.2)
110
+ addressable (>= 2.3.5)
111
+ faraday (> 0.8, < 2.0)
112
+ shellany (0.0.1)
113
+ terminal-table (1.8.0)
114
+ unicode-display_width (~> 1.1, >= 1.1.1)
115
+ thor (1.1.0)
116
+ unicode-display_width (1.7.0)
117
+
118
+ PLATFORMS
119
+ x86_64-darwin-19
120
+
121
+ DEPENDENCIES
122
+ bundler (~> 2.2)
123
+ faker (~> 2.15)
124
+ git_helper!
125
+ guard-rspec (~> 4.3)
126
+ rake (~> 13.0)
127
+ rspec (~> 3.9)
128
+ rubocop
129
+
130
+ BUNDLED WITH
131
+ 2.2.9
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/d53da11f17c38cc81b5b/maintainability)](https://codeclimate.com/github/emmasax4/git_helper/maintainability) ![Default](https://github.com/emmasax4/git_helper/workflows/Default/badge.svg)
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
 
@@ -27,6 +27,11 @@ To see what version of git_helper you're running, run:
27
27
  git-helper --version
28
28
  ```
29
29
 
30
+ To help you create the `~/.git_helper/config.yml` file and set up the plugins (see below), run this command and allow the command to walk you through the prompts:
31
+ ```bash
32
+ git-helper setup
33
+ ```
34
+
30
35
  ## Plugin Usage
31
36
 
32
37
  As an additional option, you can set each of the following commands to be a git plugin, meaning you can call them in a way that feels even more git-native:
@@ -46,7 +51,7 @@ unzip path/to/downloaded/plugins.zip -d ~/.git_helper
46
51
 
47
52
  Now, the plugins will live in `~/.git_helper/plugins/*`. Add the following line to your `~/.bash_profile`:
48
53
 
49
- ```
54
+ ```bash
50
55
  export PATH=/path/to/computer/home/.git_helper/plugins:$PATH
51
56
  ```
52
57
 
@@ -70,7 +75,7 @@ alias gnb="git new-branch"
70
75
 
71
76
  And then, running `gnb` maps to `git new-branch`, which again routes to `git-helper new-branch`.
72
77
 
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).
78
+ 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
79
 
75
80
  If you're going to make using git workflows easier, might as well provide lots of options 😃.
76
81
 
@@ -173,9 +178,9 @@ The command either accepts a branch name right away or it will ask you for the n
173
178
 
174
179
  ## Contributing
175
180
 
176
- To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmasax4/git_helper/issues/new).
181
+ To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/git_helper/issues/new).
177
182
 
178
- To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/git_helper/security/policy).
183
+ To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmahsax/git_helper/security/policy).
179
184
 
180
185
  When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
181
186
 
@@ -185,7 +190,7 @@ To make a new release of this gem:
185
190
 
186
191
  1. Merge the pull request via the big green button
187
192
  2. Run `git tag vX.X.X` and `git push --tag`
188
- 3. Make a new release [here](https://github.com/emmasax4/git_helper/releases/new)
193
+ 3. Make a new release [here](https://github.com/emmahsax/git_helper/releases/new)
189
194
  4. Run `gem build *.gemspec`
190
195
  5. Run `gem push *.gem` to push the new gem to RubyGems
191
196
  6. Run `rm *.gem` to clean up your local repository
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,46 +13,54 @@ 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
- see Git Helper's GitHub repo: https://github.com/emmasax4/git_helper
18
- """
19
+ see Git Helper's GitHub repo: https://github.com/emmahsax/git_helper
20
+ "
21
+
22
+ desc 'Sets up Git Helper configs at ~/.git_helper/*'
23
+ command 'setup' do |c|
24
+ c.action do
25
+ GitHelper::Setup.new.execute
26
+ end
27
+ end
19
28
 
20
29
  arg :old_owner
21
30
  arg :new_owner
22
31
  desc "Update a repository's remote URLs from an old GitHub owner to a new owner."
23
32
  command 'change-remote' do |c|
24
- c.action do |global_options, options, args|
33
+ c.action do |_global_options, _options, args|
25
34
  raise ArgumentError, 'You must specify an old owner and a new owner' unless args.count == 2
35
+
26
36
  GitHelper::ChangeRemote.new(args[0], args[1]).execute
27
37
  end
28
38
  end
29
39
 
30
40
  desc 'Checks out the default branch of a repo based on the local remote branches.'
31
41
  command 'checkout-default' do |c|
32
- c.action do |global_options, options, args|
42
+ c.action do |_global_options, _options, _args|
33
43
  GitHelper::CheckoutDefault.new.execute
34
44
  end
35
45
  end
36
46
 
37
47
  desc "Clean a repository's git branches."
38
48
  command 'clean-branches' do |c|
39
- c.action do |global_options, options, args|
49
+ c.action do |_global_options, _options, _args|
40
50
  GitHelper::CleanBranches.new.execute
41
51
  end
42
52
  end
43
53
 
44
54
  desc 'Creates an empty commit with a basic commit message.'
45
55
  command 'empty-commit' do |c|
46
- c.action do |global_options, options, args|
56
+ c.action do |_global_options, _options, _args|
47
57
  GitHelper::EmptyCommit.new.execute
48
58
  end
49
59
  end
50
60
 
51
61
  desc 'Reset your local git commits to origin/HEAD.'
52
62
  command 'forget-local-commits' do |c|
53
- c.action do |global_options, options, args|
63
+ c.action do |_global_options, _options, _args|
54
64
  GitHelper::ForgetLocalCommits.new.execute
55
65
  end
56
66
  end
@@ -58,21 +68,23 @@ end
58
68
  arg :new_branch_name, optional: true
59
69
  desc 'Create a new branch for features, bug fixes, or experimentation.'
60
70
  command 'new-branch' do |c|
61
- c.action do |global_options, options, args|
71
+ c.action do |_global_options, _options, args|
62
72
  GitHelper::NewBranch.new.execute(args[0])
63
73
  end
64
74
  end
65
75
 
66
- 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.'
67
78
  command 'merge-code-request' do |c|
68
- c.action do |global_options, options, args|
79
+ c.action do |_global_options, _options, _args|
69
80
  GitHelper::CodeRequest.new.merge
70
81
  end
71
82
  end
72
83
 
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.'
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.'
74
86
  command 'code-request' do |c|
75
- c.action do |global_options, options, args|
87
+ c.action do |_global_options, _options, _args|
76
88
  GitHelper::CodeRequest.new.create
77
89
  end
78
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
5
  require 'highline'
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,10 @@ 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.process_directory_remotes?(current_dir)
27
+ if File.exist?('.git') && cli.ask_yes_no(
28
+ "Found git directory: #{current_dir}. Do you wish to proceed in updating #{current_dir}'s remote URLs? (y/n)"
29
+ )
30
+ process_git_repository
27
31
  end
28
32
 
29
33
  Dir.chdir(original_dir)
@@ -40,6 +44,8 @@ module GitHelper
40
44
  puts "\n"
41
45
  end
42
46
 
47
+ # rubocop:disable Metrics/AbcSize
48
+ # rubocop:disable Metrics/MethodLength
43
49
  private def process_remote(remote)
44
50
  remote_name = local_code.remote_name(remote)
45
51
 
@@ -56,6 +62,8 @@ module GitHelper
56
62
  puts " Changing the remote URL #{remote_name} to be '#{remote_url}'."
57
63
  local_code.change_remote(remote_name, remote_url)
58
64
  end
65
+ # rubocop:enable Metrics/MethodLength
66
+ # rubocop:enable Metrics/AbcSize
59
67
 
60
68
  private def local_code
61
69
  @local_code ||= GitHelper::LocalCode.new
@@ -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,13 @@ 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.conflicting_remote_clarification
32
+ resp = cli.ask(
33
+ 'Found git remotes for both GitHub and GitLab. Would you like to proceed ' \
34
+ 'with GitLab or GitHub? (github/gitlab)'
35
+ ).downcase
36
+
28
37
  if resp.include?('hub')
29
38
  github_pull_request
30
39
  elsif resp.include?('lab')
@@ -34,6 +43,7 @@ module GitHelper
34
43
  exit
35
44
  end
36
45
  end
46
+ # rubocop:enable Metrics/MethodLength
37
47
 
38
48
  private def github_pull_request
39
49
  @github_pull_request ||= GitHelper::GitHubPullRequest.new(options)
@@ -61,11 +71,12 @@ module GitHelper
61
71
  end
62
72
 
63
73
  private def base_branch
64
- @base_branch ||= if cli.base_branch_default?(default_branch)
65
- default_branch
66
- else
67
- cli.base_branch
68
- end
74
+ @base_branch ||=
75
+ if cli.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
76
+ default_branch
77
+ else
78
+ cli.ask('Base branch?')
79
+ end
69
80
  end
70
81
 
71
82
  private def local_branch
@@ -77,11 +88,14 @@ module GitHelper
77
88
  end
78
89
 
79
90
  private def new_code_request_title
80
- @new_code_request_title ||= if cli.accept_autogenerated_title?(autogenerated_title)
81
- autogenerated_title
82
- else
83
- cli.title
84
- end
91
+ @new_code_request_title ||=
92
+ if autogenerated_title && cli.ask_yes_no(
93
+ "Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)"
94
+ )
95
+ autogenerated_title
96
+ else
97
+ cli.ask('Title?')
98
+ end
85
99
  end
86
100
 
87
101
  private def cli