Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add patch option to show command [fix #59]

Signed-off-by: Stephen Celis <stephen@stephencelis.com>
  • Loading branch information...
commit bbde9c26b0b4bdf49b04a4eb73fc455ce60f8aba 1 parent 3065f68
Stephen Celis stephencelis authored
Showing with 32 additions and 17 deletions.
  1. +20 −10 lib/ghi/commands/show.rb
  2. +12 −7 lib/ghi/web.rb
30 lib/ghi/commands/show.rb
View
@@ -1,12 +1,13 @@
module GHI
module Commands
class Show < Command
- attr_accessor :web
+ attr_accessor :patch, :web
def options
OptionParser.new do |opts|
opts.banner = 'usage: ghi show <issueno>'
opts.separator ''
+ opts.on('-p', '--patch') { self.patch = true }
opts.on('-w', '--web') { self.web = true }
end
end
@@ -15,18 +16,27 @@ def execute
require_issue
require_repo
options.parse! args
+ patch_path = "pull/#{issue}.patch" if patch # URI also in API...
if web
- Web.new(repo).open "issues/#{issue}"
+ Web.new(repo).open patch_path || "issues/#{issue}"
else
- i = throb { api.get "/repos/#{repo}/issues/#{issue}" }.body
- page do
- puts format_issue(i)
- n = i['comments']
- if n > 0
- puts "#{n} comment#{'s' unless n == 1}:\n\n"
- Comment.execute %W(-l #{issue} -- #{repo})
+ if patch_path
+ i = throb { Web.new(repo).curl(patch_path) }
+ page do
+ puts i
+ break
+ end
+ else
+ i = throb { api.get "/repos/#{repo}/issues/#{issue}" }.body
+ page do
+ puts format_issue(i)
+ n = i['comments']
+ if n > 0
+ puts "#{n} comment#{'s' unless n == 1}:\n\n"
+ Comment.execute %W(-l #{issue} -- #{repo})
+ end
+ break
end
- break
end
end
end
19 lib/ghi/web.rb
View
@@ -1,3 +1,4 @@
+require 'open-uri'
require 'uri'
module GHI
@@ -10,17 +11,21 @@ def initialize base
end
def open path = '', params = {}
- unless params.empty?
- q = params.map { |k, v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }
- path += "?#{q.join '&'}"
- end
- system "open '#{uri + path}'"
+ system "open '#{uri_for path, params}'"
+ end
+
+ def curl path = '', params = {}
+ uri_for(path, params).open.read
end
private
- def uri
- URI(BASE_URI) + "#{base}/"
+ def uri_for path, params
+ unless params.empty?
+ q = params.map { |k, v| "#{CGI.escape k.to_s}=#{CGI.escape v.to_s}" }
+ path += "?#{q.join '&'}"
+ end
+ URI(BASE_URI) + "#{base}/" + path
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.