watson-ruby 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +37 -8
- data/lib/watson.rb +23 -15
- data/lib/watson/asana.rb +619 -0
- data/lib/watson/bitbucket.rb +0 -3
- data/lib/watson/command.rb +29 -6
- data/lib/watson/config.rb +79 -25
- data/lib/watson/formatters/base_formatter.rb +0 -1
- data/lib/watson/formatters/default_formatter.rb +9 -0
- data/lib/watson/fs.rb +0 -3
- data/lib/watson/github.rb +5 -4
- data/lib/watson/gitlab.rb +0 -3
- data/lib/watson/parser.rb +7 -5
- data/lib/watson/printer.rb +0 -3
- data/lib/watson/remote.rb +2 -4
- data/lib/watson/version.rb +1 -1
- data/spec/config_spec.rb +6 -0
- data/spec/parser_spec.rb +1 -0
- metadata +4 -3
data/lib/watson/bitbucket.rb
CHANGED
data/lib/watson/command.rb
CHANGED
@@ -3,9 +3,6 @@ module Watson
|
|
3
3
|
# Controls program flow and parses options given by command line
|
4
4
|
class Command
|
5
5
|
|
6
|
-
# Debug printing for this class
|
7
|
-
DEBUG = false
|
8
|
-
|
9
6
|
class << self
|
10
7
|
|
11
8
|
# Include for debug_print
|
@@ -26,18 +23,33 @@ module Watson
|
|
26
23
|
_flag_list = %w[
|
27
24
|
-c --context-depth
|
28
25
|
-d --dirs
|
26
|
+
--debug
|
29
27
|
-f --files
|
28
|
+
--format
|
30
29
|
-h --help
|
31
30
|
-i --ignore
|
32
31
|
-p --parse-depth
|
33
32
|
-r --remote
|
34
33
|
-s --show
|
35
34
|
-t --tags
|
36
|
-
--format
|
37
35
|
-u --update
|
38
36
|
-v --version
|
39
37
|
]
|
40
38
|
|
39
|
+
# Add debug prints based on --debug flag
|
40
|
+
if (_index = args.index('--debug')) != nil
|
41
|
+
_debug_mode = Array.new
|
42
|
+
_index += 1
|
43
|
+
until _flag_list.include?(args[_index]) || _index > (args.length - 1)
|
44
|
+
_debug_mode.push(args[_index].downcase)
|
45
|
+
_index += 1
|
46
|
+
end
|
47
|
+
# Slice out so we can ignore in regular CLI parsing
|
48
|
+
args.slice!(args.index('--debug') ... _index)
|
49
|
+
|
50
|
+
Watson.debug_mode = _debug_mode
|
51
|
+
end
|
52
|
+
|
41
53
|
|
42
54
|
# If we get the version or help flag, ignore all other flags
|
43
55
|
# Just display these and exit
|
@@ -46,7 +58,6 @@ module Watson
|
|
46
58
|
return version if args.index('-v') != nil || args.index('--version') != nil
|
47
59
|
|
48
60
|
|
49
|
-
|
50
61
|
# If not one of the above then we are performing actual watson stuff
|
51
62
|
# Create all the necessary watson components so we can perform
|
52
63
|
# all actions associated with command line args
|
@@ -179,6 +190,8 @@ module Watson
|
|
179
190
|
|
180
191
|
-c, --context-depth lines of context to provide with posted issue
|
181
192
|
-d, --dirs list of directories to search in
|
193
|
+
--debug enable debug prints from specified class
|
194
|
+
all debug prints enabled if no arguments passed
|
182
195
|
-f, --files list of files to search in
|
183
196
|
--format set output format for watson
|
184
197
|
[print, json, unite, silent]
|
@@ -441,7 +454,7 @@ module Watson
|
|
441
454
|
|
442
455
|
# Check the config for any remote entries (GitHub or Bitbucket) and print
|
443
456
|
# We *should* always have a repo + API together, but API should be enough
|
444
|
-
if @config.github_api.empty? && @config.bitbucket_api.empty?
|
457
|
+
if @config.github_api.empty? && @config.bitbucket_api.empty? && @config.asana_api.empty?
|
445
458
|
formatter.print_status "!", YELLOW
|
446
459
|
print BOLD + "No remotes currently exist\n\n" + RESET
|
447
460
|
end
|
@@ -461,6 +474,12 @@ module Watson
|
|
461
474
|
print BOLD + "GitLab Repo : " + RESET + "#{ @config.gitlab_repo }\n\n" + RESET
|
462
475
|
end
|
463
476
|
|
477
|
+
if !@config.asana_api.empty?
|
478
|
+
print BOLD + "Asana API Key : " + RESET + "#{ @config.asana_api }\n" + RESET
|
479
|
+
print BOLD + "Asana Workspace : " + RESET + "#{ @config.asana_workspace }\n" + RESET
|
480
|
+
print BOLD + "Asana Project : " + RESET + "#{ @config.asana_project }\n\n" + RESET
|
481
|
+
end
|
482
|
+
|
464
483
|
# If github or bitbucket passed, setup
|
465
484
|
# If just -r (0 args) do nothing and only have above printed
|
466
485
|
# If more than 1 arg is passed, unrecognized, warn user
|
@@ -478,6 +497,10 @@ module Watson
|
|
478
497
|
debug_print "GitLab setup called from CL\n"
|
479
498
|
Watson::Remote::GitLab.setup(@config)
|
480
499
|
|
500
|
+
when "asana"
|
501
|
+
debug_print "Asana setup called from CL\n"
|
502
|
+
Watson::Remote::Asana.setup(@config)
|
503
|
+
|
481
504
|
end
|
482
505
|
elsif args.length > 1
|
483
506
|
formatter.print_status "x", RED
|
data/lib/watson/config.rb
CHANGED
@@ -7,9 +7,6 @@ module Watson
|
|
7
7
|
# Include for debug_print
|
8
8
|
include Watson
|
9
9
|
|
10
|
-
# Debug printing for this class
|
11
|
-
DEBUG = false
|
12
|
-
|
13
10
|
# [review] - Combine into single statement (for performance or something?)
|
14
11
|
# [todo] - Add config options (rc file) for default max depth and context lines
|
15
12
|
|
@@ -21,6 +18,8 @@ module Watson
|
|
21
18
|
attr_accessor :file_list
|
22
19
|
# List of tags to look for when parsing
|
23
20
|
attr_accessor :tag_list
|
21
|
+
# List of custom filetypes to accept
|
22
|
+
attr_accessor :type_list
|
24
23
|
# Number of directories to parse recursively
|
25
24
|
attr_accessor :parse_depth
|
26
25
|
# Number of lines of issue context to grab
|
@@ -70,6 +69,17 @@ module Watson
|
|
70
69
|
# Hash to hold list of all Bitbucket issues associated with repo
|
71
70
|
attr_accessor :bitbucket_issues
|
72
71
|
|
72
|
+
# Flag for whether Asana access is avaliable
|
73
|
+
attr_accessor :asana_valid
|
74
|
+
# Asana API Key
|
75
|
+
attr_accessor :asana_api
|
76
|
+
# Asana workspace
|
77
|
+
attr_accessor :asana_workspace
|
78
|
+
# Asana project within the workspace to place issues
|
79
|
+
attr_accessor :asana_project
|
80
|
+
# Hash to hold list of all Asana issues associated with repo
|
81
|
+
attr_accessor :asana_issues
|
82
|
+
|
73
83
|
|
74
84
|
# Flag for whether GitLab access is avaliable
|
75
85
|
attr_accessor :gitlab_valid
|
@@ -119,6 +129,7 @@ module Watson
|
|
119
129
|
@dir_list = Array.new()
|
120
130
|
@file_list = Array.new()
|
121
131
|
@tag_list = Array.new()
|
132
|
+
@type_list = Hash.new()
|
122
133
|
@issue_count = 0
|
123
134
|
|
124
135
|
# Remote options
|
@@ -147,8 +158,16 @@ module Watson
|
|
147
158
|
@gitlab_issues = Hash.new()
|
148
159
|
|
149
160
|
|
161
|
+
@asana_valid = false
|
162
|
+
@asana_api = ""
|
163
|
+
@asana_workspace = ""
|
164
|
+
@asana_project = ""
|
165
|
+
@asana_issues = Hash.new()
|
166
|
+
|
150
167
|
|
151
168
|
@output_format = Watson::Formatters::DefaultFormatter
|
169
|
+
|
170
|
+
|
152
171
|
end
|
153
172
|
|
154
173
|
|
@@ -176,6 +195,11 @@ module Watson
|
|
176
195
|
unless @gitlab_api.empty? && @gitlab_repo.empty?
|
177
196
|
Remote::GitLab.get_issues(self)
|
178
197
|
end
|
198
|
+
|
199
|
+
unless @asana_api.empty? && @asana_project.empty? && @asana_workspace.empty?
|
200
|
+
Remote::Asana.get_issues(self)
|
201
|
+
end
|
202
|
+
|
179
203
|
end
|
180
204
|
|
181
205
|
|
@@ -207,40 +231,41 @@ module Watson
|
|
207
231
|
|
208
232
|
###########################################################
|
209
233
|
# Watson config creater
|
210
|
-
#
|
234
|
+
# Attempts to create config based on $HOME/.watsonrc
|
235
|
+
# If this doesn't exist, copies default config from /assets/defaultConf to $HOME and current directory
|
211
236
|
def create_conf
|
212
237
|
# [review] - Not sure if I should use the open/read/write or Fileutils.cp
|
213
238
|
|
214
239
|
# Identify method entry
|
215
240
|
debug_print "#{ self.class } : #{ __method__ }\n"
|
216
241
|
|
217
|
-
|
218
|
-
# Generate full path since File doesn't care about the LOAD_PATH
|
242
|
+
# Full path to assets/defaultConf (File class doesn't look at LOAD_PATH)
|
219
243
|
# [review] - gsub uses (.?)+ to grab anything after lib (optional), better regex?
|
220
244
|
_full_path = __dir__.gsub(%r!/lib/watson(.?)+!, '') + "/assets/defaultConf"
|
221
245
|
debug_print "Full path to defaultConf (in gem): #{ _full_path }\n"
|
222
246
|
|
223
|
-
#
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
247
|
+
# $HOME/.watsonrc exists, '~' should be crossplatform with File.expand_path
|
248
|
+
_home_path = File.expand_path('~') + '/.watsonrc'
|
249
|
+
|
250
|
+
# Obtain default config to write to current directory
|
251
|
+
if Watson::FS.check_file(_home_path)
|
252
|
+
_default = File.open(_home_path, 'r') { |file| file.read }
|
253
|
+
debug_print ".watsonrc found in $HOME, using as base\n"
|
254
|
+
elsif Watson::FS.check_file(_full_path)
|
255
|
+
_default = File.open(_full_path, 'r') { |file| file.read }
|
256
|
+
# Write default to $HOME
|
257
|
+
File.open(_home_path, 'w') { |file| file.write(_default) }
|
258
|
+
debug_print ".watsonrc not found in $HOME, using assets\n"
|
228
259
|
else
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
# Open rc file in current directory in write mode and write default
|
234
|
-
_output = File.open(@rc_file, 'w')
|
235
|
-
_output.write(_default)
|
236
|
-
|
237
|
-
# Close both default and new rc files
|
238
|
-
_input.close
|
239
|
-
_output.close
|
240
|
-
|
241
|
-
debug_print "Successfully wrote defaultConf to current directory\n"
|
242
|
-
return true
|
260
|
+
print "Unable to find .watsonrc in $HOME or #{ _full_path}\n"
|
261
|
+
print "Cannot create a default config, exiting...\n"
|
262
|
+
return false
|
243
263
|
end
|
264
|
+
|
265
|
+
# Open @rc_file and write the default contents to it
|
266
|
+
File.open(@rc_file, 'w') { |file| file.write(_default) }
|
267
|
+
debug_print "Successfully wrote defaultConf to current directory\n"
|
268
|
+
true
|
244
269
|
end
|
245
270
|
|
246
271
|
|
@@ -370,6 +395,16 @@ module Watson
|
|
370
395
|
debug_print "@tag_list --> #{ @tag_list }\n"
|
371
396
|
|
372
397
|
|
398
|
+
when "type"
|
399
|
+
# Regex to grab ".type" => ["param1", "param2"]
|
400
|
+
_mtch = _line.match(/(\"\S+\")\s+=>\s+(\[(\".+\")+\])/)
|
401
|
+
if !_mtch.nil?
|
402
|
+
_ext = _mtch[1].gsub(/\"/, '')
|
403
|
+
_type = JSON.parse(_mtch[2])
|
404
|
+
@type_list[_ext] = _type
|
405
|
+
end
|
406
|
+
|
407
|
+
|
373
408
|
when "ignore"
|
374
409
|
# Same as previous for ignores
|
375
410
|
# [review] - Populate @tag_list, then check size instead
|
@@ -441,6 +476,20 @@ module Watson
|
|
441
476
|
@gitlab_repo = _line.chomp!
|
442
477
|
debug_print "GitLab Repo: #{ @gitlab_repo }\n"
|
443
478
|
|
479
|
+
when "asana_project"
|
480
|
+
@asana_project = _line.chomp!
|
481
|
+
debug_print "Asana Project: #{ @asana_project }\n"
|
482
|
+
|
483
|
+
when "asana_api"
|
484
|
+
@asana_api = _line.chomp!
|
485
|
+
debug_print "Asana API: #{ @asana_api }\n"
|
486
|
+
|
487
|
+
when "asana_workspace"
|
488
|
+
@asana_workspace = _line.chomp!
|
489
|
+
debug_print "Asana Workspace: #{ @asana_workspace }\n"
|
490
|
+
|
491
|
+
|
492
|
+
|
444
493
|
else
|
445
494
|
debug_print "Unknown tag found #{_section}\n"
|
446
495
|
end
|
@@ -555,3 +604,8 @@ module Watson
|
|
555
604
|
end
|
556
605
|
end
|
557
606
|
|
607
|
+
if __FILE__ == $0
|
608
|
+
@config = Watson::Config.new
|
609
|
+
end
|
610
|
+
|
611
|
+
|
@@ -171,6 +171,15 @@ module Watson::Formatters
|
|
171
171
|
MESSAGE
|
172
172
|
end
|
173
173
|
|
174
|
+
if _AS = @config.asana_issues[issue[:md5]]
|
175
|
+
debug_print "Found #{ issue[:title]} in remote issues\n"
|
176
|
+
completed = _AS[:state]
|
177
|
+
|
178
|
+
cprint <<-MESSAGE.gsub(/^(\s+)/, '').chomp
|
179
|
+
#{BOLD}[#{RESET}#{completed ? GREEN : RED}#{BOLD}AS##{_AS[:id]}#{RESET}#{BOLD}]#{RESET}
|
180
|
+
MESSAGE
|
181
|
+
end
|
182
|
+
|
174
183
|
|
175
184
|
cprint "\n"
|
176
185
|
end
|
data/lib/watson/fs.rb
CHANGED
data/lib/watson/github.rb
CHANGED
@@ -5,9 +5,6 @@ module Watson
|
|
5
5
|
# and post issues to GitHub
|
6
6
|
class GitHub
|
7
7
|
|
8
|
-
# Debug printing for this class
|
9
|
-
DEBUG = false
|
10
|
-
|
11
8
|
class << self
|
12
9
|
|
13
10
|
# [todo] - Allow closing of issues from watson? Don't like that idea but maybe
|
@@ -102,6 +99,10 @@ module Watson
|
|
102
99
|
return false
|
103
100
|
end
|
104
101
|
|
102
|
+
# Label for Auth Token
|
103
|
+
print BOLD + "Auth Token Label (leave blank to ignore): " + RESET
|
104
|
+
_label = $stdin.gets.chomp
|
105
|
+
|
105
106
|
_endpoint = "https://api.github.com" if _endpoint.empty?
|
106
107
|
|
107
108
|
# HTTP Request to get OAuth Token
|
@@ -117,7 +118,7 @@ module Watson
|
|
117
118
|
:method => "POST",
|
118
119
|
:basic_auth => [_username, _password],
|
119
120
|
:data => {"scopes" => ["repo"],
|
120
|
-
"note" => "watson",
|
121
|
+
"note" => "watson - #{_label}",
|
121
122
|
"note_url" => "http://watson.goosecode.com/" },
|
122
123
|
:verbose => false
|
123
124
|
}
|
data/lib/watson/gitlab.rb
CHANGED
data/lib/watson/parser.rb
CHANGED
@@ -12,9 +12,6 @@ module Watson
|
|
12
12
|
require 'digest'
|
13
13
|
require 'pp'
|
14
14
|
|
15
|
-
# Debug printing for this class
|
16
|
-
DEBUG = false
|
17
|
-
|
18
15
|
###########################################################
|
19
16
|
# Initialize the parser with the current watson config
|
20
17
|
def initialize(config)
|
@@ -406,10 +403,15 @@ module Watson
|
|
406
403
|
'.lua' => ['--', '--[['], # Lua
|
407
404
|
'.vim' => ['"'], # VimL
|
408
405
|
'.md' => ['<!--'], # Markdown
|
409
|
-
'.html' => ['<!--']
|
406
|
+
'.html' => ['<!--'], # HTML
|
407
|
+
'.el' => [';'] # Emacslisp
|
410
408
|
}
|
411
409
|
|
412
|
-
|
410
|
+
# Merge config file type list with defaults
|
411
|
+
_ext.merge!(@config.type_list)
|
412
|
+
|
413
|
+
|
414
|
+
loop do
|
413
415
|
_mtch = filename.match(/(\.(\S+))$/)
|
414
416
|
debug_print "Extension: #{ _mtch }\n"
|
415
417
|
|
data/lib/watson/printer.rb
CHANGED
@@ -25,9 +25,6 @@ module Watson
|
|
25
25
|
# Include for debug_print (for class methods)
|
26
26
|
include Watson
|
27
27
|
|
28
|
-
# Debug printing for this class
|
29
|
-
DEBUG = false
|
30
|
-
|
31
28
|
###########################################################
|
32
29
|
# Printer initialization method to setup necessary parameters, states, and vars
|
33
30
|
def initialize(config)
|
data/lib/watson/remote.rb
CHANGED
@@ -2,9 +2,6 @@ module Watson
|
|
2
2
|
# Remote class that handles all remote HTTP calls to Bitbucket and GitHub
|
3
3
|
class Remote
|
4
4
|
|
5
|
-
# Debug printing for this class
|
6
|
-
DEBUG = false
|
7
|
-
|
8
5
|
class << self
|
9
6
|
|
10
7
|
# Include for debug_print
|
@@ -129,7 +126,7 @@ module Watson
|
|
129
126
|
def post_structure(structure, config, counter)
|
130
127
|
|
131
128
|
# Return if remote isn't valid or both github and bitbucket aren't valid
|
132
|
-
return false if !config.remote_valid || (!config.github_valid && !config.bitbucket_valid && !config.gitlab_valid)
|
129
|
+
return false if !config.remote_valid || (!config.asana_valid && !config.github_valid && !config.bitbucket_valid && !config.gitlab_valid)
|
133
130
|
formatter = Printer.new(config).build_formatter
|
134
131
|
|
135
132
|
# Parse through entire structure and post issues to remote
|
@@ -140,6 +137,7 @@ module Watson
|
|
140
137
|
Remote::GitHub.post_issue(issue, config) if config.github_valid
|
141
138
|
Remote::Bitbucket.post_issue(issue, config) if config.bitbucket_valid
|
142
139
|
Remote::GitLab.post_issue(issue, config) if config.gitlab_valid
|
140
|
+
Remote::Asana.post_issue(issue, config) if config.asana_valid
|
143
141
|
formatter.print_status "!", GREEN
|
144
142
|
print BOLD + "Remote Posting Status: #{counter += 1} / #{config.issue_count}"
|
145
143
|
print "\r"
|
data/lib/watson/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -98,6 +98,12 @@ describe Config do
|
|
98
98
|
@config.bitbucket_repo.should == ''
|
99
99
|
@config.bitbucket_issues.should == Hash.new()
|
100
100
|
|
101
|
+
@config.asana_valid.should be_false
|
102
|
+
@config.asana_api.should == ''
|
103
|
+
@config.asana_workspace.should == ''
|
104
|
+
@config.asana_project.should == ''
|
105
|
+
@config.asana_issues.should == Hash.new()
|
106
|
+
|
101
107
|
end
|
102
108
|
end
|
103
109
|
|