git_cli_prompt 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e0baf03b1eff4fcce89d777a0701742d9a87d8ca42a9e2b420b78fcafda4d8c
4
- data.tar.gz: e40cf5b3951335cc9472bac286323d784605711bdbe9e96395892dabc7f384f7
3
+ metadata.gz: 80add3df91c6cc3b90064e63b37a50997b2cea41773cb7f638414de890e5a0fa
4
+ data.tar.gz: 0223e5f621299a44dfd3e16a1f7764b008ab5cd174fdd5151fa6002fd20ade2b
5
5
  SHA512:
6
- metadata.gz: 6b673ef6d30fa03773bf530162a9cc383c4035858126da8aa3c778357b120e252a1cea1e17ef8b638e4603cffc27326e3ad55b33d625b0cabbb2902fb6f692c2
7
- data.tar.gz: bd5e2adb046a397c84aa20d8dc287d679d6411c392f7b4e1524c7981d14ee97d00dba825df84584efb0f6f39e2c8503d8e2ed26390695416935a299a0f78541c
6
+ metadata.gz: 3d534ae9e6274ee88dd7bfdd7f1b9ce165505a0cc7bf6952adbc834a92572610b22898dfb2ca5cf1cf0849e4c058cee64b28eea28aa870ecf699b029ee97995e
7
+ data.tar.gz: 1c18a1ef138052a4c8faa913b9110a076c0be6c933c0e9e9d694ebafeebec2c94d01331a091ea833712928a701d7f7f42c71263f7dce5d2bbe757c1bb7d23512
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_cli_prompt (0.1.0)
5
+ tlogger
6
+ toolrack
7
+ tty-prompt
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ base58 (0.2.3)
13
+ devops_helper (0.5.0)
14
+ git_cli
15
+ gvcs
16
+ tlogger
17
+ toolrack
18
+ tty-prompt (= 0.22.0)
19
+ diff-lcs (1.4.4)
20
+ git_cli (0.9.0)
21
+ gvcs
22
+ ptools (~> 1.4.0)
23
+ tlogger
24
+ toolrack
25
+ gvcs (0.1.0)
26
+ pastel (0.8.0)
27
+ tty-color (~> 0.5)
28
+ ptools (1.4.2)
29
+ rake (13.0.6)
30
+ rspec (3.10.0)
31
+ rspec-core (~> 3.10.0)
32
+ rspec-expectations (~> 3.10.0)
33
+ rspec-mocks (~> 3.10.0)
34
+ rspec-core (3.10.1)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-expectations (3.10.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-mocks (3.10.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-support (3.10.2)
43
+ tlogger (0.26.1)
44
+ toolrack (0.16.0)
45
+ base58
46
+ tlogger
47
+ tty-color (0.6.0)
48
+ tty-cursor (0.7.1)
49
+ tty-prompt (0.22.0)
50
+ pastel (~> 0.8)
51
+ tty-reader (~> 0.8)
52
+ tty-reader (0.9.0)
53
+ tty-cursor (~> 0.7)
54
+ tty-screen (~> 0.8)
55
+ wisper (~> 2.0)
56
+ tty-screen (0.8.1)
57
+ wisper (2.0.1)
58
+
59
+ PLATFORMS
60
+ x86_64-linux
61
+
62
+ DEPENDENCIES
63
+ devops_helper
64
+ git_cli_prompt!
65
+ rake (~> 13.0)
66
+ rspec (~> 3.0)
67
+
68
+ BUNDLED WITH
69
+ 2.2.28
data/lib/commit.rb ADDED
@@ -0,0 +1,231 @@
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
+ if not_empty?(stDir) or not_empty?(stFiles)
32
+ say " Item(s) already staged for commit: \n"
33
+ stDir.each do |md|
34
+ say " #{md.path}"
35
+ end
36
+ stFiles.each do |md|
37
+ say " #{md.path}"
38
+ end
39
+ end
40
+
41
+ if pending
42
+
43
+ say "\n\n Items could be add to version control:\n"
44
+ cnt = 1
45
+ [modDir, modFiles, newDir, newFiles, delDir, delFiles].each do |cont|
46
+ cont.each do |md|
47
+ say " #{'%2s' % cnt}. #{md.to_s}\n"
48
+ cnt += 1
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ puts
55
+
56
+ if not pending
57
+ pmt.say("\n Workspace is clean. No changes or unstage files or directory is found.\n", color: :green)
58
+ "Workspace is clean. No changes or unstage files or directory is found"
59
+
60
+ else
61
+
62
+ ops = pmt.select(" Please select desired operation:") do |menu|
63
+ menu.default 1
64
+
65
+ menu.choice " Add", :add if pending
66
+ if not_empty?(stDir) or not_empty?(stFiles)
67
+ menu.choice " Remove file from staged", :remove_staged
68
+ menu.choice " Commit staged", :commit
69
+ end
70
+ menu.choice " Ignore changes", :ignore
71
+ menu.choice " Quit", :quit
72
+ end
73
+
74
+ case ops
75
+ when :add
76
+ choices = []
77
+ choices += mark_modified_choice(modDir)
78
+ choices += mark_modified_choice(modFiles)
79
+ choices += mark_new_choice(newDir)
80
+ choices += mark_new_choice(newFiles)
81
+ choices += mark_del_choice(delDir)
82
+ choices += mark_del_choice(delFiles)
83
+
84
+ prompt_add_selection(ws, choices, &block)
85
+ commit_staged(ws, &block)
86
+
87
+ when :ignore
88
+ pmt.ok "\n Changes are ignored for this release", color: :yellow
89
+
90
+ when :quit
91
+ raise UserChangedMind
92
+
93
+ when :remove_staged
94
+
95
+ choices = []
96
+ choices += stDir.map { |v| [v.path,v] }
97
+ choices += stFiles.map { |v| [v.path,v] }
98
+
99
+ sel = prompt_remove_staging(choices)
100
+ ws.remove_from_staging(sel)
101
+
102
+ when :commit
103
+
104
+ commit_staged(ws, &block)
105
+
106
+ end
107
+ end
108
+
109
+
110
+ rescue TTY::Reader::InputInterrupt
111
+ ok "\n\n Aborted"
112
+
113
+ #rescue UserChangedMind
114
+ # ok "\n Noted. Please retry the process again\n"
115
+
116
+ #rescue UserSelectNone
117
+ # ok "\n Nothing is selected. Process halted\n"
118
+
119
+ #rescue Exception => ex
120
+ # error(ex.message)
121
+ # logger.error ex.message
122
+ # logger.error ex.backtrace.join('\n')
123
+
124
+ end
125
+ end
126
+
127
+ def prompt_remove_staging(choices)
128
+
129
+ sel = pmt.select(" Please select which item(s) to remove from staging:") do |menu|
130
+
131
+ choices.each do |c|
132
+ menu.choice c[0], c[1]
133
+ end
134
+
135
+ end
136
+
137
+ raise UserSelectNone, " No selection of staged item(s) were made" if is_empty?(sel)
138
+ if confirm_selection(sel)
139
+ sel
140
+ else
141
+ raise UserChangedMind, " User aborted"
142
+ end
143
+
144
+ end
145
+
146
+ def prompt_add_selection(ws, choices, &block)
147
+
148
+ sel = multi_select(" Please select which items to add to this commit session:") do |menu|
149
+ choices.each do |c|
150
+ menu.choice c[0], c[1]
151
+ end
152
+ end
153
+
154
+ raise UserSelectNone, " No selection of unversioned item(s) was made" if is_empty?(sel)
155
+ if confirm_selection(sel)
156
+ psel = vcs_items_to_path_array(sel)
157
+ ws.add_to_staging(psel)
158
+ else
159
+ raise UserChangedMind, " User aborted"
160
+ end
161
+
162
+ end
163
+
164
+ def confirm_selection(sel)
165
+
166
+ sel = [sel] if not sel.is_a?(Array)
167
+ cs = []
168
+ cnt = 1
169
+ sel.each do |s|
170
+ cs << "#{"%2s" % cnt.to_s}. #{s}"
171
+ cnt += 1
172
+ end
173
+
174
+ yes?(" You've selected the following item(s). Proceed?\n#{cs.join("\n")}\n")
175
+
176
+ end
177
+
178
+ def prompt_commit_message(&block)
179
+
180
+ if block
181
+ defMsg = block.call(:default_commit_message)
182
+ end
183
+
184
+ msg = pmt.ask(" Commit Message :", required: true) do |m|
185
+ m.default = defMsg if not_empty?(defMsg)
186
+ end
187
+
188
+ msg
189
+ end
190
+
191
+ def commit_staged(ws, &block)
192
+ msg = prompt_commit_message(&block)
193
+ output = ws.commit(msg)
194
+ block.call(:changes_commited, msg, output) if block
195
+ output
196
+ end
197
+
198
+ private
199
+ def mark_new_choice(arr)
200
+ res = []
201
+ arr.each do |a|
202
+ res << [a.to_s,a]
203
+ end
204
+ res
205
+ end
206
+
207
+ def mark_modified_choice(arr)
208
+ res = []
209
+ arr.each do |a|
210
+ res << [a.to_s,a]
211
+ end
212
+ res
213
+ end
214
+
215
+ def mark_del_choice(arr)
216
+ res = []
217
+ arr.each do |a|
218
+ res << [a.to_s,a]
219
+ end
220
+ res
221
+ end
222
+
223
+ def vcs_items_to_path_array(array)
224
+ array.map do |v|
225
+ v.path
226
+ end
227
+ end
228
+
229
+
230
+ end
231
+ 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.0"
5
5
  end
data/lib/push.rb ADDED
@@ -0,0 +1,82 @@
1
+
2
+ module GitCliPrompt
3
+ module Push
4
+ include TR::CondUtils
5
+ include CliPrompt
6
+
7
+ def push(root, &block)
8
+
9
+ raise PushError, "Root is empty" if is_empty?(root)
10
+
11
+ begin
12
+
13
+ ws = Gvcs::Workspace.new(root)
14
+
15
+ raise PushError, "#{root} is not a workspace" if not ws.is_workspace?
16
+
17
+ conf = ws.remote_config
18
+ if is_empty?(conf)
19
+ res = pmt.yes?(" There is no remote repository configured for workspace at '#{File.expand_path(root)}'. Do you want to add one?")
20
+ raise UserAborted if not res
21
+ name, url = prompt_new_remote
22
+
23
+ ws.add_remote(name, url)
24
+
25
+ conf = ws.remote_config
26
+ end
27
+
28
+ branch = block.call(:push_to_branch) if block
29
+ branch = ws.current_branch if is_empty?(branch)
30
+
31
+ if conf.keys.length == 1
32
+ # direct push
33
+ name = conf.keys.first
34
+ url = conf.values.first["push"]
35
+ if confirm_push(name, url)
36
+ ws.push_changes_with_tags(name, branch)
37
+ block.call(:push_info, { name: name }) if block
38
+ else
39
+ raise UserAborted
40
+ end
41
+ else
42
+ raise UserChangedMind
43
+ end
44
+
45
+ rescue TTY::Reader::InputInterrupt
46
+ end
47
+ end
48
+
49
+ def confirm_push(name, url)
50
+
51
+ pmt.yes?(" Confirm push to repository '#{name}' [#{url}]?")
52
+
53
+ end
54
+
55
+
56
+ def prompt_new_remote
57
+
58
+ name = pmt.ask(" Please provide a name of this remote config :", required: true)
59
+ url = pmt.ask(" Please provide the URL:", required: true)
60
+
61
+ if confirm_input(name, url)
62
+ [name, url]
63
+ else
64
+ raise UserChangedMind
65
+ end
66
+
67
+ end
68
+
69
+ def confirm_input(name, url)
70
+
71
+ cont = []
72
+ cont << ""
73
+ cont << " Name : #{name}"
74
+ cont << " URL : #{url}"
75
+ cont << ""
76
+
77
+ pmt.yes?(" You've provided the following info. Proceed?\n#{cont.join("\r\n")}")
78
+
79
+ end
80
+
81
+ end
82
+ 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,7 +1,7 @@
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Liaw
@@ -75,13 +75,19 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".rspec"
77
77
  - Gemfile
78
+ - Gemfile.lock
78
79
  - README.md
79
80
  - Rakefile
80
81
  - bin/console
81
82
  - bin/setup
82
83
  - git_cli_prompt.gemspec
84
+ - lib/commit.rb
83
85
  - lib/git_cli_prompt.rb
86
+ - lib/git_cli_prompt/cli_prompt.rb
87
+ - lib/git_cli_prompt/logger.rb
84
88
  - lib/git_cli_prompt/version.rb
89
+ - lib/push.rb
90
+ - lib/tag.rb
85
91
  homepage: ''
86
92
  licenses: []
87
93
  metadata: {}