class GHI::Commands::Show

Attributes

patch[RW]
web[RW]

Public Instance Methods

execute() click to toggle source
# File lib/ghi/commands/show.rb, line 15
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 patch_path || "issues/#{issue}"
  else
    if patch_path
      i = throb { Web.new(repo).curl patch_path }
      unless i.start_with? 'From'
        warn 'Patch not found'
        abort
      end
      page do
        no_color { puts i }
        break
      end
    else
      i = throb { api.get "/repos/#{repo}/issues/#{issue}" }.body
      determine_merge_status(i) if pull_request?(i)
      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
    end
  end
end
options() click to toggle source
# File lib/ghi/commands/show.rb, line 6
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

Private Instance Methods

determine_merge_status(pr) click to toggle source
# File lib/ghi/commands/show.rb, line 55
def determine_merge_status(pr)
  pr['merged'] = true if pr['state'] == 'closed' && merged?
end
merged?() click to toggle source
# File lib/ghi/commands/show.rb, line 59
def merged?
  # API returns with a Not Found error when the PR is not merged
  api.get "/repos/#{repo}/pulls/#{issue}/merge" rescue false
end
pull_request?(issue) click to toggle source
# File lib/ghi/commands/show.rb, line 51
def pull_request?(issue)
  issue['pull_request']['html_url']
end