git_helper 3.3.1 → 3.3.2
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +20 -0
- data/Guardfile +3 -1
- data/README.md +1 -1
- data/Rakefile +2 -0
- data/bin/git-helper +18 -13
- data/lib/git_helper.rb +5 -1
- data/lib/git_helper/change_remote.rb +11 -3
- data/lib/git_helper/checkout_default.rb +2 -0
- data/lib/git_helper/clean_branches.rb +2 -0
- data/lib/git_helper/code_request.rb +29 -16
- data/lib/git_helper/empty_commit.rb +2 -0
- data/lib/git_helper/forget_local_commits.rb +2 -0
- data/lib/git_helper/git_config_reader.rb +3 -5
- data/lib/git_helper/gitlab_client.rb +2 -0
- data/lib/git_helper/highline_cli.rb +3 -1
- data/lib/git_helper/local_code.rb +18 -8
- data/lib/git_helper/merge_request.rb +86 -66
- data/lib/git_helper/new_branch.rb +2 -0
- data/lib/git_helper/octokit_client.rb +2 -0
- data/lib/git_helper/pull_request.rb +94 -63
- data/lib/git_helper/setup.rb +37 -17
- data/lib/git_helper/version.rb +3 -1
- data/spec/git_helper/change_remote_spec.rb +17 -17
- data/spec/git_helper/checkout_default_spec.rb +2 -0
- data/spec/git_helper/clean_branches_spec.rb +2 -0
- data/spec/git_helper/code_request_spec.rb +2 -0
- data/spec/git_helper/empty_commit_spec.rb +2 -0
- data/spec/git_helper/forget_local_commits_spec.rb +2 -0
- data/spec/git_helper/git_config_reader_spec.rb +4 -2
- data/spec/git_helper/gitlab_client_spec.rb +2 -0
- data/spec/git_helper/highline_cli_spec.rb +7 -5
- data/spec/git_helper/local_code_spec.rb +2 -0
- data/spec/git_helper/merge_request_spec.rb +8 -7
- data/spec/git_helper/new_branch_spec.rb +2 -0
- data/spec/git_helper/octokit_client_spec.rb +2 -0
- data/spec/git_helper/pull_request_spec.rb +5 -3
- data/spec/git_helper/setup_spec.rb +12 -7
- data/spec/spec_helper.rb +3 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '02607381872b87e3390ddfe00db3a66da5b72698943abfc7af1fb556b69bc5fd'
|
4
|
+
data.tar.gz: 85ef4555a8f0be75248dc20895a62d3e7660276154c4cee638faceb7f0ff701a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 354f303f75c86aefa64b8af4378e0006aab40b322ad5fa5b3f18018e45625d5f0e2d57c5a2f6ff8eb5e38d60863f995ac55fdecfe995d922dfff0d5dc3db4a52
|
7
|
+
data.tar.gz: 2a946bf13c0b36ebe71ca352623aeb6c509a3a3ee2c565ed1e433380713afacd08fddfd69626ca22a88225a65f0f7f5d093f5bf25b58c3cbc2121ebf70d9529b
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -12,6 +12,7 @@ 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)
|
@@ -65,14 +66,20 @@ GEM
|
|
65
66
|
octokit (4.20.0)
|
66
67
|
faraday (>= 0.9)
|
67
68
|
sawyer (~> 0.8.0, >= 0.5.3)
|
69
|
+
parallel (1.20.1)
|
70
|
+
parser (3.0.0.0)
|
71
|
+
ast (~> 2.4.1)
|
68
72
|
pry (0.14.0)
|
69
73
|
coderay (~> 1.1)
|
70
74
|
method_source (~> 1.0)
|
71
75
|
public_suffix (4.0.6)
|
76
|
+
rainbow (3.0.0)
|
72
77
|
rake (13.0.3)
|
73
78
|
rb-fsevent (0.10.4)
|
74
79
|
rb-inotify (0.10.1)
|
75
80
|
ffi (~> 1.0)
|
81
|
+
regexp_parser (2.1.1)
|
82
|
+
rexml (3.2.4)
|
76
83
|
rspec (3.10.0)
|
77
84
|
rspec-core (~> 3.10.0)
|
78
85
|
rspec-expectations (~> 3.10.0)
|
@@ -86,6 +93,18 @@ GEM
|
|
86
93
|
diff-lcs (>= 1.2.0, < 2.0)
|
87
94
|
rspec-support (~> 3.10.0)
|
88
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)
|
89
108
|
ruby2_keywords (0.0.4)
|
90
109
|
sawyer (0.8.2)
|
91
110
|
addressable (>= 2.3.5)
|
@@ -106,6 +125,7 @@ DEPENDENCIES
|
|
106
125
|
guard-rspec (~> 4.3)
|
107
126
|
rake (~> 13.0)
|
108
127
|
rspec (~> 3.9)
|
128
|
+
rubocop
|
109
129
|
|
110
130
|
BUNDLED WITH
|
111
131
|
2.2.9
|
data/Guardfile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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 [](https://github.com/emmahsax/git_helper/actions/workflows/main.yml)
|
2
2
|
|
3
3
|
## Gem Usage
|
4
4
|
|
data/Rakefile
CHANGED
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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
|
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 |
|
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
|
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 |
|
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
5
|
require 'highline'
|
4
6
|
require 'octokit'
|
5
7
|
|
6
|
-
|
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) && !
|
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
|
-
|
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,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
|
-
|
6
|
-
|
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.ask(
|
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 ||=
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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,12 +88,14 @@ module GitHelper
|
|
77
88
|
end
|
78
89
|
|
79
90
|
private def new_code_request_title
|
80
|
-
@new_code_request_title ||=
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
86
99
|
end
|
87
100
|
|
88
101
|
private def cli
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitHelper
|
2
4
|
class GitConfigReader
|
3
5
|
def gitlab_token
|
@@ -17,15 +19,11 @@ module GitHelper
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def git_config_file_path
|
20
|
-
Dir.pwd.scan(/\
|
22
|
+
"#{Dir.pwd.scan(%r{\A/\w*/\w*/}).first}.git_helper/config.yml"
|
21
23
|
end
|
22
24
|
|
23
25
|
private def config_file
|
24
26
|
YAML.load_file(git_config_file_path)
|
25
27
|
end
|
26
|
-
|
27
|
-
private def git_config_file
|
28
|
-
'.git_helper/config.yml'
|
29
|
-
end
|
30
28
|
end
|
31
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitHelper
|
2
4
|
class HighlineCli
|
3
5
|
def ask(prompt)
|
@@ -15,7 +17,7 @@ module GitHelper
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def ask_options(prompt, choices)
|
18
|
-
choices_as_string_options = ''
|
20
|
+
choices_as_string_options = ''.dup
|
19
21
|
choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
|
20
22
|
compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
|
21
23
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GitHelper
|
2
4
|
class LocalCode
|
3
5
|
def checkout_default
|
@@ -44,20 +46,20 @@ module GitHelper
|
|
44
46
|
end
|
45
47
|
|
46
48
|
def https_remote?(remote)
|
47
|
-
remote.scan(
|
49
|
+
remote.scan(%r{(https://)}).any?
|
48
50
|
end
|
49
51
|
|
50
52
|
def remote_project(remote)
|
51
53
|
if https_remote?(remote)
|
52
|
-
remote.scan(
|
54
|
+
remote.scan(%r{https://\S+/(\S*).git}).first.first
|
53
55
|
elsif ssh_remote?(remote)
|
54
|
-
remote.scan(
|
56
|
+
remote.scan(%r{/(\S*).git}).first.first
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
60
|
def remote_source(remote)
|
59
61
|
if https_remote?(remote)
|
60
|
-
remote.scan(
|
62
|
+
remote.scan(%r{https://([a-zA-z.]+)/}).first.first
|
61
63
|
elsif ssh_remote?(remote)
|
62
64
|
remote.scan(/git@([a-zA-z.]+):/).first.first
|
63
65
|
end
|
@@ -73,18 +75,20 @@ module GitHelper
|
|
73
75
|
|
74
76
|
def project_name
|
75
77
|
# Get the repo/project name by looking in the remote URLs for the full name
|
76
|
-
`git remote -v`.scan(/\S
|
78
|
+
`git remote -v`.scan(/\S\s*\S+.com\S{1}(\S*).git/).first.first
|
77
79
|
end
|
78
80
|
|
79
81
|
def branch
|
80
82
|
# Get the current branch by looking in the list of branches for the *
|
81
|
-
`git branch`.scan(/\*\s(
|
83
|
+
`git branch`.scan(/\*\s(\S*)/).first.first
|
82
84
|
end
|
83
85
|
|
84
86
|
def default_branch
|
85
87
|
`git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@" | tr -d "\n"`
|
86
88
|
end
|
87
89
|
|
90
|
+
# rubocop:disable Metrics/AbcSize
|
91
|
+
# rubocop:disable Metrics/MethodLength
|
88
92
|
def template_options(identifiers)
|
89
93
|
nested_templates = Dir.glob(
|
90
94
|
File.join("#{identifiers[:template_directory]}/#{identifiers[:nested_directory_name]}", '*.md'),
|
@@ -100,11 +104,15 @@ module GitHelper
|
|
100
104
|
)
|
101
105
|
nested_templates.concat(non_nested_templates).concat(root_templates).uniq
|
102
106
|
end
|
107
|
+
# rubocop:enable Metrics/MethodLength
|
108
|
+
# rubocop:enable Metrics/AbcSize
|
103
109
|
|
104
110
|
def read_template(file_name)
|
105
111
|
File.open(file_name).read
|
106
112
|
end
|
107
113
|
|
114
|
+
# rubocop:disable Metrics/AbcSize
|
115
|
+
# rubocop:disable Metrics/MethodLength
|
108
116
|
def generate_title(local_branch)
|
109
117
|
branch_arr = local_branch.split(local_branch.include?('_') ? '_' : '-')
|
110
118
|
|
@@ -112,11 +120,11 @@ module GitHelper
|
|
112
120
|
|
113
121
|
if branch_arr.length == 1
|
114
122
|
branch_arr.first.capitalize
|
115
|
-
elsif branch_arr[0].scan(/(
|
123
|
+
elsif branch_arr[0].scan(/(\w+)/).any? && branch_arr[1].scan(/(\d+)/).any? # branch includes jira_123 at beginning
|
116
124
|
issue = "#{branch_arr[0].upcase}-#{branch_arr[1]}"
|
117
125
|
description = branch_arr[2..-1].join(' ')
|
118
126
|
"#{issue} #{description.capitalize}"
|
119
|
-
elsif branch_arr[0].scan(/(
|
127
|
+
elsif branch_arr[0].scan(/(\w+-\d+)/).any? # branch includes string jira-123 at beginning
|
120
128
|
issue = branch_arr[0].upcase
|
121
129
|
description = branch_arr[1..-1].join(' ')
|
122
130
|
"#{issue} #{description.capitalize}"
|
@@ -124,5 +132,7 @@ module GitHelper
|
|
124
132
|
branch_arr[0..-1].join(' ').capitalize
|
125
133
|
end
|
126
134
|
end
|
135
|
+
# rubocop:enable Metrics/MethodLength
|
136
|
+
# rubocop:enable Metrics/AbcSize
|
127
137
|
end
|
128
138
|
end
|