hub 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of hub might be problematic. Click here for more details.
- data/lib/hub/commands.rb +34 -11
- data/lib/hub/json.rb +57 -36
- data/lib/hub/version.rb +1 -1
- metadata +2 -2
data/lib/hub/commands.rb
CHANGED
@@ -937,6 +937,20 @@ help
|
|
937
937
|
req = Net::HTTP.const_get(type).new(url.request_uri)
|
938
938
|
req.basic_auth "#{user}/token", token if user and token
|
939
939
|
|
940
|
+
http = setup_http(url)
|
941
|
+
|
942
|
+
yield req if block_given?
|
943
|
+
http.start { http.request(req) }
|
944
|
+
end
|
945
|
+
|
946
|
+
def http_post(url, params = nil)
|
947
|
+
http_request(url, :Post) do |req|
|
948
|
+
req.set_form_data params if params
|
949
|
+
req['Content-Length'] = req.body ? req.body.length : 0
|
950
|
+
end
|
951
|
+
end
|
952
|
+
|
953
|
+
def setup_http(url)
|
940
954
|
port = url.port
|
941
955
|
if use_ssl = 'https' == url.scheme and not use_ssl?
|
942
956
|
# ruby compiled without openssl
|
@@ -944,21 +958,22 @@ help
|
|
944
958
|
port = 80
|
945
959
|
end
|
946
960
|
|
947
|
-
|
948
|
-
if
|
949
|
-
|
950
|
-
|
961
|
+
http_args = [url.host, port]
|
962
|
+
if proxy = proxy_url(use_ssl)
|
963
|
+
http_args.concat proxy.select(:host, :port)
|
964
|
+
if proxy.userinfo
|
965
|
+
require 'cgi'
|
966
|
+
http_args.concat proxy.userinfo.split(':', 2).map {|a| CGI.unescape a }
|
967
|
+
end
|
951
968
|
end
|
952
969
|
|
953
|
-
|
954
|
-
http.start { http.request(req) }
|
955
|
-
end
|
970
|
+
http = Net::HTTP.new(*http_args)
|
956
971
|
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
req['Content-Length'] = req.body ? req.body.length : 0
|
972
|
+
if http.use_ssl = use_ssl
|
973
|
+
# TODO: SSL peer verification
|
974
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
961
975
|
end
|
976
|
+
return http
|
962
977
|
end
|
963
978
|
|
964
979
|
def load_net_http
|
@@ -971,6 +986,14 @@ help
|
|
971
986
|
defined? ::OpenSSL
|
972
987
|
end
|
973
988
|
|
989
|
+
def proxy_url(use_ssl)
|
990
|
+
env_name = "HTTP#{use_ssl ? 'S' : ''}_PROXY"
|
991
|
+
if proxy = ENV[env_name] || ENV[env_name.downcase]
|
992
|
+
proxy = "http://#{proxy}" unless proxy.include? '://'
|
993
|
+
URI.parse(proxy)
|
994
|
+
end
|
995
|
+
end
|
996
|
+
|
974
997
|
# Fake exception type for net/http exception handling.
|
975
998
|
# Necessary because net/http may or may not be loaded at the time.
|
976
999
|
module HTTPExceptions
|
data/lib/hub/json.rb
CHANGED
@@ -1,76 +1,97 @@
|
|
1
1
|
require 'strscan'
|
2
2
|
require 'forwardable'
|
3
3
|
|
4
|
+
# Stupid pure Ruby JSON parser.
|
4
5
|
class Hub::JSON
|
6
|
+
def self.parse(data) new(data).parse end
|
7
|
+
|
5
8
|
WSP = /\s+/
|
6
|
-
OBJ = /[{\[]/
|
7
|
-
|
8
|
-
|
9
|
-
NUL = /null
|
9
|
+
OBJ = /[{\[]/; HEN = /\}/; AEN = /\]/
|
10
|
+
COL = /\s*:\s*/; KEY = /\s*,\s*/
|
11
|
+
NUM = /-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/
|
12
|
+
BOL = /true|false/; NUL = /null/
|
10
13
|
|
11
14
|
extend Forwardable
|
12
15
|
|
13
16
|
attr_reader :scanner
|
14
17
|
alias_method :s, :scanner
|
15
|
-
private :s
|
16
18
|
def_delegators :scanner, :scan, :matched
|
17
|
-
|
18
|
-
def self.parse(str)
|
19
|
-
self.new(str).parse
|
20
|
-
end
|
19
|
+
private :s, :scan, :matched
|
21
20
|
|
22
21
|
def initialize data
|
23
22
|
@scanner = StringScanner.new data.to_s
|
24
23
|
end
|
25
24
|
|
26
|
-
def space
|
27
|
-
scan WSP
|
28
|
-
end
|
29
|
-
|
30
25
|
def parse
|
31
26
|
space
|
32
27
|
object
|
33
28
|
end
|
34
29
|
|
30
|
+
private
|
31
|
+
|
32
|
+
def space() scan WSP end
|
33
|
+
|
34
|
+
def endkey() scan(KEY) or space end
|
35
|
+
|
35
36
|
def object
|
36
|
-
|
37
|
-
when '{' then hash
|
38
|
-
when '[' then array
|
39
|
-
end
|
37
|
+
matched == '{' ? hash : array if scan(OBJ)
|
40
38
|
end
|
41
39
|
|
42
40
|
def value
|
43
41
|
object or string or
|
44
|
-
|
45
|
-
scan(
|
42
|
+
scan(NUL) ? nil :
|
43
|
+
scan(BOL) ? matched.size == 4:
|
44
|
+
scan(NUM) ? eval(matched) :
|
45
|
+
error
|
46
46
|
end
|
47
47
|
|
48
48
|
def hash
|
49
|
-
|
49
|
+
obj = {}
|
50
50
|
space
|
51
|
-
|
52
|
-
|
53
|
-
scan(/\s*:\s*/)
|
54
|
-
current[key] = value
|
55
|
-
scan(/\s*,\s*/) or space
|
56
|
-
end
|
57
|
-
current
|
51
|
+
repeat_until(HEN) { k = string; scan(COL); obj[k] = value; endkey }
|
52
|
+
obj
|
58
53
|
end
|
59
54
|
|
60
55
|
def array
|
61
|
-
|
56
|
+
ary = []
|
62
57
|
space
|
63
|
-
|
64
|
-
|
65
|
-
scan(/\s*,\s*/) or space
|
66
|
-
end
|
67
|
-
current
|
58
|
+
repeat_until(AEN) { ary << value; endkey }
|
59
|
+
ary
|
68
60
|
end
|
69
61
|
|
62
|
+
SPEC = {'b' => "\b", 'f' => "\f", 'n' => "\n", 'r' => "\r", 't' => "\t"}
|
63
|
+
UNI = 'u'; CODE = /[a-fA-F0-9]{4}/
|
64
|
+
STR = /"/; STE = '"'
|
65
|
+
ESC = '\\'
|
66
|
+
|
70
67
|
def string
|
71
|
-
if
|
72
|
-
|
73
|
-
|
68
|
+
if scan(STR)
|
69
|
+
str, esc = '', false
|
70
|
+
while c = s.getch
|
71
|
+
if esc
|
72
|
+
str << (c == UNI ? (s.scan(CODE) || error).to_i(16).chr : SPEC[c] || c)
|
73
|
+
esc = false
|
74
|
+
else
|
75
|
+
case c
|
76
|
+
when ESC then esc = true
|
77
|
+
when STE then break
|
78
|
+
else str << c
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
str
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def error
|
87
|
+
raise "parse error at: #{scan(/.{1,10}/m).inspect}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def repeat_until reg
|
91
|
+
until scan(reg)
|
92
|
+
pos = s.pos
|
93
|
+
yield
|
94
|
+
error unless s.pos > pos
|
74
95
|
end
|
75
96
|
end
|
76
97
|
end
|
data/lib/hub/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-01-
|
13
|
+
date: 2012-01-24 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: ! " `hub` is a command line utility which adds GitHub knowledge to `git`.\n\n
|
16
16
|
\ It can used on its own or as a `git` wrapper.\n\n Normal:\n\n $ hub clone
|