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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c13ba5881255f027628ecb4d0c2b89c001e4940e
4
- data.tar.gz: 406069b4a52de7d481b5907a59bb35c8dd6abe6a
3
+ metadata.gz: da9382974aee60af64d71f1cc6a63f594330cc12
4
+ data.tar.gz: 7cb4dbb672ffa04412ae1198ac79c97f0bab6643
5
5
  SHA512:
6
- metadata.gz: 74bcaa0ac025a657062122bc02df3146cc3189b6ae579eb6ca4f52f3a5a4782076be2c30d206c308f288b2986671db0c81cd89c97b7364da761d9e20faf94af2
7
- data.tar.gz: 6098f8440287d51898970381aa1583e8186ae88fed76fd6fa0568c589d146279b835c1f6708ec427b186b999fe066c7248cb33c37c3e8ba65c7cd2606306e9f5
6
+ metadata.gz: f5646b1f3b0db3fd820369e7dcb6727d235cec7bdc5be8bcb3fb2d4656265b5611f8be47dc48603f89e8a5206a3156e972b914e6b600b5fcc0b256d8baf16a6b
7
+ data.tar.gz: 3f17083485b7efee7672483ca889ba23af2fa2811573d2834d31ba2bb5c47f28dee279c5e338627004cdfb7605efa4dc12382ec1cf4c6e132d7884c962fe6248
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- watson-ruby (1.4.3)
4
+ watson-ruby (1.5.0)
5
5
  json
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -27,8 +27,9 @@ bundle exec rake
27
27
 
28
28
 
29
29
  ## Recent Updates
