wielder_of_anor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +115 -0
- data/Rakefile.rb +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/wielder_of_anor +15 -0
- data/lib/wielder_of_anor.rb +358 -0
- data/lib/wielder_of_anor/version.rb +3 -0
- data/wielder_of_anor.gemspec +27 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad37c3a3da1954f5170dfaf371fc551fa3ca4a3e
|
4
|
+
data.tar.gz: eb087cbb5f567c15554b3f5364cd034cf1ebf6e3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d2db50100946ee5621e1e8c7f64fdedb9fe193b4e338fda958dc16b0d78043218bfd65b53a7d40b382c83ec4a47959040ef7320f6ec7650f1ea78061f61815f6
|
7
|
+
data.tar.gz: bbee44b64ab52325b5a6a6c2aafc4584b1d602968934a380af34f6cf53fb70c7df59d6ded370b10cd0a70cee2691fcc5d0b271a0b40877eee4fa7162e3621988
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 iamsellek
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# Wielder of Anor
|
2
|
+
Checks a user's staged files for "forbidden" words (as determined by the user)
|
3
|
+
and, if any are found, alerts the user to the locations of said words.
|
4
|
+
|
5
|
+
## Longer Description
|
6
|
+
I am absent-minded. Very absent-minded. Absent-minded to the point that I'll
|
7
|
+
throw some "puts" or "console.log" commands into my code for debugging purposes
|
8
|
+
only to completely forget about them and then happily push all my code to
|
9
|
+
master branch without a care in the world. This...is not okay. Yet despite my
|
10
|
+
constant reminders to my brain that it most certainly is not okay, it keeps
|
11
|
+
quite happily forgetting everything about everything when it's time to commit
|
12
|
+
my code. And since I (apparently) can't magically fix the way my brain works, I
|
13
|
+
figured I'd make my computer double-check me since, you know, that is the entire
|
14
|
+
reason we invented computers to begin with. Enter Wielder of Anor.
|
15
|
+
|
16
|
+
Wielder of Anor is a quick and easy way to ensure that you aren't pushing your
|
17
|
+
code to production (or anywhere else it shouldn't be) with "forbidden words" you
|
18
|
+
don't want there. You yourself determine which words are forbidden, so this app
|
19
|
+
should be helpful to anyone wanting to prevent certain text from making it past
|
20
|
+
your dev environment. Maybe you're like me and you can never remember to pull
|
21
|
+
your debugging commands out of your code before committing. Maybe you're a code
|
22
|
+
master and commit swaths of code at a time, laughing at the mere mortals around
|
23
|
+
you who commit smaller chunks of work several times a day, and you can't be
|
24
|
+
bothered to check through your tens of thousands of lines of code to ensure you
|
25
|
+
didn't leave some debugging command in there somewhere. Or maybe your code gets
|
26
|
+
more and more filled with swear words the more frustrating a problem gets and
|
27
|
+
you just can't let one of those slip to production again because seriously it'd
|
28
|
+
be like the third or fourth time and you like working here and can't imagine
|
29
|
+
staying here if you slip up another time or two and...
|
30
|
+
|
31
|
+
Ahem. Sorry.
|
32
|
+
|
33
|
+
So. If you need to prevent anything in your code from making it past your dev
|
34
|
+
environment and need a reliable way to do this, use Wielder of Anor.
|
35
|
+
|
36
|
+
## Setup
|
37
|
+
Setup is simple! Just download Wielder of Anor to the location of your choosing
|
38
|
+
and then run it!
|
39
|
+
|
40
|
+
## Use/What It Does
|
41
|
+
To use Wielder of Anor, just run it *from within the code directory you want to
|
42
|
+
run the forbidden words checks against* (this is important). A note: it does not
|
43
|
+
*and should not* actually be *in* your code directory. From your code directory,
|
44
|
+
just type `ruby full_path_to_wielder_of_anon.rb` followed by the arguments. I
|
45
|
+
have personally made an alias for doing this. Feel free to do that or type the
|
46
|
+
full path each time as you desire. You can pass in a couple of arguments here.
|
47
|
+
|
48
|
+
The first argument can be:
|
49
|
+
|
50
|
+
* Your eventual commit message (in quotes), if you've chosen to allow Wielder
|
51
|
+
of Anor itself to run your commits for you. If you've chosen to *not* allow it
|
52
|
+
to run your commits for you, this argument will be ignored.
|
53
|
+
* 'help' - This will simply print out shorter versions of the options you are
|
54
|
+
currently reading.
|
55
|
+
* 'config' - This will re-run the configuration process. IF YOU SET ANY OF YOUR
|
56
|
+
FILE LOCATIONS TO POINT TO PREVIOUSLY EXISTING FILES, THOSE FILES *WILL* BE
|
57
|
+
OVERWRITTEN.
|
58
|
+
|
59
|
+
There is currently only one option for the second argument:
|
60
|
+
|
61
|
+
* The second argument can only be '1' and will be ignored unless there is a
|
62
|
+
commit message as the first argument. If this argument is passed, Wielder of
|
63
|
+
Anor will skip checking for any forbidden words whatsoever and jump straight
|
64
|
+
to the commit portion of the app. This is mainly here so that you can easily
|
65
|
+
force a commit after Wielder of Anor tells you of some forbidden words that
|
66
|
+
you've decided to allow for whatever reason. For instance, say 'puts' is one
|
67
|
+
of your forbidden words and there's a commented-out puts statement in your
|
68
|
+
code that you didn't put there and that, as such, you don't want to delete.
|
69
|
+
It's the only forbidden word showing up, so the rest of your code is clean.
|
70
|
+
So, instead of now having to type out a full git commit command, you can now
|
71
|
+
just hit your up arrow, hit the spacebar, type a '1' and hit enter.
|
72
|
+
|
73
|
+
Once run, Wielder of Anor will run a bash command that'll export the result of a
|
74
|
+
`git diff HEAD --staged --name-only` (so all files that you have 'git add'ed
|
75
|
+
since git HEAD) to a file. It'll then check every line in every one of those
|
76
|
+
files for any of your forbidden words and print out the locations of any and
|
77
|
+
every one it finds.
|
78
|
+
|
79
|
+
If it found none (or if you've skipped the search and are forcing a commit), you
|
80
|
+
are good to go and can tell the app to then run the git commit command, if
|
81
|
+
you've opted to allow it to do so. At this point, Wielder of Anor will run a
|
82
|
+
`git commit -m ` followed by your commit message (your first argument when
|
83
|
+
running the app). Once it prints out "COMMITTED.", execution will end. Don't
|
84
|
+
forget to run your git push!
|
85
|
+
|
86
|
+
## Wielder of Anor? Wut.
|
87
|
+
You know, the thing Gandalf calls himself to the Balrog as he's all "YOU SHALL
|
88
|
+
NOT PASS!" over and over? When he's, you know, preventing the Balrog from
|
89
|
+
getting past him? He...he prevents a *forbidden* thing from...
|
90
|
+
|
91
|
+
A gatekeeper. This app is a gatekeeper. Gandalf was a Gatekeeper that one
|
92
|
+
time. It's artistic. Or something.
|
93
|
+
|
94
|
+
## License
|
95
|
+
The MIT License (MIT)
|
96
|
+
|
97
|
+
Copyright (c) 2016 Chris Sellek
|
98
|
+
|
99
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
100
|
+
of this software and associated documentation files (the "Software"), to deal
|
101
|
+
in the Software without restriction, including without limitation the rights
|
102
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
103
|
+
copies of the Software, and to permit persons to whom the Software is
|
104
|
+
furnished to do so, subject to the following conditions:
|
105
|
+
|
106
|
+
The above copyright notice and this permission notice shall be included in all
|
107
|
+
copies or substantial portions of the Software.
|
108
|
+
|
109
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
110
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
111
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
112
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
113
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
114
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
115
|
+
SOFTWARE.
|
data/Rakefile.rb
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wielder_of_anor"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/bin/wielder_of_anor
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'wielder_of_anor'
|
4
|
+
|
5
|
+
woa = WielderOfAnor::WielderOfAnor.new
|
6
|
+
|
7
|
+
woa.help if ARGV[0] == 'help'
|
8
|
+
|
9
|
+
woa.first_run if ARGV[0] == 'config'
|
10
|
+
|
11
|
+
woa.output_forbidden_words if ARGV[0] == 'words'
|
12
|
+
|
13
|
+
woa.prepare(ARGV[0], ARGV[1])
|
14
|
+
|
15
|
+
woa.wielder_of_anor
|
@@ -0,0 +1,358 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require 'yaml'
|
3
|
+
require 'rainbow'
|
4
|
+
|
5
|
+
module WielderOfAnor
|
6
|
+
class WielderOfAnor
|
7
|
+
##############################################################################
|
8
|
+
##############################################################################
|
9
|
+
## ##
|
10
|
+
## commit_message is the git commit message the user would like to send ##
|
11
|
+
## once we have verified that there are no forbidden words present in their ##
|
12
|
+
## code. ##
|
13
|
+
## ##
|
14
|
+
## force_commit is either '1' or nil. If it's 1, we will commit later even ##
|
15
|
+
## if there are forbidden words present. ##
|
16
|
+
## ##
|
17
|
+
##############################################################################
|
18
|
+
##############################################################################
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
set_app_directory
|
22
|
+
|
23
|
+
@forbidden_words = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def prepare(commit_message, force_commit)
|
27
|
+
set_app_directory
|
28
|
+
|
29
|
+
first_run unless File.exists?("#{@app_directory}/config/config.yaml")
|
30
|
+
|
31
|
+
config = YAML.load_file("#{@app_directory}/config/config.yaml")
|
32
|
+
@commit_message = commit_message
|
33
|
+
@force_commit = force_commit
|
34
|
+
@current_directory = Dir.pwd
|
35
|
+
@files_changed_file_location = config['files_changed_file_location']
|
36
|
+
@commit_for_user = config['commit_for_user']
|
37
|
+
|
38
|
+
# Don't want to use a previous version.
|
39
|
+
File.delete(@files_changed_file_location) if File.exists?(@files_changed_file_location)
|
40
|
+
|
41
|
+
git_diff
|
42
|
+
|
43
|
+
@files_changed_file = File.open(@files_changed_file_location, "r")
|
44
|
+
|
45
|
+
get_forbidden_words(config['forbidden_words_file_location'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def help
|
49
|
+
lines_pretty_print 'Wielder of Anor can accept up to two parameters on run. The first parameter can be:'
|
50
|
+
|
51
|
+
single_space
|
52
|
+
|
53
|
+
lines_pretty_print '- Your eventual commit message (in quotes). This is ignored if you have not allowed '\
|
54
|
+
'Wielder of Anor to commit for you.'
|
55
|
+
lines_pretty_print '- help - You should already know what this does :).'
|
56
|
+
lines_pretty_print '- config - Re-runs the initial set up.'
|
57
|
+
|
58
|
+
single_space
|
59
|
+
|
60
|
+
lines_pretty_print 'And your second parameter can only be \'1\', and it\'ll be ignored unless all of the '\
|
61
|
+
'following is true:'
|
62
|
+
|
63
|
+
single_space
|
64
|
+
|
65
|
+
lines_pretty_print '- You have allowed Wielder of Anor to run commits for you.'
|
66
|
+
lines_pretty_print '- Your first parameter is your commit message.'
|
67
|
+
|
68
|
+
abort
|
69
|
+
end
|
70
|
+
|
71
|
+
def output_forbidden_words
|
72
|
+
set_app_directory
|
73
|
+
config = YAML.load_file("#{@app_directory}/config/config.yaml")
|
74
|
+
|
75
|
+
unless config
|
76
|
+
lines_pretty_print Rainbow('You have yet to set your forbidden words! Please run the app with the parameter '\
|
77
|
+
'\'config\' to set up your configurations and forbidden words.').red
|
78
|
+
|
79
|
+
abort
|
80
|
+
end
|
81
|
+
|
82
|
+
get_forbidden_words(config['forbidden_words_file_location'])
|
83
|
+
|
84
|
+
lines_pretty_print Rainbow('Your forbidden words are:').yellow
|
85
|
+
|
86
|
+
single_space
|
87
|
+
|
88
|
+
@forbidden_words.each do |word|
|
89
|
+
lines_pretty_print Rainbow(word).yellow
|
90
|
+
end
|
91
|
+
|
92
|
+
single_space
|
93
|
+
|
94
|
+
abort
|
95
|
+
end
|
96
|
+
|
97
|
+
def first_run
|
98
|
+
lines_pretty_print 'Thanks for downloading Wielder of Anor! Let\'s run through the '\
|
99
|
+
'initial setup!'
|
100
|
+
lines_pretty_print Rainbow('**Please ensure your file locations are correct. Wielder of Anor '\
|
101
|
+
'does not currently check your input for validity.**').red
|
102
|
+
|
103
|
+
STDIN.gets
|
104
|
+
|
105
|
+
files_changed_file_location = set_files_changed_file_location
|
106
|
+
|
107
|
+
forbidden_words_file_location = set_forbidden_words_file_location
|
108
|
+
|
109
|
+
commit_for_user = set_commit_for_user
|
110
|
+
|
111
|
+
single_space
|
112
|
+
|
113
|
+
set_configs(files_changed_file_location, forbidden_words_file_location, commit_for_user)
|
114
|
+
|
115
|
+
set_forbidden_words(forbidden_words_file_location)
|
116
|
+
end
|
117
|
+
|
118
|
+
def set_files_changed_file_location
|
119
|
+
set_app_directory
|
120
|
+
|
121
|
+
lines_pretty_print 'Whenever you run Wielder of Anor, it will first run a git diff and '\
|
122
|
+
'export the results to a file (so that it\'s only checking the files '\
|
123
|
+
'you have actually changed and not your entire code base!). Where '\
|
124
|
+
'would you like that file to be located?'
|
125
|
+
lines_pretty_print Rainbow('(Just hit enter to accept the default, which is'\
|
126
|
+
" #{@app_directory}/docs/files_changed.)").yellow
|
127
|
+
files_changed_file_location = STDIN.gets.strip!
|
128
|
+
files_changed_file_location = "#{@app_directory}/docs/files_changed" if files_changed_file_location == ''
|
129
|
+
|
130
|
+
files_changed_file_location
|
131
|
+
end
|
132
|
+
|
133
|
+
def set_forbidden_words_file_location
|
134
|
+
lines_pretty_print 'Your \'forbidden words\' are stored in a file. Where would like that'\
|
135
|
+
' file to be located?'
|
136
|
+
lines_pretty_print Rainbow('(Just hit enter to accept the default, which is'\
|
137
|
+
" #{@app_directory}/docs/forbidden_words.)").yellow
|
138
|
+
forbidden_words_file_location = STDIN.gets.strip!
|
139
|
+
forbidden_words_file_location = "#{@app_directory}/docs/forbidden_words" if forbidden_words_file_location == ""
|
140
|
+
|
141
|
+
forbidden_words_file_location
|
142
|
+
end
|
143
|
+
|
144
|
+
def set_commit_for_user
|
145
|
+
lines_pretty_print 'Would you like Wielder of Anor to run your commits for you once you'\
|
146
|
+
' have verified that your code is free of forbidden words?'
|
147
|
+
lines_pretty_print Rainbow('(Type \'yes\' or \'no\'. Just hitting enter defaults to no.)').yellow
|
148
|
+
|
149
|
+
commit_for_user = STDIN.gets.strip!.downcase
|
150
|
+
commit_for_user = 'no' if commit_for_user == ''
|
151
|
+
|
152
|
+
until commit_for_user == 'yes' || commit_for_user =='y' || commit_for_user == 'no' || commit_for_user == 'n' do
|
153
|
+
lines_pretty_print Rainbow('Please type either \'yes\' or \'no\'.').yellow
|
154
|
+
commit_for_user = STDIN.gets.strip!.downcase
|
155
|
+
end
|
156
|
+
|
157
|
+
commit_for_user
|
158
|
+
end
|
159
|
+
|
160
|
+
def set_configs(files_changed_file_location, forbidden_words_file_location, commit_for_user)
|
161
|
+
config = {}
|
162
|
+
config['files_changed_file_location'] = files_changed_file_location
|
163
|
+
config['forbidden_words_file_location'] = forbidden_words_file_location
|
164
|
+
|
165
|
+
if commit_for_user == 'yes' || commit_for_user == 'y'
|
166
|
+
config['commit_for_user'] = true
|
167
|
+
elsif commit_for_user == 'no' || commit_for_user == 'n'
|
168
|
+
config['commit_for_user'] = false
|
169
|
+
end
|
170
|
+
|
171
|
+
file = File.open('config/config.yaml', 'w')
|
172
|
+
YAML.dump(config, file)
|
173
|
+
file.close
|
174
|
+
end
|
175
|
+
|
176
|
+
def set_forbidden_words(forbidden_words_file_location)
|
177
|
+
forbidden_words_file = File.open(forbidden_words_file_location, 'w')
|
178
|
+
forbidden_words_count = 0
|
179
|
+
|
180
|
+
done = false
|
181
|
+
|
182
|
+
lines_pretty_print 'Great! Now that we\'re done with the files, let\'s add your forbidden '\
|
183
|
+
'words from here!'
|
184
|
+
single_space
|
185
|
+
|
186
|
+
until done do
|
187
|
+
lines_pretty_print Rainbow('Enter a forbidden word and hit enter. If you are done entering '\
|
188
|
+
'forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words_count > 0
|
189
|
+
|
190
|
+
lines_pretty_print Rainbow('Added! Enter another forbidden word and hit enter. If you are done '\
|
191
|
+
'entering forbidden words, type \'x211\' and hit enter instead.').yellow unless forbidden_words_count == 0
|
192
|
+
word = STDIN.gets.strip!
|
193
|
+
single_space
|
194
|
+
|
195
|
+
if word == 'x211'
|
196
|
+
done = true
|
197
|
+
else
|
198
|
+
forbidden_words_file.puts word
|
199
|
+
forbidden_words_count += 1
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
forbidden_words_file.close
|
204
|
+
|
205
|
+
lines_pretty_print 'And with that, we\'re done! Feel free to run Wielder of Anor again if'\
|
206
|
+
' you\'d like to check your code now!'
|
207
|
+
|
208
|
+
abort
|
209
|
+
end
|
210
|
+
|
211
|
+
def git_diff
|
212
|
+
bash("git diff HEAD --name-only --staged > #{@files_changed_file_location}")
|
213
|
+
end
|
214
|
+
|
215
|
+
def get_forbidden_words(file_location)
|
216
|
+
forbidden_words_file = File.open(file_location)
|
217
|
+
|
218
|
+
forbidden_words_file.each_line do |line|
|
219
|
+
@forbidden_words << line.strip
|
220
|
+
end
|
221
|
+
|
222
|
+
forbidden_words_file.close
|
223
|
+
end
|
224
|
+
|
225
|
+
def wielder_of_anor
|
226
|
+
found_forbidden = false
|
227
|
+
|
228
|
+
# If we're forcing the commit, don't bother checking for forbidden words.
|
229
|
+
unless @force_commit
|
230
|
+
count = File.foreach(@files_changed_file).inject(0) {|c, line| c+1}
|
231
|
+
|
232
|
+
if count == 0
|
233
|
+
single_space
|
234
|
+
|
235
|
+
lines_pretty_print Rainbow('No files have been added. Please use the git add command to add files to your '\
|
236
|
+
'commit.').red
|
237
|
+
|
238
|
+
single_space
|
239
|
+
|
240
|
+
abort
|
241
|
+
end
|
242
|
+
|
243
|
+
single_space
|
244
|
+
|
245
|
+
print_header_footer
|
246
|
+
|
247
|
+
single_space
|
248
|
+
|
249
|
+
@files_changed_file.each_line do |files_changed_line|
|
250
|
+
code_file = File.open("#{@current_directory}/#{files_changed_line.strip}", "r")
|
251
|
+
index = 0
|
252
|
+
|
253
|
+
code_file.each_line do |line|
|
254
|
+
index += 1
|
255
|
+
@forbidden_words.each do |word|
|
256
|
+
if line.include?(word)
|
257
|
+
found_forbidden = true
|
258
|
+
lines_pretty_print "-- FORBIDDEN WORD FOUND ON LINE #{index} IN #{files_changed_line.strip}: --"
|
259
|
+
lines_pretty_print " #{line.strip!}"
|
260
|
+
double_space
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
code_file.close
|
266
|
+
end
|
267
|
+
|
268
|
+
single_space
|
269
|
+
|
270
|
+
print_header_footer
|
271
|
+
|
272
|
+
single_space
|
273
|
+
else
|
274
|
+
lines_pretty_print Rainbow('NOT SEARCHING FOR FORBIDDEN WORDS, PER USER INPUT.').red
|
275
|
+
single_space
|
276
|
+
end
|
277
|
+
|
278
|
+
@files_changed_file.close
|
279
|
+
|
280
|
+
results(found_forbidden)
|
281
|
+
end
|
282
|
+
|
283
|
+
def results(found_forbidden)
|
284
|
+
if found_forbidden
|
285
|
+
single_space
|
286
|
+
lines_pretty_print 'Remove offending line(s) and re-run commit statement or run this '\
|
287
|
+
'app again with \'1\' as your second argument to force the commit.'
|
288
|
+
|
289
|
+
single_space
|
290
|
+
lines_pretty_print Rainbow('**ONLY FORCE THE COMMIT IF YOU ARE SURE YOU ARE 100% SURE YOU WANT '\
|
291
|
+
'TO COMMIT THE ABOVE LINES TO YOUR BRANCH!!**').red
|
292
|
+
File.delete(@files_changed_file)
|
293
|
+
abort
|
294
|
+
else
|
295
|
+
unless @force_commit
|
296
|
+
lines_pretty_print Rainbow('Found 0 forbidden words!').green
|
297
|
+
|
298
|
+
single_space
|
299
|
+
end
|
300
|
+
|
301
|
+
File.delete(@files_changed_file)
|
302
|
+
commit if @commit_for_user
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def print_header_footer
|
307
|
+
puts '***************************************************************************'
|
308
|
+
end
|
309
|
+
|
310
|
+
def commit
|
311
|
+
if @force_commit
|
312
|
+
lines_pretty_print 'Skipped checking for forbidden words. Ready to commit now?'
|
313
|
+
lines_pretty_print Rainbow('**WARNING: YOU ARE FORCING THE COMMIT WITHOUT CHECKING FOR FORBIDDEN WORDS.**').red
|
314
|
+
|
315
|
+
single_space
|
316
|
+
else
|
317
|
+
lines_pretty_print 'Okay to commit! Should I go ahead and run the actual commit now?'
|
318
|
+
end
|
319
|
+
|
320
|
+
lines_pretty_print 'Please type \'yes\' OR \'y\' to continue. Any other input will be treated as a \'no\'.'
|
321
|
+
|
322
|
+
input = STDIN.gets.chomp.downcase
|
323
|
+
|
324
|
+
single_space
|
325
|
+
|
326
|
+
if input == 'yes' || input == 'y'
|
327
|
+
bash(%Q[git commit -m "#{@commit_message}"])
|
328
|
+
single_space
|
329
|
+
lines_pretty_print 'Committed.'
|
330
|
+
single_space
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def bash(command)
|
335
|
+
# Dir.chdir ensures all bash commands are being run from the correct
|
336
|
+
# directory.
|
337
|
+
Dir.chdir(@current_directory) { system "#{command}" }
|
338
|
+
end
|
339
|
+
|
340
|
+
def set_app_directory
|
341
|
+
@app_directory = File.expand_path(File.dirname(__FILE__)).chomp('/lib')
|
342
|
+
end
|
343
|
+
|
344
|
+
def lines_pretty_print(string)
|
345
|
+
lines = string.scan(/\S.{0,70}\S(?=\s|$)|\S+/)
|
346
|
+
|
347
|
+
lines.each { |line| puts line }
|
348
|
+
end
|
349
|
+
|
350
|
+
def single_space
|
351
|
+
puts ''
|
352
|
+
end
|
353
|
+
|
354
|
+
def double_space
|
355
|
+
puts "\n\n"
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wielder_of_anor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wielder_of_anor'
|
8
|
+
spec.version = WielderOfAnor::VERSION
|
9
|
+
spec.authors = ['Chris Sellek']
|
10
|
+
spec.email = ['iamsellek@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Checks a user\'s staged files for \'forbidden\' words (as determined by the user) '\
|
13
|
+
'and, if any are found, alerts the user to the locations of said words.'
|
14
|
+
spec.description = 'See GitHub page for longer description.'
|
15
|
+
spec.homepage = 'https://github.com/iamsellek/wielder_of_anor'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = ['wielder_of_anor']
|
20
|
+
spec.test_files = []
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'rainbow'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wielder_of_anor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Sellek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rainbow
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: See GitHub page for longer description.
|
56
|
+
email:
|
57
|
+
- iamsellek@gmail.com
|
58
|
+
executables:
|
59
|
+
- wielder_of_anor
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile.rb
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- bin/wielder_of_anor
|
71
|
+
- lib/wielder_of_anor.rb
|
72
|
+
- lib/wielder_of_anor/version.rb
|
73
|
+
- wielder_of_anor.gemspec
|
74
|
+
homepage: https://github.com/iamsellek/wielder_of_anor
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.14.1
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Checks a user's staged files for 'forbidden' words (as determined by the
|
98
|
+
user) and, if any are found, alerts the user to the locations of said words.
|
99
|
+
test_files: []
|