stephencelis-ghi 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -0
- data/bin/ghi +1 -1
- data/lib/ghi/cli.rb +87 -36
- data/lib/ghi.rb +1 -1
- data/spec/ghi/api_spec.rb +12 -14
- data/spec/ghi/cli_spec.rb +237 -3
- data/spec/ghi/issue_spec.rb +21 -2
- data/spec/ghi_spec.rb +0 -2
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -28,6 +28,7 @@ Go:
|
|
28
28
|
--claim [number]
|
29
29
|
-d, --unlabel [number] [label]
|
30
30
|
-u, --url [number]
|
31
|
+
--[no-]colors
|
31
32
|
-V, --version
|
32
33
|
-h, --help
|
33
34
|
|
@@ -63,6 +64,9 @@ ghi also works anywhere:
|
|
63
64
|
ghi -rstephencelis/ghi -l # Mine: "stephencelis/ghi"
|
64
65
|
|
65
66
|
|
67
|
+
ghi uses ANSI colors if you use them in git.
|
68
|
+
|
69
|
+
|
66
70
|
== CONTRIBUTORS
|
67
71
|
|
68
72
|
* Jamie Macey (http://blog.tracefunc.com)
|
data/bin/ghi
CHANGED
data/lib/ghi/cli.rb
CHANGED
@@ -130,22 +130,53 @@ module GHI::CLI #:nodoc:
|
|
130
130
|
def comment?
|
131
131
|
![:open, :edit].include?(action)
|
132
132
|
end
|
133
|
+
|
134
|
+
def puts(*args)
|
135
|
+
args = args.flatten.each { |arg|
|
136
|
+
arg.gsub!(/(state:)?(# Open.*| open)$/) { "#$1\e[32m#$2\e[0m" }
|
137
|
+
arg.gsub!(/(state:)?(# Closed.*| closed)$/) { "#$1\e[31m#$2\e[0m" }
|
138
|
+
marked = [GHI.login, search_term, tag, "(?:#|gh)-\d+"].compact * "|"
|
139
|
+
unless arg.include? "\e"
|
140
|
+
arg.gsub!(/(#{marked})/i) { "\e[1;4;33m#{$&}\e[0m" }
|
141
|
+
end
|
142
|
+
} if colorize?
|
143
|
+
rescue NoMethodError
|
144
|
+
# Do nothing.
|
145
|
+
ensure
|
146
|
+
Kernel.puts(*args)
|
147
|
+
end
|
148
|
+
|
149
|
+
def colorize?
|
150
|
+
return false unless $stdout.isatty
|
151
|
+
return @colorize if defined? @colorize
|
152
|
+
@colorize = !`git config --get-regexp color`.chomp.empty?
|
153
|
+
end
|
133
154
|
end
|
134
155
|
|
135
156
|
class Executable
|
136
157
|
include FileHelper, FormattingHelper
|
137
158
|
|
138
159
|
attr_reader :message, :user, :repo, :api, :action, :state, :search_term,
|
139
|
-
:number, :title, :body, :
|
160
|
+
:number, :title, :body, :tag, :args
|
140
161
|
|
141
|
-
def
|
142
|
-
@args =
|
162
|
+
def parse!(*argv)
|
163
|
+
@args = argv
|
164
|
+
option_parser.parse!(*args)
|
143
165
|
|
144
166
|
if action.nil?
|
145
167
|
puts option_parser
|
146
168
|
exit
|
147
169
|
end
|
148
170
|
|
171
|
+
run!
|
172
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument,
|
173
|
+
OptionParser::AmbiguousOption => e
|
174
|
+
warn "#{File.basename $0}: #{e.message}"
|
175
|
+
puts option_parser
|
176
|
+
exit 1
|
177
|
+
end
|
178
|
+
|
179
|
+
def run!
|
149
180
|
`git config --get remote.origin.url`.match %r{([^:/]+)/([^/]+).git$}
|
150
181
|
@user ||= $1
|
151
182
|
@repo ||= $2
|
@@ -159,10 +190,9 @@ module GHI::CLI #:nodoc:
|
|
159
190
|
when :edit then edit
|
160
191
|
when :close then close
|
161
192
|
when :reopen then reopen
|
162
|
-
when :comment then comment
|
163
|
-
when :label, :claim then
|
164
|
-
when :unlabel then
|
165
|
-
|
193
|
+
when :comment then prepare_comment && comment
|
194
|
+
when :label, :claim then prepare_label && label
|
195
|
+
when :unlabel then prepare_label && unlabel
|
166
196
|
when :url then url
|
167
197
|
end
|
168
198
|
rescue GHI::API::InvalidConnection
|
@@ -175,10 +205,10 @@ module GHI::CLI #:nodoc:
|
|
175
205
|
rescue GHI::API::ResponseError => e
|
176
206
|
warn "#{File.basename $0}: #{e.message} (#{user}/#{repo})"
|
177
207
|
exit 1
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
208
|
+
end
|
209
|
+
|
210
|
+
def commenting?
|
211
|
+
@commenting
|
182
212
|
end
|
183
213
|
|
184
214
|
private
|
@@ -216,7 +246,7 @@ module GHI::CLI #:nodoc:
|
|
216
246
|
@action = :list
|
217
247
|
@state = :open
|
218
248
|
when /^m$/
|
219
|
-
@title =
|
249
|
+
@title = args * " "
|
220
250
|
when /^u$/
|
221
251
|
@action = :url
|
222
252
|
else
|
@@ -227,16 +257,16 @@ module GHI::CLI #:nodoc:
|
|
227
257
|
opts.on("-c", "--closed", "--close [number]") do |v|
|
228
258
|
case v
|
229
259
|
when /^\d+$/
|
230
|
-
@action
|
260
|
+
@action = :close
|
231
261
|
@number = v.to_i unless v.nil?
|
232
|
-
when /^l
|
262
|
+
when /^l$/
|
233
263
|
@action = :list
|
234
264
|
@state = :closed
|
235
|
-
when /^u
|
265
|
+
when /^u$/
|
236
266
|
@action = :url
|
237
267
|
@state = :closed
|
238
268
|
when nil
|
239
|
-
|
269
|
+
@action = :close
|
240
270
|
else
|
241
271
|
raise OptionParser::InvalidOption
|
242
272
|
end
|
@@ -246,7 +276,6 @@ module GHI::CLI #:nodoc:
|
|
246
276
|
case v
|
247
277
|
when /^\d+$/
|
248
278
|
@action = :edit
|
249
|
-
@state = :closed
|
250
279
|
@number = v.to_i
|
251
280
|
when nil
|
252
281
|
raise OptionParser::MissingArgument
|
@@ -256,17 +285,22 @@ module GHI::CLI #:nodoc:
|
|
256
285
|
end
|
257
286
|
|
258
287
|
opts.on("-r", "--repo", "--repository [name]") do |v|
|
259
|
-
|
260
|
-
|
261
|
-
|
288
|
+
case v
|
289
|
+
when nil
|
290
|
+
raise OptionParser::MissingArgument
|
291
|
+
else
|
292
|
+
repo = v.split "/"
|
293
|
+
repo.unshift GHI.login if repo.length == 1
|
294
|
+
@user, @repo = repo
|
295
|
+
end
|
262
296
|
end
|
263
297
|
|
264
298
|
opts.on("-m", "--comment [number|comment]") do |v|
|
265
299
|
case v
|
266
300
|
when /^\d+$/, nil
|
267
301
|
@action ||= :comment
|
268
|
-
@number ||= v
|
269
|
-
@
|
302
|
+
@number ||= v.to_i unless v.nil?
|
303
|
+
@commenting = true
|
270
304
|
else
|
271
305
|
@body = v
|
272
306
|
end
|
@@ -282,7 +316,7 @@ module GHI::CLI #:nodoc:
|
|
282
316
|
raise OptionParser::MissingArgument if v.nil?
|
283
317
|
@action = :claim
|
284
318
|
@number = v.to_i
|
285
|
-
@
|
319
|
+
@tag = GHI.login
|
286
320
|
end
|
287
321
|
|
288
322
|
opts.on("-d", "--unlabel [number] [label]") do |v|
|
@@ -291,20 +325,26 @@ module GHI::CLI #:nodoc:
|
|
291
325
|
when /^\d+$/
|
292
326
|
@number = v.to_i
|
293
327
|
when /^\w+$/
|
294
|
-
@
|
328
|
+
@tag = v
|
295
329
|
end
|
296
330
|
end
|
297
331
|
|
298
|
-
opts.on("-u", "--url [number]") do |v|
|
332
|
+
opts.on("-u", "--url [state|number]") do |v|
|
299
333
|
@action = :url
|
300
334
|
case v
|
301
335
|
when /^\d+$/
|
302
336
|
@number = v.to_i
|
303
|
-
when /^c
|
337
|
+
when /^c(?:losed)?$/
|
304
338
|
@state = :closed
|
339
|
+
when /^u(?:nread)?$/
|
340
|
+
@state = :unread
|
305
341
|
end
|
306
342
|
end
|
307
343
|
|
344
|
+
opts.on("--[no-]color") do |v|
|
345
|
+
@colorize = v
|
346
|
+
end
|
347
|
+
|
308
348
|
opts.on_tail("-V", "--version") do
|
309
349
|
puts "#{File.basename($0)}: v#{GHI::VERSION}"
|
310
350
|
exit
|
@@ -335,7 +375,7 @@ module GHI::CLI #:nodoc:
|
|
335
375
|
def open
|
336
376
|
if title.nil?
|
337
377
|
new_title, new_body = gets_from_editor GHI::Issue.new("title" => body)
|
338
|
-
elsif @
|
378
|
+
elsif @commenting && body.nil?
|
339
379
|
new_title, new_body = gets_from_editor GHI::Issue.new("title" => title)
|
340
380
|
end
|
341
381
|
new_title ||= title
|
@@ -357,8 +397,9 @@ module GHI::CLI #:nodoc:
|
|
357
397
|
end
|
358
398
|
|
359
399
|
def close
|
400
|
+
raise GHI::API::InvalidRequest, "need a number" if number.nil?
|
360
401
|
issue = api.close number
|
361
|
-
if @
|
402
|
+
if @commenting || new_body = body
|
362
403
|
new_body ||= gets_from_editor issue
|
363
404
|
comment = api.comment number, new_body
|
364
405
|
end
|
@@ -368,7 +409,7 @@ module GHI::CLI #:nodoc:
|
|
368
409
|
|
369
410
|
def reopen
|
370
411
|
issue = api.reopen number
|
371
|
-
if @
|
412
|
+
if @commenting || new_body = body
|
372
413
|
new_body ||= gets_from_editor issue
|
373
414
|
comment = api.comment number, new_body
|
374
415
|
end
|
@@ -376,22 +417,32 @@ module GHI::CLI #:nodoc:
|
|
376
417
|
puts "(comment #{comment["status"]})" if comment
|
377
418
|
end
|
378
419
|
|
379
|
-
def
|
380
|
-
|
381
|
-
|
420
|
+
def prepare_label
|
421
|
+
@tag ||= (body || args * " ")
|
422
|
+
raise GHI::API::InvalidRequest, "need a label" if @tag.empty?
|
423
|
+
true
|
424
|
+
end
|
425
|
+
|
426
|
+
def label
|
427
|
+
labels = api.add_label tag, number
|
382
428
|
puts action_format
|
383
429
|
puts indent(labels.join(", "))
|
384
430
|
end
|
385
431
|
|
386
|
-
def
|
387
|
-
|
388
|
-
labels = api.remove_label new_label, number
|
432
|
+
def unlabel
|
433
|
+
labels = api.remove_label tag, number
|
389
434
|
puts action_format
|
390
435
|
puts indent(labels.empty? ? "no labels" : labels.join(", "))
|
391
436
|
end
|
392
437
|
|
438
|
+
def prepare_comment
|
439
|
+
@body = args.flatten.first
|
440
|
+
@commenting = false unless body.nil?
|
441
|
+
true
|
442
|
+
end
|
443
|
+
|
393
444
|
def comment
|
394
|
-
body
|
445
|
+
@body ||= gets_from_editor api.show(number)
|
395
446
|
comment = api.comment(number, body)
|
396
447
|
delete_message
|
397
448
|
puts "(comment #{comment["status"]})"
|
data/lib/ghi.rb
CHANGED
data/spec/ghi/api_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
1
|
require "ghi"
|
3
2
|
require "ghi/api"
|
4
3
|
require "ghi/issue"
|
5
|
-
include GHI
|
6
4
|
|
7
5
|
ISSUES_YAML = <<-YAML
|
8
6
|
---
|
@@ -54,15 +52,15 @@ YAML
|
|
54
52
|
|
55
53
|
describe GHI::API do
|
56
54
|
it "should require user and repo" do
|
57
|
-
proc { API.new(nil, nil) }.should raise_error(API::InvalidConnection)
|
58
|
-
proc { API.new("u", nil) }.should raise_error(API::InvalidConnection)
|
59
|
-
proc { API.new(nil, "r") }.should raise_error(API::InvalidConnection)
|
60
|
-
proc { API.new("u", "r") }.should_not raise_error(API::InvalidConnection)
|
55
|
+
proc { GHI::API.new(nil, nil) }.should raise_error(GHI::API::InvalidConnection)
|
56
|
+
proc { GHI::API.new("u", nil) }.should raise_error(GHI::API::InvalidConnection)
|
57
|
+
proc { GHI::API.new(nil, "r") }.should raise_error(GHI::API::InvalidConnection)
|
58
|
+
proc { GHI::API.new("u", "r") }.should_not raise_error(GHI::API::InvalidConnection)
|
61
59
|
end
|
62
60
|
|
63
61
|
describe "requests" do
|
64
62
|
before :all do
|
65
|
-
@api = API.new "stephencelis", "ghi"
|
63
|
+
@api = GHI::API.new "stephencelis", "ghi"
|
66
64
|
GHI.stub!(:login).and_return "stephencelis"
|
67
65
|
GHI.stub!(:token).and_return "token"
|
68
66
|
end
|
@@ -106,7 +104,7 @@ describe GHI::API do
|
|
106
104
|
Net::HTTP.stub!(:get).and_return ISSUES_YAML
|
107
105
|
issues = @api.search "me"
|
108
106
|
issues.should be_an_instance_of(Array)
|
109
|
-
issues.each { |issue| issue.should be_an_instance_of(Issue) }
|
107
|
+
issues.each { |issue| issue.should be_an_instance_of(GHI::Issue) }
|
110
108
|
end
|
111
109
|
|
112
110
|
it "should search closed" do
|
@@ -120,7 +118,7 @@ describe GHI::API do
|
|
120
118
|
Net::HTTP.stub!(:get).and_return ISSUES_YAML
|
121
119
|
issues = @api.list
|
122
120
|
issues.should be_an_instance_of(Array)
|
123
|
-
issues.each { |issue| issue.should be_an_instance_of(Issue) }
|
121
|
+
issues.each { |issue| issue.should be_an_instance_of(GHI::Issue) }
|
124
122
|
end
|
125
123
|
|
126
124
|
it "should list closed" do
|
@@ -132,7 +130,7 @@ describe GHI::API do
|
|
132
130
|
it "should show" do
|
133
131
|
@api.should_receive(:url).with(:show, 1).and_return "u"
|
134
132
|
Net::HTTP.stub!(:get).and_return ISSUE_YAML
|
135
|
-
@api.show(1).should be_an_instance_of(Issue)
|
133
|
+
@api.show(1).should be_an_instance_of(GHI::Issue)
|
136
134
|
end
|
137
135
|
|
138
136
|
it "should open" do
|
@@ -140,7 +138,7 @@ describe GHI::API do
|
|
140
138
|
response = mock(Net::HTTPRequest)
|
141
139
|
response.stub!(:body).and_return ISSUE_YAML
|
142
140
|
Net::HTTP.stub!(:post_form).and_return response
|
143
|
-
@api.open("Title", "Body").should be_an_instance_of(Issue)
|
141
|
+
@api.open("Title", "Body").should be_an_instance_of(GHI::Issue)
|
144
142
|
end
|
145
143
|
|
146
144
|
it "should edit" do
|
@@ -148,7 +146,7 @@ describe GHI::API do
|
|
148
146
|
response = mock(Net::HTTPRequest)
|
149
147
|
response.stub!(:body).and_return ISSUE_YAML
|
150
148
|
Net::HTTP.stub!(:post_form).and_return response
|
151
|
-
@api.edit(1, "Title", "Body").should be_an_instance_of(Issue)
|
149
|
+
@api.edit(1, "Title", "Body").should be_an_instance_of(GHI::Issue)
|
152
150
|
end
|
153
151
|
|
154
152
|
it "should close" do
|
@@ -156,7 +154,7 @@ describe GHI::API do
|
|
156
154
|
response = mock(Net::HTTPRequest)
|
157
155
|
response.stub!(:body).and_return ISSUE_YAML
|
158
156
|
Net::HTTP.stub!(:post_form).and_return response
|
159
|
-
@api.close(1).should be_an_instance_of(Issue)
|
157
|
+
@api.close(1).should be_an_instance_of(GHI::Issue)
|
160
158
|
end
|
161
159
|
|
162
160
|
it "should reopen" do
|
@@ -164,7 +162,7 @@ describe GHI::API do
|
|
164
162
|
response = mock(Net::HTTPRequest)
|
165
163
|
response.stub!(:body).and_return ISSUE_YAML
|
166
164
|
Net::HTTP.stub!(:post_form).and_return response
|
167
|
-
@api.reopen(1).should be_an_instance_of(Issue)
|
165
|
+
@api.reopen(1).should be_an_instance_of(GHI::Issue)
|
168
166
|
end
|
169
167
|
|
170
168
|
it "should add labels" do
|
data/spec/ghi/cli_spec.rb
CHANGED
@@ -1,7 +1,241 @@
|
|
1
|
-
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
1
|
require "ghi"
|
2
|
+
require "ghi/api"
|
3
3
|
require "ghi/cli"
|
4
|
-
include GHI
|
5
4
|
|
6
|
-
describe GHI::CLI do
|
5
|
+
describe GHI::CLI::Executable do
|
6
|
+
before :each do
|
7
|
+
@cli = GHI::CLI::Executable.new
|
8
|
+
@cli.stub!(:api).and_return(mock(GHI::API))
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "parsing" do
|
12
|
+
describe "with well-formed arguments" do
|
13
|
+
before :each do
|
14
|
+
@user, @repo = "localuser", "ghi"
|
15
|
+
@action = @state = @number = @term =
|
16
|
+
@title = @body = @tag = @comment = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
@cli.stub!(:`).and_return "stub:localuser/ghi.git"
|
21
|
+
@cli.should_receive(@action)
|
22
|
+
@cli.parse! @args
|
23
|
+
@cli.action.should == @action
|
24
|
+
@cli.state.should == @state
|
25
|
+
@cli.number.should == @number
|
26
|
+
@cli.search_term.should == @term
|
27
|
+
@cli.title.should == @title
|
28
|
+
@cli.body.should == @body
|
29
|
+
@cli.user.should == @user
|
30
|
+
@cli.repo.should == @repo
|
31
|
+
@cli.tag.should == @tag
|
32
|
+
if @commenting
|
33
|
+
@cli.should be_commenting
|
34
|
+
else
|
35
|
+
@cli.should_not be_commenting
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should parse -l as list open" do
|
40
|
+
@args = ["-l"]
|
41
|
+
@action, @state = :list, :open
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should parse -lo as list open" do
|
45
|
+
@args = ["-lo"]
|
46
|
+
@action, @state = :list, :open
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should parse -lc as list closed" do
|
50
|
+
@args = ["-lc"]
|
51
|
+
@action, @state = :list, :closed
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should parse -l2 as show issue 2" do
|
55
|
+
@args = ["-l2"]
|
56
|
+
@action, @number = :show, 2
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should parse -l 'term' as search open for 'term'" do
|
60
|
+
@args = ["-l", "term"]
|
61
|
+
@action, @state, @term = :search, :open, "term"
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should parse -o as open new issue" do
|
65
|
+
@args = ["-o"]
|
66
|
+
@action = :open
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should parse -o 'New Issue' as open issue with title 'New Issue'" do
|
70
|
+
@args = ["-o", "New Issue"]
|
71
|
+
@action, @title = :open, "New Issue"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should parse -om 'New Issue' as open issue with'New Issue'" do
|
75
|
+
@args = ["-om", "New Issue"]
|
76
|
+
@action, @title = :open, "New Issue"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should parse -o 'New Issue' -m as open 'New Issue' in $EDITOR" do
|
80
|
+
@args = ["-o", "New Issue", "-m"]
|
81
|
+
@action, @title, @commenting = :open, "New Issue", true
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should parse -o 'Issue' -m 'Body' as open 'Issue' with 'Body'" do
|
85
|
+
@args = ["-o", "Issue", "-m", "Body"]
|
86
|
+
@action, @title, @body = :open, "Issue", "Body"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should parse -o2 as reopen issue 2" do
|
90
|
+
@args = ["-o2"]
|
91
|
+
@action, @number = :reopen, 2
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should parse -o2 -m as reopen issue 2 with a comment" do
|
95
|
+
@args = ["-o2", "-m"]
|
96
|
+
@action, @number, @commenting = :reopen, 2, true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should parse -o2 -m 'Comment' as reopen issue 2" do
|
100
|
+
@args = ["-o2", "-m", "Comment"]
|
101
|
+
@action, @number, @body = :reopen, 2, "Comment"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should parse -ol as list open" do
|
105
|
+
@args = ["-ol"]
|
106
|
+
@action, @state = :list, :open
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should parse -ou as return open issues url" do
|
110
|
+
@args = ["-ou"]
|
111
|
+
@action = :url # Should state be :open?
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should parse -cl as list closed" do
|
115
|
+
@args = ["-cl"]
|
116
|
+
@action, @state = :list, :closed
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should parse -c2 as close issue 2" do
|
120
|
+
@args = ["-c2"]
|
121
|
+
@action, @number = :close, 2
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should parse -c2 -m as close issue 2 with a comment" do
|
125
|
+
@args = ["-c2", "-m"]
|
126
|
+
@action, @number, @commenting = :close, 2, true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should parse -c2 -m 'Fixed' as close issue 2 with 'Fixed'" do
|
130
|
+
@args = ["-c2", "-m", "Fixed"]
|
131
|
+
@action, @number, @body = :close, 2, "Fixed"
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should parse -m2 -c as close issue 2 with a comment" do
|
135
|
+
@args = ["-m2", "-c"]
|
136
|
+
@action, @number, @commenting = :close, 2, true
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should parse -cu as return closed issues url" do
|
140
|
+
@args = ["-cu"]
|
141
|
+
@action, @state = :url, :closed
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should parse -e2 as edit issue 2" do
|
145
|
+
@args = ["-e2"]
|
146
|
+
@action, @number = :edit, 2
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should parse -rlocalrepo as localuser/localrepo" do
|
150
|
+
GHI.stub!(:login).and_return "localuser"
|
151
|
+
@args = ["-rlocalrepo", "-l"]
|
152
|
+
@action, @state, @user, @repo = :list, :open, "localuser", "localrepo"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should parse -rremoteuser/remoterepo as remoteuser/remoterepo" do
|
156
|
+
@args = ["-rremoteuser/remoterepo", "-l"]
|
157
|
+
@action, @state, @user, @repo = :list, :open, "remoteuser", "remoterepo"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should parse -t2 'tag' as label issue 2 with 'tag'" do
|
161
|
+
@args = ["-t2", "tag"]
|
162
|
+
@action, @number, @tag = :label, 2, "tag"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should parse -d2 'tag' as remove label 'tag' from issue 2" do
|
166
|
+
@args = ["-d2", "tag"]
|
167
|
+
@action, @number, @tag = :unlabel, 2, "tag"
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should parse -m2 as comment on issue 2" do
|
171
|
+
@args = ["-m2"]
|
172
|
+
@action, @number, @commenting = :comment, 2, true
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should parse -m2 'Comment' as comment 'Comment' on issue 2" do
|
176
|
+
@args = ["-m2", "Comment"]
|
177
|
+
@action, @number, @body = :comment, 2, "Comment"
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should parse -u as return open issues url" do
|
181
|
+
@args = ["-u"]
|
182
|
+
@action = :url # Should state be :open?
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should parse -uo as return open issues url" do
|
186
|
+
@args = ["-uo"]
|
187
|
+
@action = :url # Should state be :open?
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should parse -uc as return open issues url" do
|
191
|
+
@args = ["-uc"]
|
192
|
+
@action, @state = :url, :closed
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should parse -u2 as return issue 2 url" do
|
196
|
+
@args = ["-u2"]
|
197
|
+
@action, @number = :url, 2
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should parse -uu as return unread issues url" do
|
201
|
+
@args = ["-uu"]
|
202
|
+
@action, @state = :url, :unread
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "with malformed arguments" do
|
207
|
+
before :each do
|
208
|
+
@cli.should_receive :warn
|
209
|
+
@cli.should_receive(:exit).with 1
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should exit with -e" do
|
213
|
+
@cli.should_receive :puts
|
214
|
+
@cli.parse! ["-e"]
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should exit with -e 'invalid'" do
|
218
|
+
@cli.should_receive :puts
|
219
|
+
@cli.parse! ["-e", "invalid"]
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should exit with -c as list closed" do
|
223
|
+
@cli.parse! ["-c"]
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should exit with -r" do
|
227
|
+
@cli.should_receive :puts
|
228
|
+
@cli.parse! ["-r"]
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should exit with -t" do
|
232
|
+
@cli.should_receive :puts
|
233
|
+
@cli.parse! ["-t"]
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should exit with -t2" do
|
237
|
+
@cli.parse! ["-t2"]
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
7
241
|
end
|
data/spec/ghi/issue_spec.rb
CHANGED
@@ -1,7 +1,26 @@
|
|
1
|
-
$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
1
|
require "ghi"
|
3
2
|
require "ghi/issue"
|
4
|
-
include GHI
|
5
3
|
|
6
4
|
describe GHI::Issue do
|
5
|
+
before :each do
|
6
|
+
@now = Time.now
|
7
|
+
@issue = GHI::Issue.new "number" => 1,
|
8
|
+
"state" => "open",
|
9
|
+
"title" => "new issue",
|
10
|
+
"user" => "schacon",
|
11
|
+
"votes" => 0,
|
12
|
+
"created_at" => @now,
|
13
|
+
"updated_at" => @now,
|
14
|
+
"body" => "my sweet, sweet issue"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should read all keys" do
|
18
|
+
@issue.number.should == 1
|
19
|
+
@issue.state.should == "open"
|
20
|
+
@issue.title.should == "new issue"
|
21
|
+
@issue.user.should == "schacon"
|
22
|
+
@issue.votes.should == 0
|
23
|
+
@issue.created_at.should == @now
|
24
|
+
@issue.updated_at.should == @now
|
25
|
+
end
|
7
26
|
end
|
data/spec/ghi_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../lib")
|
2
1
|
require "ghi"
|
3
2
|
|
4
3
|
LOGGED_OUT_YAML = <<-YAML
|
@@ -85,7 +84,6 @@ describe GHI do
|
|
85
84
|
GHI.should_receive(:gets).and_return "invalid\n", "#{token}\n"
|
86
85
|
Net::HTTP.should_receive(:get).and_return LOGGED_OUT_YAML, LOGGED_IN_YAML
|
87
86
|
GHI.should_receive(:warn).once
|
88
|
-
# FIXME: Passes on its own...but failing for `spec spec`.
|
89
87
|
GHI.should_receive(:`).with("git config --global github.token #{token}").
|
90
88
|
and_return "\n"
|
91
89
|
GHI.token.should == token
|
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.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Celis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-27 00:00:00 -07:00
|
13
13
|
default_executable: ghi
|
14
14
|
dependencies: []
|
15
15
|
|