git_cli_prompt 0.1.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e0baf03b1eff4fcce89d777a0701742d9a87d8ca42a9e2b420b78fcafda4d8c
4
- data.tar.gz: e40cf5b3951335cc9472bac286323d784605711bdbe9e96395892dabc7f384f7
3
+ metadata.gz: 72d21c5ee4f2947afc05438cbc109f1980fd3b769e110416403e6b3fd83dafb7
4
+ data.tar.gz: 1f20e4705ef0128e50248e296d70ae1ed00f37e0b9e3dfdad3f599b0edbb590c
5
5
  SHA512:
6
- metadata.gz: 6b673ef6d30fa03773bf530162a9cc383c4035858126da8aa3c778357b120e252a1cea1e17ef8b638e4603cffc27326e3ad55b33d625b0cabbb2902fb6f692c2
7
- data.tar.gz: bd5e2adb046a397c84aa20d8dc287d679d6411c392f7b4e1524c7981d14ee97d00dba825df84584efb0f6f39e2c8503d8e2ed26390695416935a299a0f78541c
6
+ metadata.gz: 85efa3c204ec2f1093f3f30eac8b8d08c656346384b9b1176a93ac7995b747c5db74fde4d1112474d8c4c82488200177d59cf67461dcb6fb9157d9bd10184b94
7
+ data.tar.gz: 37539b3af0ead43e1df434cab6e86215a9e78a733a879738de336bb489f10560813b0d8b8ae76eb400f38ded158ca6f53bcdd4789670975b0cc4a5631d6b5287
@@ -0,0 +1,6 @@
1
+ ---
2
+ git_cli_prompt:
3
+ - :version: 0.1.2
4
+ :timestamp: 1635828173.1234875
5
+ - :version: 0.2.1
6
+ :timestamp: 1635828282.1326017
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_cli_prompt (0.2.2)
5
+ tlogger
6
+ toolrack
7
+ tty-prompt
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ base58 (0.2.3)
13
+ devops_assist (0.1.1)
14
+ git_cli
15
+ git_cli_prompt
16
+ gvcs
17
+ tlogger
18
+ toolrack
19
+ tty-prompt
20
+ diff-lcs (1.4.4)
21
+ git_cli (0.9.0)
22
+ gvcs
23
+ ptools (~> 1.4.0)
24
+ tlogger
25
+ toolrack
26
+ gvcs (0.1.0)
27
+ pastel (0.8.0)
28
+ tty-color (~> 0.5)
29
+ ptools (1.4.2)
30
+ rake (13.0.6)
31
+ rspec (3.10.0)
32
+ rspec-core (~> 3.10.0)
33
+ rspec-expectations (~> 3.10.0)
34
+ rspec-mocks (~> 3.10.0)
35
+ rspec-core (3.10.1)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-expectations (3.10.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-mocks (3.10.2)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-support (3.10.2)
44
+ tlogger (0.26.1)
45
+ toolrack (0.16.0)
46
+ base58
47
+ tlogger
48
+ tty-color (0.6.0)
49
+ tty-cursor (0.7.1)
50
+ tty-prompt (0.22.0)
51
+ pastel (~> 0.8)
52
+ tty-reader (~> 0.8)
53
+ tty-reader (0.9.0)
54
+ tty-cursor (~> 0.7)
55
+ tty-screen (~> 0.8)
56
+ wisper (~> 2.0)
57
+ tty-screen (0.8.1)
58
+ wisper (2.0.1)
59
+
60
+ PLATFORMS
61
+ x86_64-linux
62
+
63
+ DEPENDENCIES
64
+ devops_assist
65
+ git_cli_prompt!
66
+ rake (~> 13.0)
67
+ rspec (~> 3.0)
68
+
69
+ BUNDLED WITH
70
+ 2.2.28
data/Rakefile CHANGED
@@ -5,6 +5,6 @@ require "rspec/core/rake_task"
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require 'devops_helper'
8
+ require 'devops_assist'
9
9
 
10
10
  task default: :spec
@@ -35,7 +35,8 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_dependency "tty-prompt"
37
37
 
38
- spec.add_development_dependency "devops_helper"
38
+ #spec.add_development_dependency "devops_helper"
39
+ spec.add_development_dependency "devops_assist"
39
40
 
40
41
  # Uncomment to register a new dependency of your gem
41
42
  # spec.add_dependency "example-gem", "~> 1.0"
data/lib/commit.rb ADDED
@@ -0,0 +1,234 @@
1
+
2
+ require 'gvcs'
3
+ require 'git_cli'
4
+
5
+ require_relative 'git_cli_prompt/logger'
6
+
7
+ module GitCliPrompt
8
+ module Commit
9
+ include TR::CondUtils
10
+ include CliPrompt
11
+ include GitCliPrompt::Logger
12
+
13
+ class CommitError < StandardError; end
14
+
15
+ def commit(root,&block)
16
+
17
+ #logger.debug "Commit operation root : #{root}"
18
+ ws = Gvcs::Workspace.new(root)
19
+ raise CommitError, "Given path '#{File.expand_path(root)}' is not a VCS workspace" if not ws.is_workspace?
20
+
21
+ begin
22
+
23
+ modDir, modFiles = ws.modified_files
24
+ newDir, newFiles = ws.new_files
25
+ delDir, delFiles = ws.deleted_files
26
+ stDir, stFiles = ws.staged_files
27
+
28
+ pending = false
29
+ pending = true if not_empty?(modDir) or not_empty?(modFiles) or not_empty?(newDir) or not_empty?(newFiles) or not_empty?(delDir) or not_empty?(delFiles)
30
+
31
+ staged = false
32
+ staged = true if not_empty?(stDir) or not_empty?(stFiles)
33
+
34
+ if not_empty?(stDir) or not_empty?(stFiles)
35
+ say " Item(s) already staged for commit: \n"
36
+ stDir.each do |md|
37
+ say " #{md.path}"
38
+ end
39
+ stFiles.each do |md|
40
+ say " #{md.path}"
41
+ end
42
+ end
43
+
44
+ if pending
45
+
46
+ say "\n\n Items could be add to version control:\n"
47
+ cnt = 1
48
+ [modDir, modFiles, newDir, newFiles, delDir, delFiles].each do |cont|
49
+ cont.each do |md|
50
+ say " #{'%2s' % cnt}. #{md.to_s}\n"
51
+ cnt += 1
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+ puts
58
+
59
+ if not pending and not staged
60
+ pmt.say("\n Workspace is clean. No changes or unstage files or directory is found.\n", color: :green)
61
+ "Workspace is clean. No changes or unstage files or directory is found"
62
+
63
+ else
64
+
65
+ ops = pmt.select(" Please select desired operation:") do |menu|
66
+ menu.default 1
67
+
68
+ menu.choice " Add", :add if pending
69
+ if not_empty?(stDir) or not_empty?(stFiles)
70
+ menu.choice " Remove file from staged", :remove_staged
71
+ menu.choice " Commit staged", :commit
72
+ end
73
+ menu.choice " Ignore changes", :ignore
74
+ menu.choice " Quit", :quit
75
+ end
76
+
77
+ case ops
78
+ when :add
79
+ choices = []
80
+ choices += mark_modified_choice(modDir)
81
+ choices += mark_modified_choice(modFiles)
82
+ choices += mark_new_choice(newDir)
83
+ choices += mark_new_choice(newFiles)
84
+ choices += mark_del_choice(delDir)
85
+ choices += mark_del_choice(delFiles)
86
+
87
+ prompt_add_selection(ws, choices, &block)
88
+ commit_staged(ws, &block)
89
+
90
+ when :ignore
91
+ pmt.ok "\n Changes are ignored for this release", color: :yellow
92
+
93
+ when :quit
94
+ raise UserChangedMind
95
+
96
+ when :remove_staged
97
+
98
+ choices = []
99
+ choices += stDir.map { |v| [v.path,v] }
100
+ choices += stFiles.map { |v| [v.path,v] }
101
+
102
+ sel = prompt_remove_staging(choices)
103
+ ws.remove_from_staging(sel)
104
+
105
+ when :commit
106
+
107
+ commit_staged(ws, &block)
108
+
109
+ end
110
+ end
111
+
112
+
113
+ rescue TTY::Reader::InputInterrupt
114
+ ok "\n\n Aborted"
115
+
116
+ #rescue UserChangedMind
117
+ # ok "\n Noted. Please retry the process again\n"
118
+
119
+ #rescue UserSelectNone
120
+ # ok "\n Nothing is selected. Process halted\n"
121
+
122
+ #rescue Exception => ex
123
+ # error(ex.message)
124
+ # logger.error ex.message
125
+ # logger.error ex.backtrace.join('\n')
126
+
127
+ end
128
+ end
129
+
130
+ def prompt_remove_staging(choices)
131
+
132
+ sel = pmt.select(" Please select which item(s) to remove from staging:") do |menu|
133
+
134
+ choices.each do |c|
135
+ menu.choice c[0], c[1]
136
+ end
137
+
138
+ end
139
+
140
+ raise UserSelectNone, " No selection of staged item(s) were made" if is_empty?(sel)
141
+ if confirm_selection(sel)
142
+ sel
143
+ else
144
+ raise UserChangedMind, " User aborted"
145
+ end
146
+
147
+ end
148
+
149
+ def prompt_add_selection(ws, choices, &block)
150
+
151
+ sel = multi_select(" Please select which items to add to this commit session:") do |menu|
152
+ choices.each do |c|
153
+ menu.choice c[0], c[1]
154
+ end
155
+ end
156
+
157
+ raise UserSelectNone, " No selection of unversioned item(s) was made" if is_empty?(sel)
158
+ if confirm_selection(sel)
159
+ psel = vcs_items_to_path_array(sel)
160
+ ws.add_to_staging(psel)
161
+ else
162
+ raise UserChangedMind, " User aborted"
163
+ end
164
+
165
+ end
166
+
167
+ def confirm_selection(sel)
168
+
169
+ sel = [sel] if not sel.is_a?(Array)
170
+ cs = []
171
+ cnt = 1
172
+ sel.each do |s|
173
+ cs << "#{"%2s" % cnt.to_s}. #{s}"
174
+ cnt += 1
175
+ end
176
+
177
+ yes?(" You've selected the following item(s). Proceed?\n#{cs.join("\n")}\n")
178
+
179
+ end
180
+
181
+ def prompt_commit_message(&block)
182
+
183
+ if block
184
+ defMsg = block.call(:default_commit_message)
185
+ end
186
+
187
+ msg = pmt.ask(" Commit Message :", required: true) do |m|
188
+ m.default = defMsg if not_empty?(defMsg)
189
+ end
190
+
191
+ msg
192
+ end
193
+
194
+ def commit_staged(ws, &block)
195
+ msg = prompt_commit_message(&block)
196
+ output = ws.commit(msg)
197
+ block.call(:changes_commited, msg, output) if block
198
+ output
199
+ end
200
+
201
+ private
202
+ def mark_new_choice(arr)
203
+ res = []
204
+ arr.each do |a|
205
+ res << [a.to_s,a]
206
+ end
207
+ res
208
+ end
209
+
210
+ def mark_modified_choice(arr)
211
+ res = []
212
+ arr.each do |a|
213
+ res << [a.to_s,a]
214
+ end
215
+ res
216
+ end
217
+
218
+ def mark_del_choice(arr)
219
+ res = []
220
+ arr.each do |a|
221
+ res << [a.to_s,a]
222
+ end
223
+ res
224
+ end
225
+
226
+ def vcs_items_to_path_array(array)
227
+ array.map do |v|
228
+ v.path
229
+ end
230
+ end
231
+
232
+
233
+ end
234
+ end
@@ -0,0 +1,24 @@
1
+
2
+ require 'tty/prompt'
3
+
4
+ module GitCliPrompt
5
+ module CliPrompt
6
+
7
+ def method_missing(mtd, *args, &block)
8
+ if pmt.respond_to?(mtd)
9
+ pmt.send(mtd, *args, &block)
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ private
16
+ def pmt
17
+ if @pmt.nil?
18
+ @pmt = TTY::Prompt.new
19
+ end
20
+ @pmt
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+
2
+ require 'tlogger'
3
+
4
+ module GitCliPrompt
5
+ module Logger
6
+
7
+ def logger
8
+ if @logger.nil?
9
+ @logger = Tlogger.new
10
+ end
11
+ @logger
12
+ end
13
+
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitCliPrompt
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.2"
5
5
  end
data/lib/push.rb ADDED
@@ -0,0 +1,84 @@
1
+
2
+ module GitCliPrompt
3
+ module Push
4
+ include TR::CondUtils
5
+ include CliPrompt
6
+
7
+ class PushError < StandardError; end
8
+
9
+ def push(root, &block)
10
+
11
+ raise PushError, "Root is empty" if is_empty?(root)
12
+
13
+ begin
14
+
15
+ ws = Gvcs::Workspace.new(root)
16
+
17
+ raise PushError, "#{root} is not a workspace" if not ws.is_workspace?
18
+
19
+ conf = ws.remote_config
20
+ if is_empty?(conf)
21
+ res = pmt.yes?(" There is no remote repository configured for workspace at '#{File.expand_path(root)}'. Do you want to add one?")
22
+ raise UserAborted if not res
23
+ name, url = prompt_new_remote
24
+
25
+ ws.add_remote(name, url)
26
+
27
+ conf = ws.remote_config
28
+ end
29
+
30
+ branch = block.call(:push_to_branch) if block
31
+ branch = ws.current_branch if is_empty?(branch)
32
+
33
+ if conf.keys.length == 1
34
+ # direct push
35
+ name = conf.keys.first
36
+ url = conf.values.first["push"]
37
+ if confirm_push(name, url)
38
+ ws.push_changes_with_tags(name, branch)
39
+ block.call(:push_info, { name: name }) if block
40
+ else
41
+ raise UserAborted
42
+ end
43
+ else
44
+ raise UserChangedMind
45
+ end
46
+
47
+ rescue TTY::Reader::InputInterrupt
48
+ end
49
+ end
50
+
51
+ def confirm_push(name, url)
52
+
53
+ pmt.yes?(" Confirm push to repository '#{name}' [#{url}]?")
54
+
55
+ end
56
+
57
+
58
+ def prompt_new_remote
59
+
60
+ name = pmt.ask(" Please provide a name of this remote config :", required: true)
61
+ url = pmt.ask(" Please provide the URL:", required: true)
62
+
63
+ if confirm_input(name, url)
64
+ [name, url]
65
+ else
66
+ raise UserChangedMind
67
+ end
68
+
69
+ end
70
+
71
+ def confirm_input(name, url)
72
+
73
+ cont = []
74
+ cont << ""
75
+ cont << " Name : #{name}"
76
+ cont << " URL : #{url}"
77
+ cont << ""
78
+
79
+ pmt.yes?(" You've provided the following info. Proceed?\n#{cont.join("\r\n")}")
80
+
81
+ end
82
+
83
+ end
84
+ end
data/lib/tag.rb ADDED
@@ -0,0 +1,58 @@
1
+
2
+
3
+ module GitCliPrompt
4
+ module Tag
5
+ include TR::CondUtils
6
+ include CliPrompt
7
+ include TR::VerUtils
8
+
9
+ class TagError < StandardError; end
10
+
11
+ def tag(root, version, &block)
12
+
13
+ raise TagError, "Workspace root cannot be empty" if is_empty?(root)
14
+ raise TagError, "Version name cannot be empty" if is_empty?(version)
15
+
16
+ ws = Gvcs::Workspace.new(root)
17
+
18
+ if ws.is_workspace?
19
+ vers = possible_versions(currentVersion)
20
+
21
+ vers << "Custom"
22
+ vers << [
23
+ "Not feeling to tag now" \
24
+ ,"Maybe not now..." \
25
+ ,"Nah, forget it..." \
26
+ ].sample
27
+
28
+ sel = pmt.select("Please select one of the options below:") do |menu|
29
+ vers.each do |v|
30
+ menu.choice v
31
+ end
32
+ end
33
+
34
+ case sel
35
+ when "Custom"
36
+ sel = pmt.ask("Please provide custom version no:", required: true)
37
+ when vers[-1]
38
+ raise UserChangedMind
39
+ end
40
+
41
+ defTagMsg = block.call(:default_tag_message) if block
42
+ if is_empty?(defTagMsg)
43
+ defTagMsg = "Automated tagging of source code of release version #{sel}"
44
+ end
45
+
46
+ msg = pmt.ask("Message for this tag : ", default: defTagMsg)
47
+
48
+ ws.create_tag(sel, msg)
49
+
50
+ else
51
+ raise TagError, "Given path '#{root}' is not a workspace"
52
+ end
53
+
54
+
55
+ end
56
+
57
+ end
58
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_cli_prompt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Liaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-22 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tlogger
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: devops_helper
56
+ name: devops_assist
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -73,15 +73,22 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".release_history.yml"
76
77
  - ".rspec"
77
78
  - Gemfile
79
+ - Gemfile.lock
78
80
  - README.md
79
81
  - Rakefile
80
82
  - bin/console
81
83
  - bin/setup
82
84
  - git_cli_prompt.gemspec
85
+ - lib/commit.rb
83
86
  - lib/git_cli_prompt.rb
87
+ - lib/git_cli_prompt/cli_prompt.rb
88
+ - lib/git_cli_prompt/logger.rb
84
89
  - lib/git_cli_prompt/version.rb
90
+ - lib/push.rb
91
+ - lib/tag.rb
85
92
  homepage: ''
86
93
  licenses: []
87
94
  metadata: {}