git_helper 3.1.3 → 3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -18
- data/README.md +11 -6
- data/bin/git-helper +8 -1
- data/lib/git_helper/change_remote.rb +1 -1
- data/lib/git_helper/code_request.rb +6 -5
- data/lib/git_helper/git_config_reader.rb +11 -3
- data/lib/git_helper/highline_cli.rb +12 -68
- data/lib/git_helper/merge_request.rb +5 -5
- data/lib/git_helper/new_branch.rb +1 -1
- data/lib/git_helper/pull_request.rb +4 -4
- data/lib/git_helper/setup.rb +96 -0
- data/lib/git_helper/version.rb +1 -1
- data/spec/git_helper/change_remote_spec.rb +2 -2
- data/spec/git_helper/code_request_spec.rb +25 -24
- data/spec/git_helper/git_config_reader_spec.rb +28 -2
- data/spec/git_helper/highline_cli_spec.rb +18 -184
- data/spec/git_helper/merge_request_spec.rb +14 -14
- data/spec/git_helper/new_branch_spec.rb +2 -2
- data/spec/git_helper/pull_request_spec.rb +12 -12
- data/spec/git_helper/setup_spec.rb +175 -0
- metadata +19 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be948f58bc902f2e3036bfc3379279afcc74012af9cb56ee1b1f8586ba9c0fa2
|
4
|
+
data.tar.gz: c4f8655fcaef1db1fba03ebb731932da6d185bb89c46ebc366781309b76ebd1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d19cf35a128b640a265aa89f229022fd7be3629e6e8ae5f6f08504494b1ccc5231af4ff1e39fbd3014ddb78e8757dd1a9413110872bdd7c8da8ae86525e7776a
|
7
|
+
data.tar.gz: d50eb1904c56c2269c139f7275321eef5516c70de6973fb2b11f8ea0f6681f5db5389f3f629c8b16718a7390442031e4999d8620a3814647b64dae340c01b8d1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (3.1
|
4
|
+
git_helper (3.3.1)
|
5
5
|
gitlab (~> 4.16)
|
6
6
|
gli (~> 2.13)
|
7
7
|
highline (~> 2.0)
|
@@ -13,14 +13,16 @@ 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.
|
16
|
+
concurrent-ruby (1.1.8)
|
17
17
|
diff-lcs (1.4.4)
|
18
18
|
faker (2.15.1)
|
19
19
|
i18n (>= 1.6, < 2)
|
20
|
-
faraday (1.
|
20
|
+
faraday (1.3.0)
|
21
|
+
faraday-net_http (~> 1.0)
|
21
22
|
multipart-post (>= 1.2, < 3)
|
22
23
|
ruby2_keywords
|
23
|
-
|
24
|
+
faraday-net_http (1.0.1)
|
25
|
+
ffi (1.14.2)
|
24
26
|
formatador (0.2.5)
|
25
27
|
gitlab (4.17.0)
|
26
28
|
httparty (~> 0.18)
|
@@ -44,9 +46,9 @@ GEM
|
|
44
46
|
httparty (0.18.1)
|
45
47
|
mime-types (~> 3.0)
|
46
48
|
multi_xml (>= 0.5.2)
|
47
|
-
i18n (1.8.
|
49
|
+
i18n (1.8.8)
|
48
50
|
concurrent-ruby (~> 1.0)
|
49
|
-
listen (3.
|
51
|
+
listen (3.4.1)
|
50
52
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
51
53
|
rb-inotify (~> 0.9, >= 0.9.10)
|
52
54
|
lumberjack (1.2.8)
|
@@ -60,14 +62,14 @@ GEM
|
|
60
62
|
notiffany (0.1.3)
|
61
63
|
nenv (~> 0.1)
|
62
64
|
shellany (~> 0.0)
|
63
|
-
octokit (4.
|
65
|
+
octokit (4.20.0)
|
64
66
|
faraday (>= 0.9)
|
65
67
|
sawyer (~> 0.8.0, >= 0.5.3)
|
66
|
-
pry (0.
|
68
|
+
pry (0.14.0)
|
67
69
|
coderay (~> 1.1)
|
68
70
|
method_source (~> 1.0)
|
69
71
|
public_suffix (4.0.6)
|
70
|
-
rake (13.0.
|
72
|
+
rake (13.0.3)
|
71
73
|
rb-fsevent (0.10.4)
|
72
74
|
rb-inotify (0.10.1)
|
73
75
|
ffi (~> 1.0)
|
@@ -75,36 +77,35 @@ GEM
|
|
75
77
|
rspec-core (~> 3.10.0)
|
76
78
|
rspec-expectations (~> 3.10.0)
|
77
79
|
rspec-mocks (~> 3.10.0)
|
78
|
-
rspec-core (3.10.
|
80
|
+
rspec-core (3.10.1)
|
79
81
|
rspec-support (~> 3.10.0)
|
80
|
-
rspec-expectations (3.10.
|
82
|
+
rspec-expectations (3.10.1)
|
81
83
|
diff-lcs (>= 1.2.0, < 2.0)
|
82
84
|
rspec-support (~> 3.10.0)
|
83
|
-
rspec-mocks (3.10.
|
85
|
+
rspec-mocks (3.10.2)
|
84
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
85
87
|
rspec-support (~> 3.10.0)
|
86
|
-
rspec-support (3.10.
|
87
|
-
ruby2_keywords (0.0.
|
88
|
+
rspec-support (3.10.2)
|
89
|
+
ruby2_keywords (0.0.4)
|
88
90
|
sawyer (0.8.2)
|
89
91
|
addressable (>= 2.3.5)
|
90
92
|
faraday (> 0.8, < 2.0)
|
91
93
|
shellany (0.0.1)
|
92
94
|
terminal-table (1.8.0)
|
93
95
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
94
|
-
thor (1.0
|
96
|
+
thor (1.1.0)
|
95
97
|
unicode-display_width (1.7.0)
|
96
98
|
|
97
99
|
PLATFORMS
|
98
|
-
ruby
|
99
100
|
x86_64-darwin-19
|
100
101
|
|
101
102
|
DEPENDENCIES
|
102
103
|
bundler (~> 2.2)
|
103
|
-
faker
|
104
|
+
faker (~> 2.15)
|
104
105
|
git_helper!
|
105
106
|
guard-rspec (~> 4.3)
|
106
107
|
rake (~> 13.0)
|
107
108
|
rspec (~> 3.9)
|
108
109
|
|
109
110
|
BUNDLED WITH
|
110
|
-
2.2.
|
111
|
+
2.2.9
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# git_helper [](https://codeclimate.com/github/emmahsax/git_helper/maintainability) [](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/
|
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/
|
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/
|
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/
|
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/bin/git-helper
CHANGED
@@ -14,9 +14,16 @@ wrap_help_text :verbatim
|
|
14
14
|
program_long_desc """
|
15
15
|
DOCUMENTATION
|
16
16
|
For documentation and help in setting up your Git configuration files,
|
17
|
-
see Git Helper's GitHub repo: https://github.com/
|
17
|
+
see Git Helper's GitHub repo: https://github.com/emmahsax/git_helper
|
18
18
|
"""
|
19
19
|
|
20
|
+
desc 'Sets up Git Helper configs at ~/.git_helper/*'
|
21
|
+
command 'setup' do |c|
|
22
|
+
c.action do ||
|
23
|
+
GitHelper::Setup.new.execute
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
20
27
|
arg :old_owner
|
21
28
|
arg :new_owner
|
22
29
|
desc "Update a repository's remote URLs from an old GitHub owner to a new owner."
|
@@ -23,7 +23,7 @@ module GitHelper
|
|
23
23
|
Dir.chdir(current_dir)
|
24
24
|
|
25
25
|
if File.exist?('.git')
|
26
|
-
process_git_repository if cli.
|
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
27
|
end
|
28
28
|
|
29
29
|
Dir.chdir(original_dir)
|
@@ -24,7 +24,7 @@ module GitHelper
|
|
24
24
|
end
|
25
25
|
|
26
26
|
private def ask_for_clarification
|
27
|
-
resp = cli.
|
27
|
+
resp = cli.ask('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').downcase
|
28
28
|
if resp.include?('hub')
|
29
29
|
github_pull_request
|
30
30
|
elsif resp.include?('lab')
|
@@ -61,10 +61,10 @@ module GitHelper
|
|
61
61
|
end
|
62
62
|
|
63
63
|
private def base_branch
|
64
|
-
@base_branch ||= if cli.
|
64
|
+
@base_branch ||= if cli.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
|
65
65
|
default_branch
|
66
66
|
else
|
67
|
-
cli.
|
67
|
+
cli.ask('Base branch?')
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -77,10 +77,11 @@ module GitHelper
|
|
77
77
|
end
|
78
78
|
|
79
79
|
private def new_code_request_title
|
80
|
-
@new_code_request_title ||= if
|
80
|
+
@new_code_request_title ||= if autogenerated_title &&
|
81
|
+
cli.ask_yes_no("Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)")
|
81
82
|
autogenerated_title
|
82
83
|
else
|
83
|
-
cli.
|
84
|
+
cli.ask('Title?')
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
@@ -4,18 +4,26 @@ module GitHelper
|
|
4
4
|
config_file[:gitlab_token]
|
5
5
|
end
|
6
6
|
|
7
|
+
def gitlab_user
|
8
|
+
config_file[:gitlab_user]
|
9
|
+
end
|
10
|
+
|
7
11
|
def github_token
|
8
12
|
config_file[:github_token]
|
9
13
|
end
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
def github_user
|
16
|
+
config_file[:github_user]
|
13
17
|
end
|
14
18
|
|
15
|
-
|
19
|
+
def git_config_file_path
|
16
20
|
Dir.pwd.scan(/\A\/[\w]*\/[\w]*\//).first << git_config_file
|
17
21
|
end
|
18
22
|
|
23
|
+
private def config_file
|
24
|
+
YAML.load_file(git_config_file_path)
|
25
|
+
end
|
26
|
+
|
19
27
|
private def git_config_file
|
20
28
|
'.git_helper/config.yml'
|
21
29
|
end
|
@@ -1,85 +1,29 @@
|
|
1
1
|
module GitHelper
|
2
2
|
class HighlineCli
|
3
|
-
def
|
4
|
-
ask(
|
5
|
-
|
6
|
-
|
7
|
-
def process_directory_remotes?(directory)
|
8
|
-
answer = ask("Found git directory: #{directory}. Do you wish to proceed in updating #{directory}'s remote URLs? (y/n)")
|
9
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
10
|
-
end
|
11
|
-
|
12
|
-
def conflicting_remote_clarification
|
13
|
-
ask('Found git remotes for both GitHub and GitLab. Would you like to proceed with GitLab or GitHub? (github/gitlab)').downcase
|
14
|
-
end
|
15
|
-
|
16
|
-
def title
|
17
|
-
ask('Title?')
|
18
|
-
end
|
19
|
-
|
20
|
-
def base_branch
|
21
|
-
ask('Base branch?')
|
22
|
-
end
|
23
|
-
|
24
|
-
def code_request_id(request_type)
|
25
|
-
ask("#{request_type} Request ID?")
|
26
|
-
end
|
27
|
-
|
28
|
-
def accept_autogenerated_title?(autogenerated_title)
|
29
|
-
return false unless autogenerated_title
|
30
|
-
answer = ask("Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)")
|
31
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
32
|
-
end
|
33
|
-
|
34
|
-
def base_branch_default?(default_branch)
|
35
|
-
answer = ask("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
|
36
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
37
|
-
end
|
38
|
-
|
39
|
-
def squash_merge_request?
|
40
|
-
answer = ask('Squash merge request? (y/n)')
|
41
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
42
|
-
end
|
43
|
-
|
44
|
-
def remove_source_branch?
|
45
|
-
answer = ask('Remove source branch after merging? (y/n)')
|
46
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
47
|
-
end
|
48
|
-
|
49
|
-
def merge_method(merge_options)
|
50
|
-
index = ask_options("Merge method?", merge_options)
|
51
|
-
merge_options[index]
|
52
|
-
end
|
53
|
-
|
54
|
-
def apply_template?(template_file_name, request_type)
|
55
|
-
answer = ask("Apply the #{request_type} request template from #{template_file_name}? (y/n)")
|
56
|
-
answer.empty? ? true : !!(answer =~ /^y/i)
|
57
|
-
end
|
58
|
-
|
59
|
-
def template_to_apply(template_options, request_type)
|
60
|
-
complete_options = template_options << 'None'
|
61
|
-
index = ask_options("Which #{request_type} request template should be applied?", complete_options)
|
62
|
-
complete_options[index]
|
3
|
+
def ask(prompt)
|
4
|
+
highline_client.ask(prompt) do |conf|
|
5
|
+
conf.readline = true
|
6
|
+
end.to_s
|
63
7
|
end
|
64
8
|
|
65
|
-
|
66
|
-
|
67
|
-
#######################
|
68
|
-
|
69
|
-
private def ask(prompt)
|
70
|
-
highline_client.ask(prompt) do |conf|
|
9
|
+
def ask_yes_no(prompt)
|
10
|
+
answer = highline_client.ask(prompt) do |conf|
|
71
11
|
conf.readline = true
|
72
12
|
end.to_s
|
13
|
+
|
14
|
+
answer.empty? ? true : !!(answer =~ /^y/i)
|
73
15
|
end
|
74
16
|
|
75
|
-
|
17
|
+
def ask_options(prompt, choices)
|
76
18
|
choices_as_string_options = ''
|
77
19
|
choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
|
78
20
|
compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
|
79
21
|
|
80
|
-
highline_client.ask(compiled_prompt) do |conf|
|
22
|
+
index = highline_client.ask(compiled_prompt) do |conf|
|
81
23
|
conf.readline = true
|
82
24
|
end.to_i - 1
|
25
|
+
|
26
|
+
choices[index]
|
83
27
|
end
|
84
28
|
|
85
29
|
private def highline_client
|
@@ -84,10 +84,10 @@ module GitHelper
|
|
84
84
|
|
85
85
|
unless mr_template_options.empty?
|
86
86
|
if mr_template_options.count == 1
|
87
|
-
apply_single_template = cli.
|
87
|
+
apply_single_template = cli.ask_yes_no("Apply the merge request template from #{mr_template_options.first}? (y/n)")
|
88
88
|
@template_name_to_apply = mr_template_options.first if apply_single_template
|
89
89
|
else
|
90
|
-
response = cli.
|
90
|
+
response = cli.ask_options("Which merge request template should be applied?", mr_template_options << 'None')
|
91
91
|
@template_name_to_apply = response unless response == 'None'
|
92
92
|
end
|
93
93
|
end
|
@@ -104,15 +104,15 @@ module GitHelper
|
|
104
104
|
end
|
105
105
|
|
106
106
|
private def mr_id
|
107
|
-
@mr_id ||= cli.
|
107
|
+
@mr_id ||= cli.ask('Merge Request ID?')
|
108
108
|
end
|
109
109
|
|
110
110
|
private def squash_merge_request
|
111
|
-
@squash_merge_request ||= cli.
|
111
|
+
@squash_merge_request ||= cli.ask_yes_no('Squash merge request? (y/n)')
|
112
112
|
end
|
113
113
|
|
114
114
|
private def remove_source_branch
|
115
|
-
@remove_source_branch ||= existing_project.remove_source_branch_after_merge || cli.
|
115
|
+
@remove_source_branch ||= existing_project.remove_source_branch_after_merge || cli.ask_yes_no('Remove source branch after merging? (y/n)')
|
116
116
|
end
|
117
117
|
|
118
118
|
private def existing_project
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GitHelper
|
2
2
|
class NewBranch
|
3
3
|
def execute(new_branch_name = nil)
|
4
|
-
branch_name = new_branch_name || GitHelper::HighlineCli.new.
|
4
|
+
branch_name = new_branch_name || GitHelper::HighlineCli.new.ask('New branch name?')
|
5
5
|
puts "Attempting to create a new branch: #{branch_name}"
|
6
6
|
GitHelper::LocalCode.new.new_branch(branch_name)
|
7
7
|
end
|
@@ -81,10 +81,10 @@ module GitHelper
|
|
81
81
|
|
82
82
|
unless pr_template_options.empty?
|
83
83
|
if pr_template_options.count == 1
|
84
|
-
apply_single_template = cli.
|
84
|
+
apply_single_template = cli.ask_yes_no("Apply the pull request template from #{pr_template_options.first}? (y/n)")
|
85
85
|
@template_name_to_apply = pr_template_options.first if apply_single_template
|
86
86
|
else
|
87
|
-
response = cli.
|
87
|
+
response = cli.ask_options("Which pull request template should be applied?", pr_template_options << 'None')
|
88
88
|
@template_name_to_apply = response unless response == 'None'
|
89
89
|
end
|
90
90
|
end
|
@@ -101,11 +101,11 @@ module GitHelper
|
|
101
101
|
end
|
102
102
|
|
103
103
|
private def pr_id
|
104
|
-
@pr_id ||= cli.
|
104
|
+
@pr_id ||= cli.ask('Pull Request ID?')
|
105
105
|
end
|
106
106
|
|
107
107
|
private def merge_method
|
108
|
-
@merge_method ||= merge_options.length == 1 ? merge_options.first : cli.
|
108
|
+
@merge_method ||= merge_options.length == 1 ? merge_options.first : cli.ask_options('Merge method?', merge_options)
|
109
109
|
end
|
110
110
|
|
111
111
|
private def merge_options
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module GitHelper
|
2
|
+
class Setup
|
3
|
+
def execute
|
4
|
+
if config_file_exists?
|
5
|
+
answer = highline.ask_yes_no("It looks like the #{config_file} file already exists. Do you wish to replace it? (y/n)")
|
6
|
+
puts
|
7
|
+
else
|
8
|
+
answer = true
|
9
|
+
end
|
10
|
+
|
11
|
+
create_or_update_config_file if answer
|
12
|
+
|
13
|
+
answer = highline.ask_yes_no(
|
14
|
+
"Do you wish to set up the Git Helper plugins? (y/n) (This process will " \
|
15
|
+
"attempt to use your GitHub personal access token to authenticate)"
|
16
|
+
)
|
17
|
+
|
18
|
+
if answer
|
19
|
+
create_or_update_plugin_files
|
20
|
+
puts "\nNow add this line to your ~/.bash_profile:\n export PATH=/path/to/computer/home/.git_helper/plugins:$PATH"
|
21
|
+
puts "\nDone!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private def create_or_update_config_file
|
26
|
+
contents = generate_file_contents
|
27
|
+
puts "\nCreating or updating your #{config_file} file..."
|
28
|
+
File.open(config_file, 'w') { |file| file.puts contents }
|
29
|
+
puts "\nDone!\n\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
private def config_file_exists?
|
33
|
+
File.exists?(config_file)
|
34
|
+
end
|
35
|
+
|
36
|
+
private def generate_file_contents
|
37
|
+
file_contents = ''
|
38
|
+
|
39
|
+
if highline.ask_yes_no("Do you wish to set up GitHub credentials? (y/n)")
|
40
|
+
file_contents << ":github_user: #{ask_question('GitHub username?')}\n"
|
41
|
+
file_contents << ":github_token: " \
|
42
|
+
"#{ask_question('GitHub personal access token? (Navigate to https://github.com/settings/tokens ' \
|
43
|
+
'to create a new personal access token)')}\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
if highline.ask_yes_no("\nDo you wish to set up GitLab credentials? (y/n)")
|
47
|
+
file_contents << ":gitlab_user: #{ask_question('GitLab username?')}\n"
|
48
|
+
file_contents << ":gitlab_token: " \
|
49
|
+
"#{ask_question('GitLab personal access token? (Navigate to https://gitlab.com/-/profile/personal_access_tokens ' \
|
50
|
+
'to create a new personal access token)')}\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
file_contents.strip
|
54
|
+
end
|
55
|
+
|
56
|
+
private def ask_question(prompt)
|
57
|
+
answer = highline.ask("\n#{prompt}")
|
58
|
+
|
59
|
+
if answer.empty?
|
60
|
+
puts "\nThis question is required."
|
61
|
+
ask_question(prompt)
|
62
|
+
else
|
63
|
+
answer
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private def create_or_update_plugin_files
|
68
|
+
plugins_dir = "#{Dir.pwd.scan(/\A\/[\w]*\/[\w]*\//).first}/.git_helper/plugins"
|
69
|
+
plugins_url = 'https://api.github.com/repos/emmahsax/git_helper/contents/plugins'
|
70
|
+
header = 'Accept: application/vnd.github.v3.raw'
|
71
|
+
token = git_config_reader.github_token
|
72
|
+
user = git_config_reader.github_user
|
73
|
+
|
74
|
+
Dir.mkdir(plugins_dir) unless File.exists?(plugins_dir)
|
75
|
+
|
76
|
+
all_plugins = JSON.parse(`curl -s -u #{user}:#{token} -H "#{header}" -L "#{plugins_url}"`)
|
77
|
+
|
78
|
+
all_plugins.each do |plugin|
|
79
|
+
plugin_content = `curl -s -u #{user}:#{token} -H "#{header}" -L "#{plugins_url}/#{plugin['name']}"`
|
80
|
+
File.open("#{plugins_dir}/#{plugin['name']}", 'w') { |file| file.puts plugin_content }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private def config_file
|
85
|
+
git_config_reader.git_config_file_path
|
86
|
+
end
|
87
|
+
|
88
|
+
private def git_config_reader
|
89
|
+
@git_config_reader ||= GitHelper::GitConfigReader.new
|
90
|
+
end
|
91
|
+
|
92
|
+
private def highline
|
93
|
+
@highline ||= GitHelper::HighlineCli.new
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|