watson-ruby 1.0.5 → 1.0.6
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +44 -23
- data/assets/defaultConf +6 -6
- data/bin/watson +1 -1
- data/lib/watson.rb +17 -17
- data/lib/watson/bitbucket.rb +52 -52
- data/lib/watson/command.rb +66 -66
- data/lib/watson/config.rb +73 -73
- data/lib/watson/fs.rb +15 -15
- data/lib/watson/github.rb +60 -60
- data/lib/watson/parser.rb +36 -31
- data/lib/watson/printer.rb +33 -33
- data/lib/watson/remote.rb +23 -23
- data/lib/watson/version.rb +2 -2
- data/spec/config_spec.rb +11 -11
- data/spec/fs_spec.rb +1 -1
- data/spec/helper_spec.rb +1 -1
- data/spec/parser_spec.rb +73 -9
- data/watson.gemspec +4 -4
- metadata +2 -2
data/lib/watson/fs.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Watson
|
2
|
-
# File system utility function class
|
3
|
-
# Contains all methods for file access in watson
|
4
|
-
class FS
|
5
|
-
|
2
|
+
# File system utility function class
|
3
|
+
# Contains all methods for file access in watson
|
4
|
+
class FS
|
5
|
+
|
6
6
|
# Debug printing for this class
|
7
7
|
DEBUG = false
|
8
|
-
|
8
|
+
|
9
9
|
class << self
|
10
10
|
# [todo] - Not sure whether to make check* methods return FP
|
11
11
|
# Makes it nice to get it returned and use it but
|
@@ -14,17 +14,17 @@ module Watson
|
|
14
14
|
|
15
15
|
# Include for debug_print
|
16
16
|
include Watson
|
17
|
-
|
17
|
+
|
18
18
|
###########################################################
|
19
19
|
# Check if file exists and can be opened
|
20
20
|
def check_file(file)
|
21
|
-
|
21
|
+
|
22
22
|
# Identify method entry
|
23
23
|
debug_print "#{ self } : #{ __method__ }\n"
|
24
|
-
|
24
|
+
|
25
25
|
# Error check for input
|
26
26
|
if file.length == 0
|
27
|
-
debug_print "No file specified\n"
|
27
|
+
debug_print "No file specified\n"
|
28
28
|
return false
|
29
29
|
end
|
30
30
|
|
@@ -35,31 +35,31 @@ module Watson
|
|
35
35
|
else
|
36
36
|
debug_print "Could not open #{ file }, skipping\n"
|
37
37
|
return false
|
38
|
-
end
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
|
42
42
|
###########################################################
|
43
|
-
# Check if directory exists and can be opened
|
43
|
+
# Check if directory exists and can be opened
|
44
44
|
def check_dir(dir)
|
45
|
-
|
45
|
+
|
46
46
|
# Identify method entry
|
47
47
|
debug_print "#{ self } : #{ __method__ }\n"
|
48
|
-
|
48
|
+
|
49
49
|
# Error check for input
|
50
50
|
if dir.length == 0
|
51
51
|
debug_print "No directory specified\n"
|
52
52
|
return false
|
53
53
|
end
|
54
54
|
|
55
|
-
# Check if directory exists
|
55
|
+
# Check if directory exists
|
56
56
|
if Dir.exists?(dir)
|
57
57
|
debug_print "#{ dir } exists and opened succesfully\n"
|
58
58
|
return true
|
59
59
|
else
|
60
60
|
debug_print "Could not open #{ dir }, skipping\n"
|
61
61
|
return false
|
62
|
-
end
|
62
|
+
end
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
data/lib/watson/github.rb
CHANGED
@@ -2,34 +2,34 @@ module Watson
|
|
2
2
|
class Remote
|
3
3
|
# GitHub remote access class
|
4
4
|
# Contains all necessary methods to obtain access to, get issue list,
|
5
|
-
# and post issues to GitHub
|
5
|
+
# and post issues to GitHub
|
6
6
|
class GitHub
|
7
|
-
|
7
|
+
|
8
8
|
# Debug printing for this class
|
9
|
-
DEBUG = false
|
9
|
+
DEBUG = false
|
10
10
|
|
11
11
|
class << self
|
12
12
|
|
13
13
|
# [todo] - Allow closing of issues from watson? Don't like that idea but maybe
|
14
|
-
# [review] - Properly scope Printer class so we dont need the Printer. for
|
14
|
+
# [review] - Properly scope Printer class so we dont need the Printer. for
|
15
15
|
# method calls?
|
16
16
|
# [todo] - Keep asking for user data until valid instead of leaving app
|
17
17
|
|
18
18
|
|
19
19
|
# Include for debug_print
|
20
20
|
include Watson
|
21
|
-
|
22
|
-
#############################################################################
|
23
|
-
# Setup remote access to GitHub
|
21
|
+
|
22
|
+
#############################################################################
|
23
|
+
# Setup remote access to GitHub
|
24
24
|
# Get Username, Repo, and PW and perform necessary HTTP calls to check validity
|
25
25
|
def setup(config)
|
26
26
|
|
27
27
|
# Identify method entry
|
28
28
|
debug_print "#{ self.class } : #{ __method__ }\n"
|
29
|
-
|
29
|
+
|
30
30
|
Printer.print_status "+", GREEN
|
31
31
|
print BOLD + "Obtaining OAuth Token for GitHub...\n" + RESET
|
32
|
-
|
32
|
+
|
33
33
|
# Check config to make sure no previous API exists
|
34
34
|
unless config.github_api.empty? && config.github_repo.empty?
|
35
35
|
Printer.print_status "!", RED
|
@@ -78,7 +78,7 @@ module Watson
|
|
78
78
|
# HTTP Request to get OAuth Token
|
79
79
|
# GitHub API v3 - http://developer.github.com/v3/
|
80
80
|
|
81
|
-
# Create options hash to pass to Remote::http_call
|
81
|
+
# Create options hash to pass to Remote::http_call
|
82
82
|
# Auth URL for GitHub + SSL
|
83
83
|
# Repo scope + notes for watson
|
84
84
|
# Basic auth with user input
|
@@ -86,9 +86,9 @@ module Watson
|
|
86
86
|
:ssl => true,
|
87
87
|
:method => "POST",
|
88
88
|
:basic_auth => [_username, _password],
|
89
|
-
:data => {"scopes" => ["repo"],
|
90
|
-
"note" => "watson",
|
91
|
-
"note_url" => "http://watson.goosecode.com/" },
|
89
|
+
:data => {"scopes" => ["repo"],
|
90
|
+
"note" => "watson",
|
91
|
+
"note_url" => "http://watson.goosecode.com/" },
|
92
92
|
:verbose => false
|
93
93
|
}
|
94
94
|
|
@@ -103,8 +103,8 @@ module Watson
|
|
103
103
|
print BOLD + "Unable to obtain OAuth Token\n" + RESET
|
104
104
|
print " Status: #{ _resp.code } - #{ _resp.message }\n\n"
|
105
105
|
return false
|
106
|
-
end
|
107
|
-
|
106
|
+
end
|
107
|
+
|
108
108
|
# Store API key obtained from POST to @config.github_api
|
109
109
|
config.github_api = _json["token"]
|
110
110
|
debug_print "Config GitHub API Key updated to: #{ config.github_api }\n"
|
@@ -139,23 +139,23 @@ module Watson
|
|
139
139
|
# Make call to GitHub API to create new label for Issues
|
140
140
|
# If status returns not 404, then we have access to repo (+ it exists)
|
141
141
|
# If 422, then (most likely) the label already exists
|
142
|
-
|
143
|
-
# Create options hash to pass to Remote::http_call
|
142
|
+
|
143
|
+
# Create options hash to pass to Remote::http_call
|
144
144
|
# Label URL for GitHub + SSL
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# Auth token
|
147
147
|
opts = {:url => "https://api.github.com/repos/#{ _owner }/#{ _repo }/labels",
|
148
148
|
:ssl => true,
|
149
149
|
:method => "POST",
|
150
|
-
:auth => config.github_api,
|
151
|
-
:data => {"name" => "watson",
|
152
|
-
"color" => "00AEEF" },
|
150
|
+
:auth => config.github_api,
|
151
|
+
:data => {"name" => "watson",
|
152
|
+
"color" => "00AEEF" },
|
153
153
|
:verbose => false
|
154
154
|
}
|
155
155
|
|
156
156
|
_json, _resp = Watson::Remote.http_call(opts)
|
157
|
-
|
158
|
-
# [review] - This is pretty messy, maybe clean it up later
|
157
|
+
|
158
|
+
# [review] - This is pretty messy, maybe clean it up later
|
159
159
|
# Check response to validate repo access
|
160
160
|
if _resp.code == "404"
|
161
161
|
print "\n"
|
@@ -172,12 +172,12 @@ module Watson
|
|
172
172
|
Printer.print_status "o", GREEN
|
173
173
|
print BOLD + "Repo successfully accessed\n\n" + RESET
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
# Store owner/repo obtained from POST to @config.github_repo
|
177
177
|
config.github_repo = "#{ _owner }/#{ _repo }"
|
178
178
|
debug_print "Config GitHub API Key updated to: #{ config.github_repo }\n"
|
179
179
|
|
180
|
-
# Inform user of label creation status (created above)
|
180
|
+
# Inform user of label creation status (created above)
|
181
181
|
Printer.print_status "+", GREEN
|
182
182
|
print BOLD + "Creating label for watson on GitHub...\n" + RESET
|
183
183
|
if _resp.code == "201"
|
@@ -193,7 +193,7 @@ module Watson
|
|
193
193
|
end
|
194
194
|
|
195
195
|
# All setup has been completed, need to update RC
|
196
|
-
# Call config updater/writer from @config to write config
|
196
|
+
# Call config updater/writer from @config to write config
|
197
197
|
debug_print "Updating config with new GitHub info\n"
|
198
198
|
config.update_conf("github_api", "github_repo")
|
199
199
|
|
@@ -211,14 +211,14 @@ module Watson
|
|
211
211
|
|
212
212
|
|
213
213
|
###########################################################
|
214
|
-
# Get all remote GitHub issues and store into Config container class
|
214
|
+
# Get all remote GitHub issues and store into Config container class
|
215
215
|
|
216
216
|
def get_issues(config)
|
217
217
|
|
218
218
|
# Identify method entry
|
219
219
|
debug_print "#{ self.class } : #{ __method__ }\n"
|
220
220
|
|
221
|
-
# Only attempt to get issues if API is specified
|
221
|
+
# Only attempt to get issues if API is specified
|
222
222
|
if config.github_api.empty?
|
223
223
|
debug_print "No API found, this shouldn't be called...\n"
|
224
224
|
return false
|
@@ -226,18 +226,18 @@ module Watson
|
|
226
226
|
|
227
227
|
|
228
228
|
# Get all open tickets
|
229
|
-
# Create options hash to pass to Remote::http_call
|
229
|
+
# Create options hash to pass to Remote::http_call
|
230
230
|
# Issues URL for GitHub + SSL
|
231
231
|
opts = {:url => "https://api.github.com/repos/#{ config.github_repo }/issues?labels=watson&state=open",
|
232
232
|
:ssl => true,
|
233
233
|
:method => "GET",
|
234
|
-
:auth => config.github_api,
|
235
|
-
:verbose => false
|
234
|
+
:auth => config.github_api,
|
235
|
+
:verbose => false
|
236
236
|
}
|
237
237
|
|
238
238
|
_json, _resp = Watson::Remote.http_call(opts)
|
239
|
-
|
240
|
-
|
239
|
+
|
240
|
+
|
241
241
|
# Check response to validate repo access
|
242
242
|
if _resp.code != "200"
|
243
243
|
Printer.print_status "x", RED
|
@@ -252,15 +252,15 @@ module Watson
|
|
252
252
|
|
253
253
|
config.github_issues[:open] = _json.empty? ? Hash.new : _json
|
254
254
|
config.github_valid = true
|
255
|
-
|
255
|
+
|
256
256
|
# Get all closed tickets
|
257
257
|
# Create option hash to pass to Remote::http_call
|
258
258
|
# Issues URL for GitHub + SSL
|
259
259
|
opts = {:url => "https://api.github.com/repos/#{ config.github_repo }/issues?labels=watson&state=closed",
|
260
260
|
:ssl => true,
|
261
261
|
:method => "GET",
|
262
|
-
:auth => config.github_api,
|
263
|
-
:verbose => false
|
262
|
+
:auth => config.github_api,
|
263
|
+
:verbose => false
|
264
264
|
}
|
265
265
|
|
266
266
|
_json, _resp = Watson::Remote.http_call(opts)
|
@@ -270,9 +270,9 @@ module Watson
|
|
270
270
|
if _resp.code != "200"
|
271
271
|
Printer.print_status "x", RED
|
272
272
|
print BOLD + "Unable to get closed issues.\n" + RESET
|
273
|
-
print " Since the open issues were obtained, something is probably wrong and you should file a bug report or something...\n"
|
273
|
+
print " Since the open issues were obtained, something is probably wrong and you should file a bug report or something...\n"
|
274
274
|
print " Status: #{ _resp.code } - #{ _resp.message }\n"
|
275
|
-
|
275
|
+
|
276
276
|
debug_print "GitHub invalid, setting config var\n"
|
277
277
|
config.github_valid = false
|
278
278
|
return false
|
@@ -281,20 +281,20 @@ module Watson
|
|
281
281
|
config.github_issues[:closed] = _json.empty? ? Hash.new : _json
|
282
282
|
config.github_valid = true
|
283
283
|
return true
|
284
|
-
end
|
284
|
+
end
|
285
285
|
|
286
286
|
|
287
287
|
###########################################################
|
288
|
-
# Post given issue to remote GitHub repo
|
288
|
+
# Post given issue to remote GitHub repo
|
289
289
|
def post_issue(issue, config)
|
290
290
|
# [todo] - Better way to identify/compare remote->local issues than md5
|
291
291
|
# Current md5 based on some things that easily can change, need better ident
|
292
292
|
|
293
293
|
# Identify method entry
|
294
294
|
debug_print "#{ self.class } : #{ __method__ }\n"
|
295
|
-
|
296
|
-
|
297
|
-
# Only attempt to get issues if API is specified
|
295
|
+
|
296
|
+
|
297
|
+
# Only attempt to get issues if API is specified
|
298
298
|
if config.github_api.empty?
|
299
299
|
debug_print "No API found, this shouldn't be called...\n"
|
300
300
|
return false
|
@@ -307,62 +307,62 @@ module Watson
|
|
307
307
|
# call exec and turn it into a real hash for parsing in watson
|
308
308
|
# Makes watson code cleaner but not as readable comment on GitHub...?
|
309
309
|
debug_print "Checking open issues to see if already posted\n"
|
310
|
-
config.github_issues[:open].each do | _open |
|
310
|
+
config.github_issues[:open].each do | _open |
|
311
311
|
if _open["body"].include?(issue[:md5])
|
312
312
|
debug_print "Found in #{ _open["title"] }, not posting\n"
|
313
313
|
return false
|
314
314
|
end
|
315
315
|
debug_print "Did not find in #{ _open["title"] }\n"
|
316
|
-
end
|
317
|
-
|
318
|
-
|
316
|
+
end
|
317
|
+
|
318
|
+
|
319
319
|
debug_print "Checking closed issues to see if already posted\n"
|
320
|
-
config.github_issues[:closed].each do | _closed |
|
320
|
+
config.github_issues[:closed].each do | _closed |
|
321
321
|
if _closed["body"].include?(issue[:md5])
|
322
322
|
debug_print "Found in #{ _closed["title"] }, not posting\n"
|
323
323
|
return false
|
324
324
|
end
|
325
325
|
debug_print "Did not find in #{ _closed["title"] }\n"
|
326
326
|
end
|
327
|
-
|
327
|
+
|
328
328
|
# We didn't find the md5 for this issue in the open or closed issues, so safe to post
|
329
|
-
|
329
|
+
|
330
330
|
# Create the body text for the issue here, too long to fit nicely into opts hash
|
331
331
|
# [review] - Only give relative path for privacy when posted
|
332
332
|
_body = "__filename__ : #{ issue[:path] }\n" +
|
333
|
-
"__line #__ : #{ issue[:line_number] }\n" +
|
333
|
+
"__line #__ : #{ issue[:line_number] }\n" +
|
334
334
|
"__tag__ : #{ issue[:tag] }\n" +
|
335
335
|
"__md5__ : #{ issue[:md5] }\n\n" +
|
336
336
|
"#{ issue[:context].join }\n"
|
337
|
-
|
337
|
+
|
338
338
|
# Create option hash to pass to Remote::http_call
|
339
339
|
# Issues URL for GitHub + SSL
|
340
340
|
opts = {:url => "https://api.github.com/repos/#{ config.github_repo }/issues",
|
341
341
|
:ssl => true,
|
342
342
|
:method => "POST",
|
343
|
-
:auth => config.github_api,
|
343
|
+
:auth => config.github_api,
|
344
344
|
:data => { "title" => issue[:title] + " [#{ issue[:path] }]",
|
345
345
|
"labels" => [issue[:tag], "watson"],
|
346
346
|
"body" => _body },
|
347
|
-
:verbose => false
|
347
|
+
:verbose => false
|
348
348
|
}
|
349
349
|
|
350
350
|
_json, _resp = Watson::Remote.http_call(opts)
|
351
|
-
|
352
|
-
|
351
|
+
|
352
|
+
|
353
353
|
# Check response to validate repo access
|
354
354
|
# Shouldn't be necessary if we passed the last check but just to be safe
|
355
355
|
if _resp.code != "201"
|
356
356
|
Printer.print_status "x", RED
|
357
357
|
print BOLD + "Post unsuccessful. \n" + RESET
|
358
|
-
print " Since the open issues were obtained earlier, something is probably wrong and you should let someone know...\n"
|
358
|
+
print " Since the open issues were obtained earlier, something is probably wrong and you should let someone know...\n"
|
359
359
|
print " Status: #{ _resp.code } - #{ _resp.message }\n"
|
360
360
|
return false
|
361
361
|
end
|
362
|
-
|
363
|
-
return true
|
362
|
+
|
363
|
+
return true
|
364
364
|
end
|
365
|
-
|
365
|
+
|
366
366
|
end
|
367
367
|
end
|
368
368
|
end
|
data/lib/watson/parser.rb
CHANGED
@@ -209,10 +209,10 @@ module Watson
|
|
209
209
|
_data.push(_line)
|
210
210
|
_line.encode('UTF-8', :invalid => :replace)
|
211
211
|
end
|
212
|
-
|
213
|
-
# Initialize issue list hash
|
212
|
+
|
213
|
+
# Initialize issue list hash
|
214
214
|
_issue_list = Hash.new()
|
215
|
-
_issue_list[:relative_path] = _relative_path
|
215
|
+
_issue_list[:relative_path] = _relative_path
|
216
216
|
_issue_list[:absolute_path] = _absolute_path
|
217
217
|
_issue_list[:has_issues] = false
|
218
218
|
@config.tag_list.each do | _tag |
|
@@ -368,6 +368,34 @@ module Watson
|
|
368
368
|
# Create _mtch var so we can access it outside of the do loop
|
369
369
|
|
370
370
|
|
371
|
+
|
372
|
+
_ext = { '.cpp' => ['//', '/*'], # C++
|
373
|
+
'.cc' => ['//', '/*'],
|
374
|
+
'.hpp' => ['//', '/*'],
|
375
|
+
'.c' => ['//', '/*'], # C
|
376
|
+
'.h' => ['//', '/*'],
|
377
|
+
'.java' => ['//', '/*', '/**'], # Java
|
378
|
+
'.class' => ['//', '/*', '/**'],
|
379
|
+
'.cs' => ['//', '/*'], # C#
|
380
|
+
'.js' => ['//', '/*'], # JavaScript
|
381
|
+
'.php' => ['//', '/*', '#'], # PHP
|
382
|
+
'.m' => ['//', '/*'], # ObjectiveC
|
383
|
+
'.mm' => ['//', '/*'],
|
384
|
+
'.go' => ['//', '/*'], # Go(lang)
|
385
|
+
'.scala' => ['//', '/*'], # Scala
|
386
|
+
'.erl' => ['%%', '%'], # Erlang
|
387
|
+
'.hs' => ['--'], # Haskell
|
388
|
+
'.sh' => ['#'], # Bash
|
389
|
+
'.rb' => ['#'], # Ruby
|
390
|
+
'.pl' => ['#'], # Perl
|
391
|
+
'.pm' => ['#'],
|
392
|
+
'.t' => ['#'],
|
393
|
+
'.py' => ['#'], # Python
|
394
|
+
'.coffee' => ['#'], # CoffeeScript
|
395
|
+
'.zsh' => ['#'], # Zsh
|
396
|
+
'.clj' => [';;'] # Clojure
|
397
|
+
}
|
398
|
+
|
371
399
|
loop do
|
372
400
|
_mtch = filename.match(/(\.(\w+))$/)
|
373
401
|
debug_print "Extension: #{ _mtch }\n"
|
@@ -375,35 +403,12 @@ module Watson
|
|
375
403
|
# Break if we don't find a match
|
376
404
|
break if _mtch.nil?
|
377
405
|
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
'.java', '.class', '.cs', '.js', '.php',
|
384
|
-
'.m', '.mm', '.go'
|
385
|
-
debug_print "Comment type is: //\n"
|
386
|
-
return '//'
|
387
|
-
|
388
|
-
when '.hs'
|
389
|
-
debug_print "Comment type is: --\n"
|
390
|
-
return '--'
|
391
|
-
|
392
|
-
when '.erl'
|
393
|
-
debug_print "Comment type is: %\n"
|
394
|
-
return '%'
|
395
|
-
|
396
|
-
# Bash, Ruby, Perl, Python
|
397
|
-
when '.sh', '.rb', '.pl', '.py', '.coffee'
|
398
|
-
debug_print "Comment type is: #\n"
|
399
|
-
return '#'
|
400
|
-
|
401
|
-
# Can't recognize extension, keep looping in case of .bk, .#, ect
|
402
|
-
else
|
403
|
-
filename = filename.gsub(/(\.(\w+))$/, '')
|
404
|
-
debug_print "Didn't recognize, searching #{ filename }\n"
|
406
|
+
return _ext[_mtch[0]] if _ext.has_key?(_mtch[0])
|
407
|
+
|
408
|
+
# Can't recognize extension, keep looping in case of .bk, .#, ect
|
409
|
+
filename = filename.gsub(/(\.(\w+))$/, '')
|
410
|
+
debug_print "Didn't recognize, searching #{ filename }\n"
|
405
411
|
|
406
|
-
end
|
407
412
|
end
|
408
413
|
|
409
414
|
# We didn't find any matches from the filename, return error (0)
|