stephencelis-ghi 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +13 -1
- data/bin/ghi +1 -0
- data/lib/ghi/api.rb +4 -0
- data/lib/ghi/cli.rb +4 -3
- data/lib/ghi.rb +42 -40
- data/spec/ghi/cli_spec.rb +1 -1
- data/spec/ghi_spec.rb +4 -4
- metadata +3 -2
data/History.rdoc
CHANGED
data/bin/ghi
CHANGED
data/lib/ghi/api.rb
CHANGED
@@ -69,6 +69,8 @@ class GHI::API
|
|
69
69
|
res
|
70
70
|
rescue ArgumentError, URI::InvalidURIError
|
71
71
|
raise ResponseError, "GitHub hiccuped on your request"
|
72
|
+
rescue SocketError
|
73
|
+
raise ResponseError, "couldn't find the internet"
|
72
74
|
end
|
73
75
|
|
74
76
|
def post(*args)
|
@@ -79,6 +81,8 @@ class GHI::API
|
|
79
81
|
res
|
80
82
|
rescue ArgumentError, URI::InvalidURIError
|
81
83
|
raise ResponseError, "GitHub hiccuped on your request"
|
84
|
+
rescue SocketError
|
85
|
+
raise ResponseError, "couldn't find the internet"
|
82
86
|
end
|
83
87
|
|
84
88
|
def errors(response)
|
data/lib/ghi/cli.rb
CHANGED
@@ -18,7 +18,7 @@ module GHI::CLI #:nodoc:
|
|
18
18
|
|
19
19
|
def gets_from_editor(issue)
|
20
20
|
if windows?
|
21
|
-
warn "Please supply the message
|
21
|
+
warn "Please supply the message with the -m option"
|
22
22
|
exit 1
|
23
23
|
end
|
24
24
|
|
@@ -195,7 +195,7 @@ module GHI::CLI #:nodoc:
|
|
195
195
|
end
|
196
196
|
|
197
197
|
def windows?
|
198
|
-
RUBY_PLATFORM.include?
|
198
|
+
RUBY_PLATFORM.include? "mswin"
|
199
199
|
end
|
200
200
|
end
|
201
201
|
|
@@ -208,8 +208,9 @@ module GHI::CLI #:nodoc:
|
|
208
208
|
def parse!(*argv)
|
209
209
|
@args, @argv = argv, argv.dup
|
210
210
|
|
211
|
+
remotes = `git config --get-regexp remote\..+\.url`.split /\n/
|
211
212
|
repo_expression = %r{([^:/]+)/([^/\.\s]+)(?:\.git)?$}
|
212
|
-
|
213
|
+
remotes.find { |r| r.include? "github.com" }.match repo_expression
|
213
214
|
@user, @repo = $1, $2
|
214
215
|
|
215
216
|
option_parser.parse!(*args)
|
data/lib/ghi.rb
CHANGED
@@ -2,52 +2,54 @@ require "net/http"
|
|
2
2
|
require "yaml"
|
3
3
|
|
4
4
|
module GHI
|
5
|
-
VERSION = "0.1.
|
5
|
+
VERSION = "0.1.6"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
class << self
|
8
|
+
def login
|
9
|
+
return @login if defined? @login
|
10
|
+
@login = `git config --get github.user`.chomp
|
11
|
+
if @login.empty?
|
12
|
+
begin
|
13
|
+
print "Please enter your GitHub username: "
|
14
|
+
@login = gets.chomp
|
15
|
+
valid = user? @login
|
16
|
+
warn "invalid username" unless valid
|
17
|
+
end until valid
|
18
|
+
`git config --global github.user #@login`
|
19
|
+
end
|
20
|
+
@login
|
18
21
|
end
|
19
|
-
@login
|
20
|
-
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
def token
|
24
|
+
return @token if defined? @token
|
25
|
+
@token = `git config --get github.token`.chomp
|
26
|
+
if @token.empty?
|
27
|
+
begin
|
28
|
+
print "GitHub token (https://github.com/account): "
|
29
|
+
@token = gets.chomp
|
30
|
+
valid = token? @token
|
31
|
+
warn "invalid token for #{login}" unless valid
|
32
|
+
end until valid
|
33
|
+
`git config --global github.token #@token`
|
34
|
+
end
|
35
|
+
@token
|
33
36
|
end
|
34
|
-
@token
|
35
|
-
end
|
36
37
|
|
37
|
-
|
38
|
+
private
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def user?(username)
|
41
|
+
url = "http://github.com/api/v2/yaml/user/show/#{username}"
|
42
|
+
!YAML.load(Net::HTTP.get(URI.parse(url)))["user"].nil?
|
43
|
+
rescue ArgumentError, URI::InvalidURIError
|
44
|
+
false
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
def token?(token)
|
48
|
+
url = "http://github.com/api/v2/yaml/user/show/#{login}"
|
49
|
+
url += "?login=#{login}&token=#{token}"
|
50
|
+
!YAML.load(Net::HTTP.get(URI.parse(url)))["user"]["plan"].nil?
|
51
|
+
rescue ArgumentError, NoMethodError, URI::InvalidURIError
|
52
|
+
false
|
53
|
+
end
|
52
54
|
end
|
53
55
|
end
|
data/spec/ghi/cli_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe GHI::CLI::Executable do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
after :each do
|
22
|
-
@cli.stub!(:`).and_return "stub:localuser/ghi.git"
|
22
|
+
@cli.stub!(:`).and_return "stub@github.com:localuser/ghi.git"
|
23
23
|
@cli.should_receive(@action)
|
24
24
|
@cli.parse! @args
|
25
25
|
@cli.action.should == @action
|
data/spec/ghi_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "ghi"
|
|
2
2
|
|
3
3
|
LOGGED_OUT_YAML = <<-YAML
|
4
4
|
---
|
5
|
-
user:
|
5
|
+
user:
|
6
6
|
id: 23
|
7
7
|
login: defunkt
|
8
8
|
name: Kristopher Walken Wanstrath
|
@@ -18,7 +18,7 @@ YAML
|
|
18
18
|
|
19
19
|
LOGGED_IN_YAML = <<-YAML
|
20
20
|
---
|
21
|
-
user:
|
21
|
+
user:
|
22
22
|
id: 23
|
23
23
|
login: defunkt
|
24
24
|
name: Kristopher Walken Wanstrath
|
@@ -35,7 +35,7 @@ user:
|
|
35
35
|
disk_usage: 50384
|
36
36
|
owned_private_repo_count: 1
|
37
37
|
private_gist_count: 0
|
38
|
-
plan:
|
38
|
+
plan:
|
39
39
|
name: mega
|
40
40
|
collaborators: 60
|
41
41
|
space: 20971520
|
@@ -54,7 +54,7 @@ describe GHI do
|
|
54
54
|
GHI.should_receive(:`).once.and_return "stephencelis\n"
|
55
55
|
GHI.login.should == "stephencelis"
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it "should return token" do
|
59
59
|
GHI.should_receive(:`).once.and_return "da39a3ee5e6b4b0d3255bfef95601890\n"
|
60
60
|
GHI.token.should == "da39a3ee5e6b4b0d3255bfef95601890"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stephencelis-ghi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Celis
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- spec/ghi_spec.rb
|
40
40
|
has_rdoc: true
|
41
41
|
homepage: http://github.com/stephencelis/ghi
|
42
|
+
licenses:
|
42
43
|
post_install_message:
|
43
44
|
rdoc_options:
|
44
45
|
- --main
|
@@ -60,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
61
|
requirements: []
|
61
62
|
|
62
63
|
rubyforge_project: ghi
|
63
|
-
rubygems_version: 1.
|
64
|
+
rubygems_version: 1.3.5
|
64
65
|
signing_key:
|
65
66
|
specification_version: 3
|
66
67
|
summary: GitHub Issues on the command line
|