git_helper 3.1.2 → 3.3.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 +24 -22
- data/Guardfile +1 -1
- 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 +4 -4
- data/lib/git_helper/highline_cli.rb +12 -68
- data/lib/git_helper/local_code.rb +1 -1
- 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 +87 -0
- data/lib/git_helper/version.rb +1 -1
- data/plugins.zip +0 -0
- data/spec/git_helper/change_remote_spec.rb +3 -2
- data/spec/git_helper/code_request_spec.rb +26 -24
- data/spec/git_helper/highline_cli_spec.rb +18 -184
- data/spec/git_helper/local_code_spec.rb +1 -0
- data/spec/git_helper/merge_request_spec.rb +29 -19
- data/spec/git_helper/new_branch_spec.rb +3 -2
- data/spec/git_helper/pull_request_spec.rb +17 -16
- data/spec/git_helper/setup_spec.rb +170 -0
- metadata +21 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9c80aa14abd85f6ebcff1a7c6592e71e4222273c8239c14c45ef905c4a3e549
|
4
|
+
data.tar.gz: 973f3831d8587d46d5e37c7738b50b5f8bab12bab9b2ec3d8ef34379b61917ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4515350964ec6a6e998a912d5b53cc49c8f90bd6d9cf9acfa5a3d499ffbad71638068266716971924efd76d6692a7aa1a1523cbcefc5c20eaeaf8e99805689aa
|
7
|
+
data.tar.gz: bfee7c84bc7d5a9a54172779bccbdbb56e0ad22f3776f8dc2d00228149ffcdf5de4dc5f3b5182aa92c6add8eec30cb0a70b7f8184fb5e1a8c8a2da2bf621007b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (3.0
|
4
|
+
git_helper (3.3.0)
|
5
5
|
gitlab (~> 4.16)
|
6
6
|
gli (~> 2.13)
|
7
7
|
highline (~> 2.0)
|
@@ -13,17 +13,19 @@ 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
|
-
faker (2.
|
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
|
-
gitlab (4.
|
26
|
-
httparty (~> 0.
|
27
|
+
gitlab (4.17.0)
|
28
|
+
httparty (~> 0.18)
|
27
29
|
terminal-table (~> 1.5, >= 1.5.1)
|
28
30
|
gli (2.19.2)
|
29
31
|
guard (2.16.2)
|
@@ -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,35 +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
|
-
|
100
|
+
x86_64-darwin-19
|
99
101
|
|
100
102
|
DEPENDENCIES
|
101
|
-
bundler (~> 2.
|
102
|
-
faker
|
103
|
+
bundler (~> 2.2)
|
104
|
+
faker (~> 2.15)
|
103
105
|
git_helper!
|
104
106
|
guard-rspec (~> 4.3)
|
105
107
|
rake (~> 13.0)
|
106
108
|
rspec (~> 3.9)
|
107
109
|
|
108
110
|
BUNDLED WITH
|
109
|
-
2.
|
111
|
+
2.2.9
|
data/Guardfile
CHANGED
@@ -1,4 +1,4 @@
|
|
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
4
|
watch('spec/spec_helper.rb') { 'spec' }
|
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
|
|
@@ -8,12 +8,12 @@ module GitHelper
|
|
8
8
|
config_file[:github_token]
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
def git_config_file_path
|
12
|
+
Dir.pwd.scan(/\A\/[\w]*\/[\w]*\//).first << git_config_file
|
13
13
|
end
|
14
14
|
|
15
|
-
private def
|
16
|
-
|
15
|
+
private def config_file
|
16
|
+
YAML.load_file(git_config_file_path)
|
17
17
|
end
|
18
18
|
|
19
19
|
private def git_config_file
|
@@ -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,87 @@
|
|
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("Do you wish to set up the Git Helper plugins? (y/n)")
|
14
|
+
|
15
|
+
if answer
|
16
|
+
create_or_update_plugin_files
|
17
|
+
puts "\nNow add this line to your ~/.bash_profile:\n export PATH=/path/to/computer/home/.git_helper/plugins:$PATH"
|
18
|
+
puts "\nDone!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private def create_or_update_config_file
|
23
|
+
contents = generate_file_contents
|
24
|
+
puts "\nCreating or updating your #{config_file} file..."
|
25
|
+
File.open(config_file, 'w') { |file| file.puts contents }
|
26
|
+
puts "\nDone!\n\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
private def config_file_exists?
|
30
|
+
File.exists?(config_file)
|
31
|
+
end
|
32
|
+
|
33
|
+
private def generate_file_contents
|
34
|
+
file_contents = ''
|
35
|
+
|
36
|
+
if highline.ask_yes_no("Do you wish to set up GitHub credentials? (y/n)")
|
37
|
+
file_contents << ":github_user: #{ask_question('GitHub username?')}\n"
|
38
|
+
file_contents << ":github_token: " \
|
39
|
+
"#{ask_question('GitHub personal access token? (Navigate to https://github.com/settings/tokens ' \
|
40
|
+
'to create a new personal access token)')}\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
if highline.ask_yes_no("\nDo you wish to set up GitLab credentials? (y/n)")
|
44
|
+
file_contents << ":gitlab_user: #{ask_question('GitLab username?')}\n"
|
45
|
+
file_contents << ":gitlab_token: " \
|
46
|
+
"#{ask_question('GitLab personal access token? (Navigate to https://gitlab.com/-/profile/personal_access_tokens ' \
|
47
|
+
'to create a new personal access token)')}\n"
|
48
|
+
end
|
49
|
+
|
50
|
+
file_contents.strip
|
51
|
+
end
|
52
|
+
|
53
|
+
private def ask_question(prompt)
|
54
|
+
answer = highline.ask("\n#{prompt}")
|
55
|
+
|
56
|
+
if answer.empty?
|
57
|
+
puts "\nThis question is required."
|
58
|
+
ask_question(prompt)
|
59
|
+
else
|
60
|
+
answer
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private def highline
|
65
|
+
@highline ||= GitHelper::HighlineCli.new
|
66
|
+
end
|
67
|
+
|
68
|
+
private def config_file
|
69
|
+
GitHelper::GitConfigReader.new.git_config_file_path
|
70
|
+
end
|
71
|
+
|
72
|
+
private def create_or_update_plugin_files
|
73
|
+
plugins_dir = "#{Dir.pwd.scan(/\A\/[\w]*\/[\w]*\//).first}/.git_helper/plugins"
|
74
|
+
plugins_url = 'https://api.github.com/repos/emmahsax/git_helper/contents/plugins'
|
75
|
+
header = 'Accept: application/vnd.github.v3.raw'
|
76
|
+
|
77
|
+
Dir.mkdir(plugins_dir) unless File.exists?(plugins_dir)
|
78
|
+
|
79
|
+
all_plugins = JSON.parse(`curl -s -H "#{header}" -L "#{plugins_url}"`)
|
80
|
+
|
81
|
+
all_plugins.each do |plugin|
|
82
|
+
plugin_content = `curl -s -H "#{header}" -L "#{plugins_url}/#{plugin['name']}"`
|
83
|
+
File.open("#{plugins_dir}/#{plugin['name']}", 'w') { |file| file.puts plugin_content }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|