watson-ruby 1.4.3 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/watson/parser.rb CHANGED
@@ -59,6 +59,9 @@ module Watson
59
59
  debug_print PP.pp(_structure, '')
60
60
  debug_print "\n\n"
61
61
 
62
+ # Pass structure to poster with count as 0
63
+ Remote.post_structure(_structure, @config, 0)
64
+
62
65
  _structure
63
66
  end
64
67
 
@@ -100,23 +103,9 @@ module Watson
100
103
  # [review] - Warning to user when file is ignored? (outside of debug_print)
101
104
  # Check against ignore list, if match, set to "" which will be ignored
102
105
  @config.ignore_list.each do |_ignore|
103
- # [review] - Better "Ruby" way to check for "*"?
104
- # [review] - Probably cleaner way to perform multiple checks below
105
- # Look for *.type on list, regex to match entry
106
- if _ignore[0] == '*'
107
- _cut = _ignore[1..-1]
108
- if _entry.match(/#{ _cut }/)
109
- debug_print "#{ _entry } is on the ignore list, setting to \"\"\n"
110
- _entry = ''
111
- break
112
- end
113
- # Else check for verbose ignore match
114
- else
115
- if _entry == _ignore || File.absolute_path(_entry) == _ignore
116
- debug_print "#{ _entry } is on the ignore list, setting to \"\"\n"
117
- _entry = ''
118
- break
119
- end
106
+ if _mtch = _entry.match(_ignore)
107
+ _entry = ''
108
+ break
120
109
  end
121
110
  end
122
111
 
@@ -137,13 +126,15 @@ module Watson
137
126
 
138
127
  # Check if entry is in ignore list
139
128
  _skip = false
129
+
140
130
  @config.ignore_list.each do |_ignore|
141
- if _entry == _ignore || File.absolute_path(_entry) == _ignore
142
- debug_print "#{ _entry } is on the ignore list, setting to \"\"\n"
131
+ if mtch = _entry.match(_ignore)
143
132
  _skip = true
144
133
  end
145
134
  end
146
135
 
136
+ debug_print "#{ _entry } was not on ignorelist, adding\n"
137
+
147
138
  # If directory is on the ignore list then skip
148
139
  next if _skip == true
149
140
 
@@ -273,7 +264,13 @@ module Watson
273
264
  # Set flag for this issue_list (for file) to indicate that
274
265
  _issue_list[:has_issues] = true
275
266
 
276
- _title = _mtch[2]
267
+ # [review] - This could probably be done better, elsewhere!
268
+ # If it's a HTML comment, remove trailing -->
269
+ if _mtch[0].match(/<!--/)
270
+ _title = _mtch[2].gsub(/-->/, "")
271
+ else
272
+ _title = _mtch[2]
273
+ end
277
274
  debug_print "Issue found\n"
278
275
  debug_print "Tag: #{ _tag }\n"
279
276
  debug_print "Issue: #{ _title }\n"
@@ -339,27 +336,13 @@ module Watson
339
336
  # [review] - Keep Remote as a static method and pass config every time?
340
337
  # Or convert to a regular class and make an instance with @config
341
338
 
342
- if @config.remote_valid
343
- if @config.github_valid
344
- debug_print "GitHub is valid, posting issue\n"
345
- Remote::GitHub.post_issue(_issue, @config)
346
- else
347
- debug_print "GitHub invalid, not posting issue\n"
348
- end
349
-
350
-
351
- if @config.bitbucket_valid
352
- debug_print "Bitbucket is valid, posting issue\n"
353
- Remote::Bitbucket.post_issue(_issue, @config)
354
- else
355
- debug_print "Bitbucket invalid, not posting issue\n"
356
- end
357
- end
358
339
 
359
340
  # [review] - Use _tag string as symbol reference in hash or keep as string?
360
341
  # Look into to_sym to keep format of all _issue params the same
361
342
  _issue_list[_tag].push(_issue)
362
343
 
344
+ # Increment issue counter for posting status
345
+ @config.issue_count = @config.issue_count.next
363
346
  end
364
347
 
365
348
  # [review] - Return of parse_file is different than watson-perl
@@ -419,11 +402,12 @@ module Watson
419
402
  '.zsh' => ['#'], # Zsh
420
403
  '.clj' => [';;'], # Clojure
421
404
  '.sql' => ['---', '//', '#' ], # SQL and PL types
422
- '.lua' => ['--', '--[['] # Lua
405
+ '.lua' => ['--', '--[['], # Lua
406
+ '.html' => ['<!--'] # HTML
423
407
  }
