wielder_of_anor 0.4.4 → 1.0.0

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
  SHA1:
3
- metadata.gz: bcf8bceb416f575172e60e3cffa7f74386ceac33
4
- data.tar.gz: 637d833680e3f79ff037d06acc9b0693b907fce4
3
+ metadata.gz: 1ac81beb241c3fc3d035d04c618420fad99b9dcc
4
+ data.tar.gz: '0664259f3f64ce317b60d4556874cc080e93afe4'
5
5
  SHA512:
6
- metadata.gz: 7bb0c2b2d94f950489e424d56d25936717a7433476c5585472840b8ce111fcf4d4ad430d82dec9dbdbbc79c59483a7379a2ee70329810d2b88acaa6e72c77c13
7
- data.tar.gz: 3c5d8b45900b83d920cfac4ccdb587a25976559df8d3297b87f6bc1826b8e2fd17a9d5e3cd5ff2fbe72c40c316cf8e8f59c3ec95cbde7f4564d279763bf8248d
6
+ metadata.gz: d9f991d0e174d5681b298a6a46f566c1273b898d02fcf39dfccaec44ec30cbd11a199716e06a3ceb34b8efe290816d3098c6658ae24c7f283af712ab20bdaed9
7
+ data.tar.gz: fe9dcf70c5f8f91795ff9125bafdd0c2bfd48a180581ee5a2f5fa24ee5221482a43f3d67f368266972a4b3597774f0c1db369847189e41ffbab90a8f11f8c32f
@@ -31,9 +31,8 @@ module WielderOfAnor
31
31
 
32
32
  def prepare(commit_message, force_commit)
33
33
  # If there's just one, it's the current version. Don't run if the current config is present.
34
- restore_settings('wielder_of_anor', VERSION) if
35
- Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*").length > 1 &&
36
- !(File.exists?("#{@app_directory}/lib/config.yaml"))
34
+ restore_woa_settings if Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*").length > 1 &&
35
+ !(File.exists?("#{@app_directory}/lib/config.yaml"))
37
36
  first_run unless File.exists?("#{@app_directory}/lib/config.yaml")
38
37
 
39
38
  config = YAML.load_file("#{@app_directory}/lib/config.yaml")
@@ -42,6 +41,9 @@ module WielderOfAnor
42
41
  @current_directory = Dir.pwd
43
42
  @files_changed_file_location = config['files_changed_file_location']
44
43
  @commit_for_user = config['commit_for_user']
44
+ @check_branch = config['check_branch']
45
+ @branches_to_check = config['branches_to_check']
46
+ @current_branch_file_location = "#{@app_directory}/lib/current_branch"
45
47
 
46
48
  # Don't want to use a previous version.
47
49
  File.delete(@files_changed_file_location) if File.exists?(@files_changed_file_location)
@@ -109,11 +111,15 @@ module WielderOfAnor
109
111
 
110
112
  commit_for_user = set_commit_for_user
111
113
 
114
+ check_branch = set_check_branch
115
+
116
+ branches_to_check = set_branches_to_check if check_branch == 'yes' || check_branch == 'y'
117
+
112
118
  single_space
113
119
 
114
120
  forbidden_words = set_forbidden_words
115
121
 
116
- set_configs(files_changed_file_location, forbidden_words, commit_for_user)
122
+ set_configs(files_changed_file_location, forbidden_words, commit_for_user, check_branch, branches_to_check)
117
123
  end
118
124
 
119
125
  def set_commit_for_user
@@ -129,10 +135,57 @@ module WielderOfAnor
129
135
  commit_for_user = STDIN.gets.strip!.downcase
130
136
  end
131
137
 
138
+ single_space
139
+
132
140
  commit_for_user
133
141
  end
134
142
 
135
- def set_configs(files_changed_file_location, forbidden_words, commit_for_user)
143
+ def set_check_branch
144
+ lines_pretty_print 'Would you like Wielder of Anor to stop you from committing to a certain branch or branches?'
145
+ lines_pretty_print Rainbow('(Type \'yes\' or \'no\'. Just hitting enter defaults to no.)').yellow
146
+
147
+ check_branch = STDIN.gets.strip!.downcase
148
+ check_branch = 'no' if check_branch == ''
149
+
150
+ until check_branch == 'yes' || check_branch =='y' || check_branch == 'no' || check_branch == 'n' do
151
+ lines_pretty_print Rainbow('Please type either \'yes\' or \'no\'.').yellow
152
+ check_branch = STDIN.gets.strip!.downcase
153
+ end
154
+
155
+ single_space
156
+
157
+ check_branch
158
+ end
159
+
160
+ def set_branches_to_check
161
+ branches_to_check = []
162
+
163
+ done = false
164
+
165
+ lines_pretty_print 'Sounds good! What branches should I block you from committing to?'
166
+ single_space
167
+
168
+ until done do
169
+ lines_pretty_print Rainbow('Enter a forbidden branch and hit enter. If you are done entering forbidden '\
170
+ 'branches, just hit enter instead.').yellow unless branches_to_check.count > 0
171
+
172
+ lines_pretty_print Rainbow('Added! Enter another forbidden branch and hit enter. If you are done '\
173
+ 'entering forbidden branches, just hit enter instead.').yellow unless branches_to_check.count == 0
174
+ branch = STDIN.gets.strip!
175
+
176
+ single_space
177
+
178
+ if branch == ''
179
+ done = true
180
+ else
181
+ branches_to_check << branch
182
+ end
183
+ end
184
+
185
+ branches_to_check
186
+ end
187
+
188
+ def set_configs(files_changed_file_location, forbidden_words, commit_for_user, check_branch, branches_to_check)
136
189
  config = {}