30
+ - watson now supports [GitLab](http://gitlab.com)
30
31
  - [vim-unite-watson.vim](https://github.com/alpaca-tc/vim-unite-watson.vim) integrates watson right into vim!
31
- - watson now supports multiple export modes
32
+ - watson now supports multiple export modes
32
33
  - JSON output allows you to integrate watson parse data into your own apps
33
34
  - Silent output allows you to use watson without a printout; tie it to git hooks for streamlined issue posting
34
35
 
@@ -50,6 +51,11 @@ submit a pull request (comment parsing happens in **lib/watson/paser.rb**)
50
51
  - **Go**
51
52
  - **Scala**
52
53
  - **Erlang**
54
+ - **Fortran**
55
+ - **SQL / PL**
56
+ - **Lua**
57
+ - **HTML**
58
+ - **SASS SCSS**
53
59
  - **Haskell**
54
60
  - **Bash / Zsh**
55
61
  - **Ruby**
@@ -58,24 +64,30 @@ submit a pull request (comment parsing happens in **lib/watson/paser.rb**)
58
64
  - **Coffeescript**
59
65
  - **Clojure**
60
66
 
67
+
61
68
  ## Command line arguments
62
69
  ```
63
70
  Usage: watson [OPTION]...
64
71
  Running watson with no arguments will parse with settings in RC file
65
72
  If no RC file exists, default RC file will be created
66
73
 
67
- -c, --context-depth number of lines of context to provide with posted issue
74
+ -c, --context-depth lines of context to provide with posted issue
68
75
  -d, --dirs list of directories to search in
69
76
  -f, --files list of files to search in
70
- --format set output format for watson [print, json, unite, silent]
77
+ --format set output format for watson
78
+ [print, json, unite, silent]
71
79
  -h, --help print help
72
80
  -i, --ignore list of files, directories, or types to ignore
73
81
  -p, --parse-depth depth to recursively parse directories
74
- -r, --remote list / create tokens for Bitbucket/GitHub
82
+ -r, --remote list / create tokens for remote posting
83
+ [github, bitbucket, gitlab]
84
+ -s, --show filter results (files listed) based on issue status
85
+ [all, clean, dirty]
75
86
  -t, --tags list of tags to search for
76
87
  -u, --update update remote repos with current issues
77
88
  -v, --version print watson version and info
78
89
 
90
+
79
91
  Any number of files, tags, dirs, and ignores can be listed after flag
80
92
  Ignored files should be space separated
81
93
  To use *.filetype identifier, encapsulate in "" to avoid shell substitutions
@@ -116,8 +128,8 @@ If passed with `unite`, the output will be compatible with the unite.vim plugin
116
128
 
117
129
  If passed with `silent`, watson will have no output.
118
130
 
119
- - This particular option is useful if remote posting to GitHub or Bitbucket is desired without the visual component of watson.
120
- - For example, you could set up a **git commit hook** to post issues to GitHub/Bitbucket, but avoid the giant print out every time.
131
+ - This particular option is useful if remote posting to GitHub, Bitbucket, or GitLab is desired without the visual component of watson.
132
+ - For example, you could set up a **git commit hook** to post issues to GitHub/Bitbucket/GitLab, but avoid the giant print out every time.
121
133
 
122
134
 
123
135
  ### -h, --help
@@ -137,10 +149,10 @@ If individual directories are passed with the -d (--dirs) flag, each will be par
137
149
  If watson is run without this parameter, the parsing depth is unlimited and will search through all subdirectories found.
138
150
 
139
151
 
140
- ### -r, --remote [GITHUB, BITBUCKET]
152
+ ### -r, --remote [GITHUB, BITBUCKET, GITLAB]
141
153
  This parameter is used to both list currently established remotes as well as setup new ones.
142
154
  If passed without any options, the currently established remotes will be listed.
143
- If passed with a github or bitbucket argument, watson will proceed to ask some questions to set up the corresponding remote.
155
+ If passed with a github, bitbucket, gitlab argument, watson will proceed to ask some questions to set up the corresponding remote.
144
156
 
145
157
 
146
158
  ### -s, --show [ALL, CLEAN, DIRTY]
@@ -158,7 +170,7 @@ The tag currently supports any regular character and number combination, no spec
158
170
 
159
171
  ### -u, --update
160
172
  This parameter is used to update remote repos with new issues.
161
- watson **does not** post new issues by default therefore this parameter is required to push up to GitHub/Bitbucket.
173
+ watson **does not** post new issues by default therefore this parameter is required to push up to GitHub/Bitbucket/GitLab.
162
174
  watson **does** pull issue status by default, therefore you will always be notified of resolved issues on GitHub/Bitbucket.
163
175
 
164
176
  ### -v, --version
@@ -181,10 +193,12 @@ This supports wildcard type selecting by providing .filename (no * required)
181
193
 
182
194
  **[context_depth]** - This value determines how many lines of context should be grabbed for each issue when posting to a remote.
183
195
 
184
- **[(github/bitbucket)]** - If a remote is established, the API key for the corresponding remote is stored here.
196
+ **[(github/bitbucket/gitlab)_api]** - If a remote is established, the API key for the corresponding remote is stored here.
185
197
  Currently, OAuth has yet to be implemented for Bitbucket so the Bitbucket username is stored here.
186
198
 
187
- **[(github/bitbucket)_repo]** - The repo name / path is stored here.
199
+ **[(github/bitbucket/gitlab)_repo]** - The repo name / path is stored here.
200
+
201
+ **[(github/gitlab)_endpoint]** - The endpoint in case of GitHub Enterprise of GitLab configuration.
188
202
 
189
203
  The remote related .watsonrc options shouldn't need to be edited manually, as they are automatically populated when the -r, --remote setup is called.
190
204
 
@@ -208,6 +222,9 @@ Special thanks to [@eugenekolo](http://twitter.com/eugenekolo) [[email](eugenek@
208
222
  Special thanks to [@crowell](http://github.com/crowell) for testing out watson-ruby!
209
223
 
210
224
  ## FAQ
225
+ - ** Will inline issues get deleted if I close them on GitHub/Bitbucket/GitLab?**
226
+ No, watson won't touch your source code, it will only inform you that issues have been closed remotely.
227
+
211
228
  - **Why Ruby?**
212
229
  I wanted to learn Ruby and this seemed like a pretty decent project.
213
230
 
data/lib/watson.rb CHANGED
@@ -7,6 +7,7 @@ require_relative 'watson/formatters'
7
7
  require_relative 'watson/remote'
8
8
  require_relative 'watson/github'
9
9
  require_relative 'watson/bitbucket'
10
+ require_relative 'watson/gitlab'
10
11
  require_relative 'watson/version'
11
12
 
12
13
  module Watson
@@ -116,12 +116,13 @@ module Watson
116
116
  # Create options hash to pass to Remote::http_call
117
117
  # Endpoint for accessing Repo as User with SSL
118
118
  # Basic auth with user input
119
- opts = {:url => "https://bitbucket.org/api/1.0/repositories/#{_owner}/#{_repo}",
120
- :ssl => true,
121
- :method => "GET",
122
- :basic_auth => [_username, _password],
123
- :verbose => false
124
- }
119
+ opts = {
120
+ :url => "https://bitbucket.org/api/1.0/repositories/#{_owner}/#{_repo}",
121
+ :ssl => true,
122
+ :method => "GET",
123
+ :basic_auth => [_username, _password],
124
+ :verbose => false
125
+ }
125
126
 
126
127
  _json, _resp = Watson::Remote.http_call(opts)
127
128
 
@@ -208,12 +209,13 @@ module Watson
208
209
  # Get all open tickets (anything but resolved)
209
210
  # Create options hash to pass to Remote::http_call
210
211
  # Issues URL for Bitbucket + SSL
211
- opts = {:url => "https://bitbucket.org/api/1.0/repositories/#{ config.bitbucket_repo }/issues?status=!resolved",
212
- :ssl => true,
213
- :method => "GET",
214
- :basic_auth => [config.bitbucket_api, config.bitbucket_pw],
215
- :verbose => false
216
- }
212
+ opts = {
213
+ :url => "https://bitbucket.org/api/1.0/repositories/#{ config.bitbucket_repo }/issues",
214
+ :ssl => true,
215
+ :method => "GET",
216
+ :basic_auth => [config.bitbucket_api, config.bitbucket_pw],
217
+ :verbose => false
218
+ }
217
219
 
218
220
  _json, _resp = Watson::Remote.http_call(opts)
219
221
 
@@ -232,38 +234,23 @@ module Watson
232
234
  end
233
235
 
234
236
 
237
+ # Create hash entry from each returned issue
238
+ # MD5 of issue serves as hash key
239
+ # Hash value is another hash of info we will use
240
+ _json["issues"].each do |issue|
235
241
 
236
- config.bitbucket_issues[:open] = _json["issues"].empty? ? Hash.new : _json["issues"]
237
- config.bitbucket_valid = true
238
-
239
- # Get all closed tickets
240
- # Create options hash to pass to Remote::http_call
241
- # Issues URL for Bitbucket + SSL
242
- opts = {:url => "https://bitbucket.org/api/1.0/repositories/#{ config.bitbucket_repo }/issues?status=resolved",
243
- :ssl => true,
244
- :method => "GET",
245
- :basic_auth => [config.bitbucket_api, config.bitbucket_pw],
246
- :verbose => false
247
- }
248
-
249
- _json, _resp = Watson::Remote.http_call(opts)
250
-
251
- # Check response to validate repo access
252
- # Shouldn't be necessary if we passed the last check but just to be safe
253
- if _resp.code != "200"
254
- formatter.print_status "x", RED
255
- print BOLD + "Unable to get closed issues.\n" + RESET
256
- print " Since the open issues were obtained, something is probably wrong and you should file a bug report or something...\n"
257
- print " Status: #{ _resp.code } - #{ _resp.message }\n"
242
+ # Skip this issue if it doesn't have watson md5 tag
243
+ next if (_md5 = issue["content"].match(/__md5__ : (\w+)/)).nil?
258
244
 
259
- debug_print "Bitbucket invalid, setting config var\n"
260
- config.bitbucket_valid = false
261
- return false
245
+ # If it does, use md5 as hash key and populate values with our info
246
+ config.bitbucket_issues[_md5[1]] = {
247
+ :title => issue["title"],
248
+ :id => issue["local_id"],
249
+ :state => issue["status"]
250
+ }
262
251
  end
263
252
 
264
- config.bitbucket_issues[:closed] = _json["issues"].empty? ? Hash.new : _json["issues"]
265
253
  config.bitbucket_valid = true
266
- return true
267
254
  end
268
255
 
269
256
 
@@ -288,29 +275,10 @@ module Watson
288
275
  return false
289
276
  end
290
277
 
291
- # Check that issue hasn't been posted already by comparing md5s
292
- # Go through all open issues, if there is a match in md5, return out of method
293
- # [todo] - Play with idea of making body of GitHub issue hash format to be exec'd
294
- # Store pieces in text as :md5 => "whatever" so when we get issues we can
295
- # call exec and turn it into a real hash for parsing in watson
296
- # Makes watson code cleaner but not as readable comment on GitHub...?
297
- debug_print "Checking open issues to see if already posted\n"
298
- config.bitbucket_issues[:open].each do | _open |
299
- if _open["content"].include?(issue[:md5])
300
- debug_print "Found in #{ _open["title"] }, not posting\n"
301
- return false
302
- end
303
- debug_print "Did not find in #{_open["title"]}\n"
304
- end
305
278
 
306
- debug_print "Checking closed issues to see if already posted\n"
307
- config.bitbucket_issues[:closed].each do | _closed |
308
- if _closed["content"].include?(issue[:md5])
309
- debug_print "Found in #{ _closed["title"] }, not posting\n"
310
- return false
311
- end
312
- debug_print "Did not find in #{ _closed["title"] }\n"
313
- end
279
+ # If issue exists in list we already obtained, skip posting
280
+ return false if config.bitbucket_issues.key?(issue[:md5])
281
+ debug_print "#{issue[:md5]} not found in remote issues, posting\n"
314
282
 
315
283
 
316
284
  # If we haven't obtained the pw from user yet, do it
@@ -342,7 +310,8 @@ module Watson
342
310
 
343
311
  # Create the body text for the issue here, too long to fit nicely into opts hash
344
312
  # [review] - Only give relative path for privacy when posted
345
- _body = "__filename__ : #{ issue[:path] } \n" +
313
+ _body =
314
+ "__filename__ : #{ issue[:path] } \n" +
346
315
  "__line #__ : #{ issue[:line_number] } \n" +
347
316
  "__tag__ : #{ issue[:tag] } \n" +
348
317
  "__md5__ : #{ issue[:md5] } \n\n" +
@@ -351,14 +320,15 @@ module Watson
351
320
  # Create option hash to pass to Remote::http_call
352
321
  # Issues URL for GitHub + SSL
353
322
  # No tag or label concept in Bitbucket unfortunately :(
354
- opts = {:url => "https://bitbucket.org/api/1.0/repositories/#{ config.bitbucket_repo }/issues",
355
- :ssl => true,
356
- :method => "POST",
357
- :basic_auth => [config.bitbucket_api, config.bitbucket_pw],
358
- :data => [{"title" => issue[:title] + " [#{ issue[:path] }]",
359
- "content" => _body }],
360
- :verbose => false
361
- }
323
+ opts = {
324
+ :url => "https://bitbucket.org/api/1.0/repositories/#{ config.bitbucket_repo }/issues",
325
+ :ssl => true,
326
+ :method => "POST",
327
+ :basic_auth => [config.bitbucket_api, config.bitbucket_pw],
328
+ :data => [{"title" => issue[:title] + " [#{ issue[:path] }]",
329
+ "content" => _body }],
330
+ :verbose => false
331
+ }
362
332
 
363
333
  _json, _resp = Watson::Remote.http_call(opts)
364
334
 
@@ -373,6 +343,14 @@ module Watson
373
343
  return false
374
344
  end
375
345
 
346
+
347
+ # Parse response and append issue hash so we are up to date
348
+ config.bitbucket_issues[issue[:md5]] = {
349
+ :title => _json["title"],
350
+ :id => _json["local_id"],
351
+ :state => _json["state"]
352
+ }
353
+
376
354
  return true
377
355
  end
378
356
 
@@ -356,6 +356,7 @@ module Watson
356
356
  # For each argument passed, add to @config.ignore_list
357
357
  args.each do | _ignore |
358
358
  debug_print "Adding #{ _ignore } to config ignore_list\n"
359
+ _ignore = Regexp.escape(_ignore).gsub(/\\\*/, ".+")
359
360
  @config.ignore_list.push(_ignore)
360
361
  end
361
362
 
@@ -455,6 +456,11 @@ module Watson
455
456
  print BOLD + "Bitbucket Repo : " + RESET + "#{ @config.bitbucket_repo }\n\n" + RESET
456
457
  end
457
458
 
459
+ if !@config.gitlab_api.empty?
460
+ print BOLD + "GitLab User : " + RESET + "#{ @config.gitlab_api }\n" + RESET
461
+ print BOLD + "GitLab Repo : " + RESET + "#{ @config.gitlab_repo }\n\n" + RESET
462
+ end
463
+
458
464
  # If github or bitbucket passed, setup
459
465
  # If just -r (0 args) do nothing and only have above printed
460
466
  # If more than 1 arg is passed, unrecognized, warn user
@@ -467,6 +473,11 @@ module Watson
467
473
  when "bitbucket"
468
474
  debug_print "Bitbucket setup called from CL\n"
469
475
  Watson::Remote::Bitbucket.setup(@config)
476
+
477
+ when "gitlab"
478
+ debug_print "GitLab setup called from CL\n"
479
+ Watson::Remote::GitLab.setup(@config)
480
+
470
481
  end
471
482
  elsif args.length > 1
472
483
  formatter.print_status "x", RED
data/lib/watson/config.rb CHANGED
@@ -41,6 +41,9 @@ module Watson
41
41
  # Flag for where the temp file for printing is located
42
42
  attr_reader :tmp_file
43
43
 
44
+ # Count of number of issues found
45
+ attr_accessor :issue_count
46
+
44
47
  # Flag for whether remote access is avaliable
45
48
  attr_accessor :remote_valid
46
49
 
@@ -66,6 +69,19 @@ module Watson
66
69
  attr_accessor :bitbucket_repo
67
70
  # Hash to hold list of all Bitbucket issues associated with repo
68
71
  attr_accessor :bitbucket_issues
72
+
73
+
74
+ # Flag for whether GitLab access is avaliable
75
+ attr_accessor :gitlab_valid
76
+ # GitLab API key generated from Remote::GitHub setup
77
+ attr_accessor :gitlab_api
78
+ # GitLab Endpoint (for GitHub Enterprise)
79
+ attr_accessor :gitlab_endpoint
80
+ # GitLab repo associated with current directory + watson config
81
+ attr_accessor :gitlab_repo
82
+ # Hash to hold list of all GitLab issues associated with repo
83
+ attr_accessor :gitlab_issues
84
+
69
85
  # Formatter
70
86
  attr_accessor :output_format
71
87
 
@@ -103,6 +119,7 @@ module Watson
103
119
  @dir_list = Array.new()
104
120
  @file_list = Array.new()
105
121
  @tag_list = Array.new()
122
+ @issue_count = 0
106
123
 
107
124
  # Remote options
108
125
  @remote_valid = false
@@ -111,18 +128,26 @@ module Watson
111
128
  @github_api = ""
112
129
  @github_endpoint = ""
113
130
  @github_repo = ""
114
- @github_issues = {:open => Hash.new(),
115
- :closed => Hash.new()
116
- }
131
+ @github_issues = Hash.new()
132
+
133
+
117
134
 
118
135
  # Keep API param (and put username there) for OAuth update later
119
136
  @bitbucket_valid = false
120
137
  @bitbucket_api = ""
121
138
  @bitbucket_pw = ""
122
139
  @bitbucket_repo = ""
123
- @bitbucket_issues = {:open => Hash.new(),
124
- :closed => Hash.new()
125
- }
140
+ @bitbucket_issues = Hash.new()
141
+
142
+
143
+ @gitlab_valid = false
144
+ @gitlab_api = ""
145
+ @gitlab_endpoint = ""
146
+ @gitlab_repo = ""
147
+ @gitlab_issues = Hash.new()
148
+
149
+
150
+
126
151
  @output_format = Watson::Formatters::DefaultFormatter
127
152
  end
128
153
 
@@ -138,6 +163,8 @@ module Watson
138
163
  exit if check_conf == false
139
164
  read_conf
140
165
 
166
+
167
+ # [review] - Theres gotta be a magic ruby way to trim this down
141
168
  unless @github_api.empty? && @github_repo.empty?
142
169
  Remote::GitHub.get_issues(self)
143
170
  end
@@ -145,6 +172,10 @@ module Watson
145
172
  unless @bitbucket_api.empty? && @bitbucket_repo.empty?
146
173
  Remote::Bitbucket.get_issues(self)
147
174
  end
175
+
176
+ unless @gitlab_api.empty? && @gitlab_repo.empty?
177
+ Remote::GitLab.get_issues(self)
178
+ end
148
179
  end
149
180
 
150
181
 
@@ -239,9 +270,9 @@ module Watson
239
270
  # [review] - Keep *.swp in there?
240
271
  # [todo] - Add conditional to @rc_file such that if passed by -f we accept it
241
272
  # [todo] - Add current file (watson) to avoid accidentally printing app tags
242
- @ignore_list.push("..")
243
- @ignore_list.push(@rc_file)
244
- @ignore_list.push(@tmp_file)
273
+ @ignore_list.push(Regexp.escape(".."))
274
+ @ignore_list.push(Regexp.escape(@rc_file))
275
+ @ignore_list.push(Regexp.escape(@tmp_file))
245
276
 
246
277
  # Open and read rc
247
278
  # [review] - Not sure if explicit file close is required here
@@ -348,11 +379,12 @@ module Watson
348
379
  next
349
380
  end
350
381
 
351
- # Same as previous for ignores (regex same as dirs)
352
- # Don't eliminate trailing / because not sure if dir can have
353
- # same name as file (Linux it can't, but not sure about Win/Mac)
354
- # [review] - Can Win/Mac have dir + file with same name in same dir?
355
- _mtch = _line.match(/^(\*?)((\w+)?\.?\/?)+/)[0]
382
+ # Convert each ignore into a regex
383
+ # Grab ignore and remove leading ./ and trailing /
384
+ _mtch = _line.match(/^(\.\/)?(\S+)/)[0].gsub(/\/$/, '')
385
+
386
+ # Escape all characters then replace \* with \.+
387
+ _mtch = Regexp.escape(_mtch).gsub(/\\\*/, ".+")
356
388
  if !_mtch.empty?
357
389
  @ignore_list.push(_mtch)
358
390
  debug_print "#{ _mtch } added to @ignore_list\n"
@@ -384,12 +416,30 @@ module Watson
384
416
  @bitbucket_api = _line.chomp!
385
417
  debug_print "Bitbucket API: #{ @bitbucket_api }\n"
386
418
 
419
+ when "bitbucket_pw"
420
+ # Same as GitHub parse above
421
+ @bitbucket_pw = _line.chomp!
422
+ debug_print "Bitbucket PW: #{ @bitbucket_pw }\n"
387
423
 
388
424
  when "bitbucket_repo"
389
425
  # Same as GitHub repo parse above
390
426
  @bitbucket_repo = _line.chomp!
391
427
  debug_print "Bitbucket Repo: #{ @bitbucket_repo }\n"
392
428
 
429
+ when "gitlab_api"
430
+ # Same as GitHub
431
+ @gitlab_api = _line.chomp!
432
+ debug_print "GitLab API: #{ @gitlab_api }\n"
433
+
434
+ when "gitlab_endpoint"
435
+ # Same as GitHub
436
+ @gitlab_endpoint = _line.chomp!
437
+ debug_print "GitLab Endpoint #{ @gitlab_endpoint }\n"
438
+
439
+ when "gitlab_repo"
440
+ # Same as GitHub
441
+ @gitlab_repo = _line.chomp!
442
+ debug_print "GitLab Repo: #{ @gitlab_repo }\n"
393
443
 
394
444
  else
395
445
  debug_print "Unknown tag found #{_section}\n"