git_helper 2.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +23 -15
- data/Guardfile +1 -1
- data/README.md +21 -12
- data/Rakefile +1 -37
- data/bin/git-helper +3 -10
- data/lib/git_helper.rb +5 -2
- data/lib/git_helper/change_remote.rb +0 -3
- data/lib/git_helper/checkout_default.rb +0 -2
- data/lib/git_helper/clean_branches.rb +0 -2
- data/lib/git_helper/code_request.rb +0 -5
- data/lib/git_helper/empty_commit.rb +0 -2
- data/lib/git_helper/forget_local_commits.rb +0 -2
- data/lib/git_helper/git_config_reader.rb +1 -3
- data/lib/git_helper/gitlab_client.rb +0 -3
- data/lib/git_helper/highline_cli.rb +0 -2
- data/lib/git_helper/local_code.rb +17 -13
- data/lib/git_helper/merge_request.rb +1 -4
- data/lib/git_helper/new_branch.rb +0 -3
- data/lib/git_helper/octokit_client.rb +0 -3
- data/lib/git_helper/pull_request.rb +1 -4
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +19 -16
- data/spec/git_helper/checkout_default_spec.rb +2 -1
- data/spec/git_helper/clean_branches_spec.rb +2 -1
- data/spec/git_helper/code_request_spec.rb +21 -18
- data/spec/git_helper/empty_commit_spec.rb +2 -1
- data/spec/git_helper/forget_local_commits_spec.rb +2 -1
- data/spec/git_helper/git_config_reader_spec.rb +11 -8
- data/spec/git_helper/gitlab_client_spec.rb +2 -1
- data/spec/git_helper/highline_cli_spec.rb +40 -37
- data/spec/git_helper/local_code_spec.rb +64 -27
- data/spec/git_helper/merge_request_spec.rb +36 -28
- data/spec/git_helper/new_branch_spec.rb +2 -1
- data/spec/git_helper/octokit_client_spec.rb +2 -1
- data/spec/git_helper/pull_request_spec.rb +36 -28
- data/spec/spec_helper.rb +2 -1
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59ea066ec1e5cc797d676571c908c55fcc6de186590f5f1d1f14bb5f3ebfe1c5
|
4
|
+
data.tar.gz: 31c8412273b1e46d5f181e7a01bac5b10858f848293fe287c357f768e41ab90e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16b7f3b1a77e5a2cae432fcddc556425a18ce88ae6a7147814810af49e42ebe61ca1a82daf691165ef62f7315b10442fcf8c3b458440075b8b767090b5fe560b
|
7
|
+
data.tar.gz: dd940ec200f5275c5f07b1b91c5e504bc545b177580ab6c059e64d988438001b186ced83af14a2022e14f9526a0d69fe01989eabd7290bf5378de3560ede5968
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (
|
4
|
+
git_helper (3.0.1)
|
5
5
|
gitlab (~> 4.16)
|
6
6
|
gli (~> 2.13)
|
7
7
|
highline (~> 2.0)
|
@@ -13,9 +13,13 @@ GEM
|
|
13
13
|
addressable (2.7.0)
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
15
15
|
coderay (1.1.3)
|
16
|
+
concurrent-ruby (1.1.7)
|
16
17
|
diff-lcs (1.4.4)
|
17
|
-
|
18
|
+
faker (2.14.0)
|
19
|
+
i18n (>= 1.6, < 2)
|
20
|
+
faraday (1.1.0)
|
18
21
|
multipart-post (>= 1.2, < 3)
|
22
|
+
ruby2_keywords
|
19
23
|
ffi (1.13.1)
|
20
24
|
formatador (0.2.5)
|
21
25
|
gitlab (4.16.1)
|
@@ -40,6 +44,8 @@ GEM
|
|
40
44
|
httparty (0.18.1)
|
41
45
|
mime-types (~> 3.0)
|
42
46
|
multi_xml (>= 0.5.2)
|
47
|
+
i18n (1.8.5)
|
48
|
+
concurrent-ruby (~> 1.0)
|
43
49
|
listen (3.2.1)
|
44
50
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
45
51
|
rb-inotify (~> 0.9, >= 0.9.10)
|
@@ -47,14 +53,14 @@ GEM
|
|
47
53
|
method_source (1.0.0)
|
48
54
|
mime-types (3.3.1)
|
49
55
|
mime-types-data (~> 3.2015)
|
50
|
-
mime-types-data (3.2020.
|
56
|
+
mime-types-data (3.2020.1104)
|
51
57
|
multi_xml (0.6.0)
|
52
58
|
multipart-post (2.1.1)
|
53
59
|
nenv (0.3.0)
|
54
60
|
notiffany (0.1.3)
|
55
61
|
nenv (~> 0.1)
|
56
62
|
shellany (~> 0.0)
|
57
|
-
octokit (4.
|
63
|
+
octokit (4.19.0)
|
58
64
|
faraday (>= 0.9)
|
59
65
|
sawyer (~> 0.8.0, >= 0.5.3)
|
60
66
|
pry (0.13.1)
|
@@ -65,19 +71,20 @@ GEM
|
|
65
71
|
rb-fsevent (0.10.4)
|
66
72
|
rb-inotify (0.10.1)
|
67
73
|
ffi (~> 1.0)
|
68
|
-
rspec (3.
|
69
|
-
rspec-core (~> 3.
|
70
|
-
rspec-expectations (~> 3.
|
71
|
-
rspec-mocks (~> 3.
|
72
|
-
rspec-core (3.
|
73
|
-
rspec-support (~> 3.
|
74
|
-
rspec-expectations (3.
|
74
|
+
rspec (3.10.0)
|
75
|
+
rspec-core (~> 3.10.0)
|
76
|
+
rspec-expectations (~> 3.10.0)
|
77
|
+
rspec-mocks (~> 3.10.0)
|
78
|
+
rspec-core (3.10.0)
|
79
|
+
rspec-support (~> 3.10.0)
|
80
|
+
rspec-expectations (3.10.0)
|
75
81
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
-
rspec-support (~> 3.
|
77
|
-
rspec-mocks (3.
|
82
|
+
rspec-support (~> 3.10.0)
|
83
|
+
rspec-mocks (3.10.0)
|
78
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
-
rspec-support (~> 3.
|
80
|
-
rspec-support (3.
|
85
|
+
rspec-support (~> 3.10.0)
|
86
|
+
rspec-support (3.10.0)
|
87
|
+
ruby2_keywords (0.0.2)
|
81
88
|
sawyer (0.8.2)
|
82
89
|
addressable (>= 2.3.5)
|
83
90
|
faraday (> 0.8, < 2.0)
|
@@ -92,6 +99,7 @@ PLATFORMS
|
|
92
99
|
|
93
100
|
DEPENDENCIES
|
94
101
|
bundler (~> 2.1)
|
102
|
+
faker
|
95
103
|
git_helper!
|
96
104
|
guard-rspec (~> 4.3)
|
97
105
|
rake (~> 13.0)
|
data/Guardfile
CHANGED
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) ![
|
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
|
|
@@ -6,16 +6,18 @@
|
|
6
6
|
gem install git_helper
|
7
7
|
```
|
8
8
|
|
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 `~/.
|
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:
|
12
|
+
:github_user: GITHUB-USERNAME
|
13
13
|
:github_token: GITHUB-TOKEN
|
14
|
-
:gitlab_user:
|
14
|
+
:gitlab_user: GITLAB-USERNAME
|
15
15
|
:gitlab_token: GITLAB-TOKEN
|
16
16
|
```
|
17
17
|
|
18
|
-
To
|
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
|
```
|
@@ -30,15 +32,22 @@ git-helper --version
|
|
30
32
|
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:
|
31
33
|
|
32
34
|
```bash
|
33
|
-
# As a Gem
|
34
|
-
git-helper clean-branches
|
35
|
-
git-helper
|
35
|
+
# As a Gem # As a Plugin
|
36
|
+
git-helper clean-branches git clean-branches
|
37
|
+
git-helper code-request --create git code-request --create
|
38
|
+
```
|
39
|
+
|
40
|
+
To do this, download the `plugins.zip` file in the root of this directory. Unzip and place the contents in the appropriate location:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
mkdir ~/.git_helper
|
44
|
+
unzip path/to/downloaded/plugins.zip -d ~/.git_helper
|
36
45
|
```
|
37
46
|
|
38
|
-
|
47
|
+
Now, the plugins will live in `~/.git_helper/plugins/*`. Add the following line to your `~/.bash_profile`:
|
39
48
|
|
40
49
|
```
|
41
|
-
export PATH=/
|
50
|
+
export PATH=/path/to/computer/home/.git_helper/plugins:$PATH
|
42
51
|
```
|
43
52
|
|
44
53
|
And then run `source ~/.bash_profile`.
|
@@ -101,7 +110,7 @@ git-helper clean-branches
|
|
101
110
|
|
102
111
|
### `code-request`
|
103
112
|
|
104
|
-
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
|
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).
|
105
114
|
|
106
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`.
|
107
116
|
|
@@ -115,7 +124,7 @@ If you're trying to create a code request, the command will provide an autogener
|
|
115
124
|
|
116
125
|
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.
|
117
126
|
|
118
|
-
Lastly, for GitHub, it'll ask the user to apply any
|
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.
|
119
128
|
|
120
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.
|
121
130
|
|
data/Rakefile
CHANGED
@@ -1,37 +1 @@
|
|
1
|
-
|
2
|
-
begin
|
3
|
-
require 'bundler/setup'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'rdoc/task'
|
9
|
-
rescue LoadError
|
10
|
-
require 'rdoc/rdoc'
|
11
|
-
require 'rake/rdoctask'
|
12
|
-
RDoc::Task = Rake::RDocTask
|
13
|
-
end
|
14
|
-
|
15
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
-
rdoc.rdoc_dir = 'rdoc'
|
17
|
-
rdoc.title = 'Hubstats'
|
18
|
-
rdoc.options << '--line-numbers'
|
19
|
-
rdoc.rdoc_files.include('README.rdoc')
|
20
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
-
end
|
22
|
-
|
23
|
-
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
-
load 'rails/tasks/engine.rake'
|
25
|
-
|
26
|
-
Bundler::GemHelper.install_tasks
|
27
|
-
|
28
|
-
require 'rake/testtask'
|
29
|
-
|
30
|
-
Rake::TestTask.new(:test) do |t|
|
31
|
-
t.libs << 'lib'
|
32
|
-
t.libs << 'test'
|
33
|
-
t.pattern = 'test/**/*_test.rb'
|
34
|
-
t.verbose = false
|
35
|
-
end
|
36
|
-
|
37
|
-
task :default => :test
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/git-helper
CHANGED
@@ -22,16 +22,14 @@ arg :new_owner
|
|
22
22
|
desc "Update a repository's remote URLs from an old GitHub owner to a new owner."
|
23
23
|
command 'change-remote' do |c|
|
24
24
|
c.action do |global_options, options, args|
|
25
|
-
require_relative '../lib/git_helper/change_remote.rb'
|
26
25
|
raise ArgumentError, 'You must specify an old owner and a new owner' unless args.count == 2
|
27
26
|
GitHelper::ChangeRemote.new(args[0], args[1]).execute
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
desc
|
30
|
+
desc 'Checks out the default branch of a repo based on the local remote branches.'
|
32
31
|
command 'checkout-default' do |c|
|
33
32
|
c.action do |global_options, options, args|
|
34
|
-
require_relative '../lib/git_helper/checkout_default.rb'
|
35
33
|
GitHelper::CheckoutDefault.new.execute
|
36
34
|
end
|
37
35
|
end
|
@@ -39,23 +37,20 @@ end
|
|
39
37
|
desc "Clean a repository's git branches."
|
40
38
|
command 'clean-branches' do |c|
|
41
39
|
c.action do |global_options, options, args|
|
42
|
-
require_relative '../lib/git_helper/clean_branches.rb'
|
43
40
|
GitHelper::CleanBranches.new.execute
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
47
|
-
desc
|
44
|
+
desc 'Creates an empty commit with a basic commit message.'
|
48
45
|
command 'empty-commit' do |c|
|
49
46
|
c.action do |global_options, options, args|
|
50
|
-
require_relative '../lib/git_helper/empty_commit.rb'
|
51
47
|
GitHelper::EmptyCommit.new.execute
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
55
|
-
desc
|
51
|
+
desc 'Reset your local git commits to origin/HEAD.'
|
56
52
|
command 'forget-local-commits' do |c|
|
57
53
|
c.action do |global_options, options, args|
|
58
|
-
require_relative '../lib/git_helper/forget_local_commits.rb'
|
59
54
|
GitHelper::ForgetLocalCommits.new.execute
|
60
55
|
end
|
61
56
|
end
|
@@ -64,7 +59,6 @@ arg :new_branch_name, optional: true
|
|
64
59
|
desc 'Create a new branch for features, bug fixes, or experimentation.'
|
65
60
|
command 'new-branch' do |c|
|
66
61
|
c.action do |global_options, options, args|
|
67
|
-
require_relative '../lib/git_helper/new_branch.rb'
|
68
62
|
GitHelper::NewBranch.new.execute(args[0])
|
69
63
|
end
|
70
64
|
end
|
@@ -75,7 +69,6 @@ command 'code-request' do |c|
|
|
75
69
|
c.switch [:m, :merge], desc: 'Merge an existing pull/merge request'
|
76
70
|
|
77
71
|
c.action do |global_options, options, args|
|
78
|
-
require_relative '../lib/git_helper/code_request.rb'
|
79
72
|
raise ArgumentError, "You must specify an action (either '-m'/'--merge' or '-c'/'--create')" unless options[:create] || options[:merge]
|
80
73
|
|
81
74
|
options = global_options.merge(options)
|
data/lib/git_helper.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
require 'highline'
|
2
1
|
require 'yaml'
|
3
2
|
require 'gitlab'
|
3
|
+
require 'highline'
|
4
4
|
require 'octokit'
|
5
|
-
|
5
|
+
|
6
|
+
Dir[File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper')) + '/**/*.rb'].each do |file|
|
7
|
+
require_relative file
|
8
|
+
end
|
6
9
|
|
7
10
|
module GitHelper; end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
module GitHelper
|
2
2
|
class LocalCode
|
3
3
|
def checkout_default
|
4
|
-
system(
|
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(
|
9
|
-
system(
|
8
|
+
system('git pull')
|
9
|
+
system('git reset --hard origin/HEAD')
|
10
10
|
end
|
11
11
|
|
12
12
|
def empty_commit
|
13
|
-
system(
|
13
|
+
system('git commit --allow-empty -m \"Empty commit\"')
|
14
14
|
end
|
15
15
|
|
16
16
|
def clean_branches
|
17
|
-
system(
|
18
|
-
system(
|
19
|
-
system(
|
20
|
-
system(
|
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(
|
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(
|
88
|
+
def template_options(identifiers)
|
89
89
|
nested_templates = Dir.glob(
|
90
|
-
File.join("
|
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(
|
94
|
+
File.join(identifiers[:template_directory], "#{identifiers[:non_nested_file_name]}.md"),
|
95
95
|
File::FNM_DOTMATCH | File::FNM_CASEFOLD
|
96
96
|
)
|
97
|
-
|
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)
|
@@ -1,7 +1,3 @@
|
|
1
|
-
require_relative './gitlab_client.rb'
|
2
|
-
require_relative './highline_cli.rb'
|
3
|
-
require_relative './local_code.rb'
|
4
|
-
|
5
1
|
module GitHelper
|
6
2
|
class GitLabMergeRequest
|
7
3
|
attr_accessor :local_project, :local_branch, :local_code, :cli, :base_branch, :new_mr_title
|
@@ -101,6 +97,7 @@ module GitHelper
|
|
101
97
|
|
102
98
|
private def mr_template_options
|
103
99
|
@mr_template_options ||= local_code.template_options({
|
100
|
+
template_directory: '.gitlab',
|
104
101
|
nested_directory_name: 'merge_request_templates',
|
105
102
|
non_nested_file_name: 'merge_request_template'
|
106
103
|
})
|