137
190
  config['files_changed_file_location'] = files_changed_file_location
138
191
 
@@ -142,6 +195,14 @@ module WielderOfAnor
142
195
  config['commit_for_user'] = false
143
196
  end
144
197
 
198
+ if check_branch == 'yes' || check_branch == 'y'
199
+ config['check_branch'] = true
200
+ config['branches_to_check'] = branches_to_check
201
+ else
202
+ config['check_branch'] = false
203
+ config['branches_to_check'] = []
204
+ end
205
+
145
206
  config['forbidden_words'] = forbidden_words
146
207
 
147
208
  file = File.open("#{@app_directory}/lib/config.yaml", 'w')
@@ -159,7 +220,7 @@ module WielderOfAnor
159
220
 
160
221
  done = false
161
222
 
162
- lines_pretty_print 'Great! Now that we\'re done with the files, let\'s add your forbidden '\
223
+ lines_pretty_print 'Great! Now that we\'re done with that, let\'s add your forbidden '\
163
224
  'words from here!'
164
225
  single_space
165
226
 
@@ -300,6 +361,19 @@ module WielderOfAnor
300
361
  end
301
362
 
302
363
  def commit
364
+ if @check_branch
365
+ bash(@current_directory, "git rev-parse --abbrev-ref HEAD > #{@current_branch_file_location}")
366
+ current_branch = File.open(@current_branch_file_location, "r").read.strip!
367
+
368
+ if @branches_to_check.include?(current_branch)
369
+ lines_pretty_print Rainbow('I\'m sorry, Dave, but I can\'t allow you to do that.').red
370
+ lines_pretty_print Rainbow('You have tried committing to a forbidden branch. Danger, Will Robinson! Danger! '\
371
+ 'Aborting!').red
372
+
373
+ abort
374
+ end
375
+ end
376
+
303
377
  if @force_commit
304
378
  lines_pretty_print 'Skipped checking for forbidden words. Ready to commit now?'
305
379
  lines_pretty_print Rainbow('**WARNING: YOU ARE FORCING THE COMMIT WITHOUT CHECKING FOR FORBIDDEN WORDS.**').red
@@ -327,18 +401,45 @@ module WielderOfAnor
327
401
  @app_directory = File.expand_path(File.dirname(__FILE__)).chomp('/lib')
328
402
  end
329
403
 
330
- def lines_pretty_print(string)
331
- lines = string.scan(/\S.{0,70}\S(?=\s|$)|\S+/)
404
+ def restore_woa_settings
405
+ lines_pretty_print 'I see that you have a previous wielder_of_anor installation on this machine.'
406
+ lines_pretty_print Rainbow('Would you like to restore its settings?').yellow
332
407
 
333
- lines.each { |line| puts line }
334
- end
408
+ answered = false
335
409
 
336
- def single_space
337
- puts ''
338
- end
410
+ until answered
411
+ answer = STDIN.gets.strip!
412
+
413
+ single_space
414
+
415
+ if answer == 'yes' || answer == 'y' || answer == 'no' || answer == 'n'
416
+ answered = true
417
+ else
418
+ lines_pretty_print Rainbow('Please input either \'yes\' or \'no\'.').yellow
419
+ end
420
+ end
421
+
422
+ return if answer == 'no' || answer == 'n'
423
+
424
+ lines_pretty_print 'One moment, please.'
339
425
 
340
- def double_space
341
- puts "\n\n"
426
+ single_space
427
+
428
+ all_gems = Dir.glob("#{@app_directory.chomp("/wielder_of_anor-#{VERSION}")}/wielder_of_anor*")
429
+
430
+ # glob orders things in the array alphabetically, so the second-to-last one in the array is the
431
+ # most recent version that is not the current version.
432
+ previous_config_file = "#{all_gems[-2]}/lib/config.yaml"
433
+ config = YAML.load_file(previous_config_file)
434
+ config['files_changed_file_location'] = "#{@app_directory}/lib/files_changed"
435
+ new_config_file = File.open("#{@app_directory}/lib/config.yaml", 'w')
436
+
437
+ YAML.dump(config, new_config_file)
438
+ new_config_file.close
439
+
440
+ lines_pretty_print 'Done! Please run me again when you\'re ready.'
441
+
442
+ abort
342
443
  end
343
444
  end
344
445
  end
@@ -1,3 +1,3 @@
1
1
  module WielderOfAnorVersion
2
- VERSION = "0.4.4"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wielder_of_anor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sellek