424
408
 
425
409
  loop do
426
- _mtch = filename.match(/(\.(\w+))$/)
410
+ _mtch = filename.match(/(\.(\S+))$/)
427
411
  debug_print "Extension: #{ _mtch }\n"
428
412
 
429
413
  # Break if we don't find a match
@@ -432,7 +416,7 @@ module Watson
432
416
  return _ext[_mtch[0]] if _ext.has_key?(_mtch[0])
433
417
 
434
418
  # Can't recognize extension, keep looping in case of .bk, .#, ect
435
- filename = filename.gsub(/(\.(\w+))$/, '')
419
+ filename = filename.gsub(/(\.(\S+))$/, '')
436
420
  debug_print "Didn't recognize, searching #{ filename }\n"
437
421
 
438
422
  end
data/lib/watson/remote.rb CHANGED
@@ -19,14 +19,15 @@ module Watson
19
19
  # Default options hash for http_call
20
20
  # Will get merged with input argument hash to maintain defaults
21
21
  HTTP_opts = {
22
- :url => nil, #--> URL of endpoint [String]
23
- :ssl => false, #--> Use SSL in connection (HTTPS) (True/False]
24
- :method => nil, #--> GET or POST for respective HTTP method [String]
22
+ :url => nil, #--> URL of endpoint [String]
23
+ :ssl => false, #--> Use SSL in connection (HTTPS) (True/False]
24
+ :method => nil, #--> GET or POST for respective HTTP method [String]
25
25
  :basic_auth => Array.new(0), #--> Array of username and pw to use for basic authentication
26
- # If empty, assume no user authentication [Array]
27
- :auth => nil, #--> Authentication token [String]
28
- :data => nil, #--> Hash of data to be POST'd in HTTP request [Hash]
29
- :verbose => false #--> Turn on verbose debug for this call [True/False]
26
+ # If empty, assume no user authentication [Array]
27
+ :auth => nil, #--> Authentication token [String]
28
+ :headers => Array.new(0), #--> Array of headers, where headers are hash of key value
29
+ :data => nil, #--> Hash of data to be POST'd in HTTP request [Hash]
30
+ :verbose => false #--> Turn on verbose debug for this call [True/False]
30
31
  }
31
32
 
32
33
  ###########################################################
@@ -81,10 +82,18 @@ module Watson
81
82
 
82
83
  # Check for Authentication token key in hash to be used in header
83
84
  # I think this is pretty universal, but specifically works for GitHub
85
+ # This is standard for OAuth I think...
84
86
  if opts[:auth]
85
87
  _req["Authorization"] = "token #{ opts[:auth] }"
86
88
  end
87
89
 
90
+ # But sometimes we need we need other headers
91
+ # Set specific header (GitLab requires PRIVATE_TOKEN)
92
+ opts[:headers].each do |header|
93
+ _req["#{ header[:field] }"] = header[:value]
94
+ end
95
+
96
+
88
97
  # [review] - Add :data_format to use set_form_data vs json body?
89
98
  # For now, use Hash or Array, this is to differentiate between
90
99
  # putting post data in body vs putting it in the form
@@ -115,6 +124,38 @@ module Watson
115
124
  # return {:json => _json, :resp => _resp}
116
125
  return _json, _resp
117
126
  end
