watson-ruby 1.1.3 → 1.2.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/bin/watson +7 -14
- data/lib/watson/config.rb +18 -9
- data/lib/watson/github.rb +72 -47
- data/lib/watson/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6526764e5a9d056f1e208763be9871e9097c7848
|
4
|
+
data.tar.gz: 13b5605c8e07c6e05ce2b035180c5327a115cbb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 385b0d1fc3a4398fa63671ef1e96ac497c2e81924e2d6b8877b1df36bbea08b6e8bfca3edd2c3860a894d970deddd9cf18d51bfa2faf3b237ff569e192c2e70b
|
7
|
+
data.tar.gz: ba4a0830d8b1600da0b0506da9cedef1effb4c0cde820cc67d9b3e2261dc42a30c557201aed2a6b0df1e934c321c727da7d23f4c8d86de49661eee40f4870ddf
|
data/Gemfile.lock
CHANGED
data/bin/watson
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# coding: utf-8
|
3
|
-
|
4
|
-
# [review] - Using own funky path loading because traditional way seems wrong?
|
5
|
-
# Commented out version is traditional, seen in many apps. If you use that and
|
6
|
-
# look at load_path you get path/../lib (I'd expect those to be separate?)
|
7
|
-
# My funky version adds path/., path/bin, path/assets separately
|
8
|
-
# Maybe I don't get how the load path is supposed to look though...
|
9
|
-
|
10
|
-
#$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
11
|
-
$:.unshift *%w[. assets lib].map { |m| __dir__.gsub(/\/bin(.?)+/, '') + '/' + m }
|
12
|
-
#p($:)
|
13
|
-
|
14
|
-
|
15
|
-
require 'watson'
|
16
2
|
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
begin
|
5
|
+
require 'watson'
|
6
|
+
rescue LoadError
|
7
|
+
$LOAD_PATH << lib
|
8
|
+
require 'watson'
|
9
|
+
end
|
17
10
|
|
18
11
|
Watson::Command.execute(*ARGV)
|
data/lib/watson/config.rb
CHANGED
@@ -48,6 +48,8 @@ module Watson
|
|
48
48
|
attr_accessor :github_valid
|
49
49
|
# GitHub API key generated from Remote::GitHub setup
|
50
50
|
attr_accessor :github_api
|
51
|
+
# GitHub Endpoint (for GitHub Enterprise)
|
52
|
+
attr_accessor :github_endpoint
|
51
53
|
# GitHub repo associated with current directory + watson config
|
52
54
|
attr_accessor :github_repo
|
53
55
|
# Hash to hold list of all GitHub issues associated with repo
|
@@ -104,21 +106,22 @@ module Watson
|
|
104
106
|
# Remote options
|
105
107
|
@remote_valid = false
|
106
108
|
|
107
|
-
@github_valid
|
108
|
-
@github_api
|
109
|
-
@
|
110
|
-
@
|
111
|
-
|
112
|
-
|
109
|
+
@github_valid = false
|
110
|
+
@github_api = ""
|
111
|
+
@github_endpoint = ""
|
112
|
+
@github_repo = ""
|
113
|
+
@github_issues = {:open => Hash.new(),
|
114
|
+
:closed => Hash.new()
|
115
|
+
}
|
113
116
|
|
114
117
|
# Keep API param (and put username there) for OAuth update later
|
115
118
|
@bitbucket_valid = false
|
116
119
|
@bitbucket_api = ""
|
117
120
|
@bitbucket_pw = ""
|
118
121
|
@bitbucket_repo = ""
|
119
|
-
@bitbucket_issues
|
120
|
-
|
121
|
-
|
122
|
+
@bitbucket_issues = {:open => Hash.new(),
|
123
|
+
:closed => Hash.new()
|
124
|
+
}
|
122
125
|
end
|
123
126
|
|
124
127
|
|
@@ -362,6 +365,12 @@ module Watson
|
|
362
365
|
debug_print "GitHub API: #{ @github_api }\n"
|
363
366
|
|
364
367
|
|
368
|
+
when "github_endpoint"
|
369
|
+
# Same as above
|
370
|
+
@github_endpoint = _line.chomp!
|
371
|
+
debug_print "GitHub Endpoint #{ @github_endpoint }\n"
|
372
|
+
|
373
|
+
|
365
374
|
when "github_repo"
|
366
375
|
# Same as above
|
367
376
|
@github_repo = _line.chomp!
|
data/lib/watson/github.rb
CHANGED
@@ -31,7 +31,7 @@ module Watson
|
|
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
|
-
unless config.github_api.empty? && config.github_repo.empty?
|
34
|
+
unless config.github_api.empty? && config.github_repo.empty? && config.github_endpoint.empty?
|
35
35
|
Printer.print_status "!", RED
|
36
36
|
print BOLD + "Previous GitHub API + Repo is in RC, are you sure you want to overwrite?\n" + RESET
|
37
37
|
print " (Y)es/(N)o: "
|
@@ -39,18 +39,39 @@ module Watson
|
|
39
39
|
# Get user input
|
40
40
|
_overwrite = $stdin.gets.chomp
|
41
41
|
if ["no", "n"].include?(_overwrite.downcase)
|
42
|
-
print "\n"
|
42
|
+
print "\n\n"
|
43
43
|
Printer.print_status "x", RED
|
44
44
|
print BOLD + "Not overwriting current GitHub API + repo info\n" + RESET
|
45
45
|
return false
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
print "\n\n"
|
49
50
|
|
50
51
|
Printer.print_status "!", YELLOW
|
51
52
|
print BOLD + "Access to your GitHub account required to make/update issues\n" + RESET
|
52
53
|
print " See help or README for more details on GitHub/Bitbucket access\n\n"
|
53
54
|
|
55
|
+
Printer.print_status "!", GREEN
|
56
|
+
print BOLD + "Is this a GitHub Enterprise account?\n" + RESET
|
57
|
+
print " (Y)es/(N)o: "
|
58
|
+
|
59
|
+
# Get user input
|
60
|
+
_enterprise = $stdin.gets.chomp
|
61
|
+
if ["yes", "y"].include?(_enterprise.downcase)
|
62
|
+
print "\n\n"
|
63
|
+
print BOLD + "GitHub API Endpoint: " + RESET
|
64
|
+
_endpoint = $stdin.gets.chomp.chomp('/')
|
65
|
+
if _endpoint.empty?
|
66
|
+
Printer.print_status "x", RED
|
67
|
+
print BOLD + "Input blank. Please enter your API endpoint!\n\n" + RESET
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
else
|
71
|
+
_endpoint = ''
|
72
|
+
end
|
73
|
+
|
74
|
+
print "\n"
|
54
75
|
|
55
76
|
# [todo] - Don't just check for blank password but invalid as well
|
56
77
|
# Poor mans username/password grabbing
|
@@ -75,6 +96,8 @@ module Watson
|
|
75
96
|
return false
|
76
97
|
end
|
77
98
|
|
99
|
+
_endpoint = "https://api.github.com" if _endpoint.empty?
|
100
|
+
|
78
101
|
# HTTP Request to get OAuth Token
|
79
102
|
# GitHub API v3 - http://developer.github.com/v3/
|
80
103
|
|
@@ -82,15 +105,15 @@ module Watson
|
|
82
105
|
# Auth URL for GitHub + SSL
|
83
106
|
# Repo scope + notes for watson
|
84
107
|
# Basic auth with user input
|
85
|
-
opts = {:url => "
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
108
|
+
opts = {:url => "#{ _endpoint }/authorizations",
|
109
|
+
:ssl => true,
|
110
|
+
:method => "POST",
|
111
|
+
:basic_auth => [_username, _password],
|
112
|
+
:data => {"scopes" => ["repo"],
|
113
|
+
"note" => "watson",
|
114
|
+
"note_url" => "http://watson.goosecode.com/" },
|
115
|
+
:verbose => false
|
116
|
+
}
|
94
117
|
|
95
118
|
_json, _resp = Watson::Remote.http_call(opts)
|
96
119
|
|
@@ -105,9 +128,11 @@ module Watson
|
|
105
128
|
return false
|
106
129
|
end
|
107
130
|
|
108
|
-
# Store API key obtained from POST to @config.github_api
|
131
|
+
# Store endpoint and API key obtained from POST to @config.github_api
|
132
|
+
config.github_endpoint = _endpoint
|
109
133
|
config.github_api = _json["token"]
|
110
|
-
debug_print "Config GitHub API
|
134
|
+
debug_print "Config GitHub API Endpoint updated to: #{ config.github_endpoint }\n"
|
135
|
+
debug_print "Config GitHub API Key updated to: #{ config.github_api }\n"
|
111
136
|
|
112
137
|
|
113
138
|
# Get repo information, if blank give error
|
@@ -144,14 +169,14 @@ module Watson
|
|
144
169
|
# Label URL for GitHub + SSL
|
145
170
|
#
|
146
171
|
# Auth token
|
147
|
-
opts = {:url => "
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
172
|
+
opts = {:url => "#{ _endpoint }/repos/#{ _owner }/#{ _repo }/labels",
|
173
|
+
:ssl => true,
|
174
|
+
:method => "POST",
|
175
|
+
:auth => config.github_api,
|
176
|
+
:data => {"name" => "watson",
|
177
|
+
"color" => "00AEEF" },
|
178
|
+
:verbose => false
|
179
|
+
}
|
155
180
|
|
156
181
|
_json, _resp = Watson::Remote.http_call(opts)
|
157
182
|
|
@@ -195,14 +220,14 @@ module Watson
|
|
195
220
|
# All setup has been completed, need to update RC
|
196
221
|
# Call config updater/writer from @config to write config
|
197
222
|
debug_print "Updating config with new GitHub info\n"
|
198
|
-
config.update_conf("github_api", "github_repo")
|
223
|
+
config.update_conf("github_api", "github_repo", "github_endpoint")
|
199
224
|
|
200
225
|
# Give user some info
|
201
226
|
print "\n"
|
202
227
|
Printer.print_status "o", GREEN
|
203
228
|
print BOLD + "GitHub successfully setup\n" + RESET
|
204
229
|
print " Issues will now automatically be retrieved from GitHub by default\n"
|
205
|
-
print " Use -
|
230
|
+
print " Use -u, --update to post issues to GitHub\n"
|
206
231
|
print " See help or README for more details on GitHub/Bitbucket access\n\n"
|
207
232
|
|
208
233
|
return true
|
@@ -228,12 +253,12 @@ module Watson
|
|
228
253
|
# Get all open tickets
|
229
254
|
# Create options hash to pass to Remote::http_call
|
230
255
|
# Issues URL for GitHub + SSL
|
231
|
-
opts = {:url => "
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
256
|
+
opts = {:url => "#{ config.github_endpoint }/repos/#{ config.github_repo }/issues?labels=watson&state=open",
|
257
|
+
:ssl => true,
|
258
|
+
:method => "GET",
|
259
|
+
:auth => config.github_api,
|
260
|
+
:verbose => false
|
261
|
+
}
|
237
262
|
|
238
263
|
_json, _resp = Watson::Remote.http_call(opts)
|
239
264
|
|
@@ -256,11 +281,11 @@ module Watson
|
|
256
281
|
# Get all closed tickets
|
257
282
|
# Create option hash to pass to Remote::http_call
|
258
283
|
# Issues URL for GitHub + SSL
|
259
|
-
opts = {:url => "
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
284
|
+
opts = {:url => "#{ config.github_endpoint }/repos/#{ config.github_repo }/issues?labels=watson&state=closed",
|
285
|
+
:ssl => true,
|
286
|
+
:method => "GET",
|
287
|
+
:auth => config.github_api,
|
288
|
+
:verbose => false
|
264
289
|
}
|
265
290
|
|
266
291
|
_json, _resp = Watson::Remote.http_call(opts)
|
@@ -330,22 +355,22 @@ module Watson
|
|
330
355
|
# Create the body text for the issue here, too long to fit nicely into opts hash
|
331
356
|
# [review] - Only give relative path for privacy when posted
|
332
357
|
_body = "__filename__ : #{ issue[:path] }\n" +
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
358
|
+
"__line #__ : #{ issue[:line_number] }\n" +
|
359
|
+
"__tag__ : #{ issue[:tag] }\n" +
|
360
|
+
"__md5__ : #{ issue[:md5] }\n\n" +
|
361
|
+
"#{ issue[:context].join }\n"
|
337
362
|
|
338
363
|
# Create option hash to pass to Remote::http_call
|
339
364
|
# Issues URL for GitHub + SSL
|
340
|
-
opts = {:url => "
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
365
|
+
opts = {:url => "#{ config.github_endpoint }/repos/#{ config.github_repo }/issues",
|
366
|
+
:ssl => true,
|
367
|
+
:method => "POST",
|
368
|
+
:auth => config.github_api,
|
369
|
+
:data => { "title" => issue[:title] + " [#{ issue[:path] }]",
|
370
|
+
"labels" => [issue[:tag], "watson"],
|
371
|
+
"body" => _body },
|
372
|
+
:verbose => false
|
373
|
+
}
|
349
374
|
|
350
375
|
_json, _resp = Watson::Remote.http_call(opts)
|
351
376
|
|
data/lib/watson/version.rb
CHANGED
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
|
+
version: 1.2.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-11-
|
11
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|