git_helper 2.0.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -20
- data/Guardfile +2 -2
- data/README.md +43 -21
- data/Rakefile +1 -1
- data/bin/git-helper +12 -16
- data/lib/git_helper.rb +6 -1
- data/lib/git_helper/git_config_reader.rb +1 -3
- data/lib/git_helper/gitlab_client.rb +0 -2
- 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 -0
- data/lib/git_helper/octokit_client.rb +0 -2
- data/lib/git_helper/pull_request.rb +1 -0
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +18 -15
- data/spec/git_helper/code_request_spec.rb +20 -17
- data/spec/git_helper/git_config_reader_spec.rb +9 -7
- data/spec/git_helper/highline_cli_spec.rb +38 -36
- data/spec/git_helper/local_code_spec.rb +63 -26
- data/spec/git_helper/merge_request_spec.rb +49 -32
- data/spec/git_helper/new_branch_spec.rb +1 -0
- data/spec/git_helper/pull_request_spec.rb +39 -31
- data/spec/spec_helper.rb +2 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f85140fd3f9789ce420906994b5918e2fbb1318691829977c5234dbbb6be4867
|
4
|
+
data.tar.gz: 63cf9ee23e0d32e829c738feb4fcc5d195c034cd814e4ed1af109ff10984be6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28dcdae4082f67e060fa3aa2f31e600103a6abc50daa8f0b349034aaed9cbdfed0231ed1b9a75374483e2a37753b2482905d82c3150210af8e567ea3e6b2ac4
|
7
|
+
data.tar.gz: 3bc7be22d5bd115e7cd1d565cc0814d181f4ded6826d4aee8e58d0ba05a4d2fb773fbfa2486fab144a05780b60f846bd524ad408758677c9fad4776196931481
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (
|
4
|
+
git_helper (3.1.3)
|
5
5
|
gitlab (~> 4.16)
|
6
6
|
gli (~> 2.13)
|
7
7
|
highline (~> 2.0)
|
@@ -13,13 +13,17 @@ 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.15.1)
|
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
|
-
gitlab (4.
|
22
|
-
httparty (~> 0.
|
25
|
+
gitlab (4.17.0)
|
26
|
+
httparty (~> 0.18)
|
23
27
|
terminal-table (~> 1.5, >= 1.5.1)
|
24
28
|
gli (2.19.2)
|
25
29
|
guard (2.16.2)
|
@@ -40,21 +44,23 @@ GEM
|
|
40
44
|
httparty (0.18.1)
|
41
45
|
mime-types (~> 3.0)
|
42
46
|
multi_xml (>= 0.5.2)
|
43
|
-
|
47
|
+
i18n (1.8.5)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
listen (3.3.3)
|
44
50
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
45
51
|
rb-inotify (~> 0.9, >= 0.9.10)
|
46
52
|
lumberjack (1.2.8)
|
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)
|
@@ -89,13 +96,15 @@ GEM
|
|
89
96
|
|
90
97
|
PLATFORMS
|
91
98
|
ruby
|
99
|
+
x86_64-darwin-19
|
92
100
|
|
93
101
|
DEPENDENCIES
|
94
|
-
bundler (~> 2.
|
102
|
+
bundler (~> 2.2)
|
103
|
+
faker
|
95
104
|
git_helper!
|
96
105
|
guard-rspec (~> 4.3)
|
97
106
|
rake (~> 13.0)
|
98
107
|
rspec (~> 3.9)
|
99
108
|
|
100
109
|
BUNDLED WITH
|
101
|
-
2.
|
110
|
+
2.2.0
|
data/Guardfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
guard :rspec, cmd: 'bundle exec rspec', all_on_start: true
|
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') {
|
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) ![
|
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 code-request
|
35
|
+
# As a Gem # As a Plugin
|
36
|
+
git-helper clean-branches git clean-branches
|
37
|
+
git-helper code-request git code-request
|
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,25 +110,21 @@ 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
|
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).
|
105
114
|
|
106
|
-
After setup is complete, you can call the
|
115
|
+
After setup is complete, you can call the command like this:
|
107
116
|
|
108
117
|
```bash
|
109
|
-
git-helper code-request
|
110
|
-
# OR
|
111
|
-
git-helper code-request -m
|
118
|
+
git-helper code-request
|
112
119
|
```
|
113
120
|
|
114
|
-
|
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.
|
115
122
|
|
116
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.
|
117
124
|
|
118
|
-
|
119
|
-
|
120
|
-
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.
|
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.
|
121
126
|
|
122
|
-
|
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.
|
123
128
|
|
124
129
|
### `empty-commit`
|
125
130
|
|
@@ -137,6 +142,23 @@ This command is handy if you locally have a bunch of commits you wish to complet
|
|
137
142
|
git-helper forget-local-commits
|
138
143
|
```
|
139
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
|
+
|
140
162
|
### `new-branch`
|
141
163
|
|
142
164
|
This command is useful for making new branches in a repository on the command line. To run the command, run:
|
@@ -155,7 +177,7 @@ To submit a feature request, bug ticket, etc, please submit an official [GitHub
|
|
155
177
|
|
156
178
|
To report any security vulnerabilities, please view this project's [Security Policy](https://github.com/emmasax4/git_helper/security/policy).
|
157
179
|
|
158
|
-
|
180
|
+
When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
|
159
181
|
|
160
182
|
## Releasing
|
161
183
|
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/git-helper
CHANGED
@@ -27,7 +27,7 @@ command 'change-remote' do |c|
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
desc
|
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
|
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
|
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 '
|
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
|
-
|
73
|
-
|
74
|
-
|
69
|
+
GitHelper::CodeRequest.new.merge
|
70
|
+
end
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
|
data/lib/git_helper.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
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,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)
|
@@ -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
|
})
|
data/lib/git_helper/version.rb
CHANGED
data/plugins.zip
ADDED
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) {
|
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:
|
15
|
+
remote_name: Faker::Lorem.word,
|
10
16
|
ssh_remote?: true,
|
11
17
|
https_remote?: false,
|
12
|
-
remote_project:
|
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(
|
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(
|
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,
|
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,
|
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,
|
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) {
|
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:
|
142
|
+
remote_name: Faker::Lorem.word,
|
140
143
|
ssh_remote?: false,
|
141
144
|
https_remote?: false,
|
142
|
-
remote_project:
|
145
|
+
remote_project: project,
|
143
146
|
remote_source: 'github.com',
|
144
147
|
change_remote: true
|
145
148
|
)
|