127
+
128
+
129
+ def post_structure(structure, config, counter)
130
+
131
+ # 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)
133
+ formatter = Printer.new(config).build_formatter
134
+
135
+ # Parse through entire structure and post issues to remote
136
+ structure[:files].each do |file|
137
+ config.tag_list.each do |tag|
138
+ file[tag].each do |issue|
139
+
140
+ Remote::GitHub.post_issue(issue, config) if config.github_valid
141
+ Remote::Bitbucket.post_issue(issue, config) if config.bitbucket_valid
142
+ Remote::GitLab.post_issue(issue, config) if config.gitlab_valid
143
+ formatter.print_status "!", GREEN
144
+ print BOLD + "Remote Posting Status: #{counter += 1} / #{config.issue_count}"
145
+ print "\r"
146
+ end
147
+ end
148
+ end
149
+
150
+ # Pass any dirs we find back to this structure printer and repeat
151
+ structure[:subdirs].each do |dir|
152
+ counter = Remote::post_structure(dir, config, counter)
153
+ end
154
+
155
+ # Return counter becaused FixNums are wierd
156
+ counter
157
+ end
158
+
118
159
  end
119
160
  end
120
161
  end
@@ -1,3 +1,3 @@
1
1
  module Watson
2
- VERSION = "1.4.3"
2
+ VERSION = "1.5.0"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -52,7 +52,6 @@ describe Config do
52
52
  @config.read_conf.should be_true
53
53
  @config.dir_list.should include('.')
54
54
  @config.tag_list.should include('fix', 'review', 'todo')
55
- @config.ignore_list.should include('.git', '*.swp')
56
55
 
57
56
  end
58
57
  end
@@ -92,14 +91,12 @@ describe Config do
92
91
  @config.github_valid.should be_false
93
92
  @config.github_api.should == ''
94
93
  @config.github_repo.should == ''
95
- @config.github_issues.should == {:open => Hash.new(),
96
- :closed => Hash.new() }
94
+ @config.github_issues.should == Hash.new()
97
95
 
98
96
  @config.bitbucket_valid.should be_false
99
97
  @config.bitbucket_api.should == ''
100
98
  @config.bitbucket_repo.should == ''
101
- @config.bitbucket_issues.should == {:open => Hash.new(),
102
- :closed => Hash.new() }
99
+ @config.bitbucket_issues.should == Hash.new()
103
100
 
104
101
  end
105
102
  end
@@ -107,7 +104,6 @@ describe Config do
107
104
  describe '#run' do
108
105
  it 'should populate all member vars' do
109
106
  @config.run
110
- @config.ignore_list.should include('.git', '*.swp')
111
107
  @config.tag_list.should include('fix', 'review', 'todo')
112
108
  @config.dir_list.should include('.')
113
109
  end
data/watson.gemspec CHANGED
@@ -10,13 +10,13 @@ Gem::Specification.new do |s|
10
10
 
11
11
  s.authors = ["nhmood"]
12
12
  s.email = 'nhmood@goosecode.com'
13
- s.homepage = 'http://goosecode.com/watson'
13
+ s.homepage = 'http://goosecode.com/watson'
14
14
 
15
- s.summary = "an inline issue manager"
15
+ s.summary = "an inline issue manager"
16
16
  s.description = "an inline issue manager with GitHub and Bitbucket support"
17
17
 
18
- s.license = 'MIT'
19
- s.files = `git ls-files`.split("\n").delete_if { |file| file.include?("assets/examples") }
18
+ s.license = 'MIT'
19
+ s.files = `git ls-files`.split("\n").delete_if { |file| file.include?("assets/examples") }
20
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
22
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watson-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nhmood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-06 00:00:00.000000000 Z
11
+ date: 2013-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -81,6 +81,7 @@ files:
81
81
  - lib/watson/formatters/unite_formatter.rb
82
82
  - lib/watson/fs.rb
83
83
  - lib/watson/github.rb
84
+ - lib/watson/gitlab.rb
84
85
  - lib/watson/parser.rb
85
86
  - lib/watson/printer.rb
86
87
  - lib/watson/remote.rb