Class: GHI::Commands::Show

Inherits:
Command
  • Object
show all
Defined in:
lib/ghi/commands/show.rb

Constant Summary

Constants included from Formatting

Formatting::CURSOR, Formatting::THROBBERS

Constants included from Formatting::Colors

Formatting::Colors::ANSI, Formatting::Colors::WEB

Instance Attribute Summary collapse

Attributes inherited from Command

#action, #args, #verbose

Attributes included from Formatting

#paging

Instance Method Summary collapse

Methods inherited from Command

#api, #assigns, execute, #initialize, #repo, #repo=

Methods included from Formatting

#columns, #dimensions, #format_comment, #format_comment_editor, #format_comments_and_events, #format_date, #format_editor, #format_event, #format_event_type, #format_issue, #format_issues, #format_issues_header, #format_labels, #format_markdown, #format_milestone, #format_milestone_editor, #format_milestones, #format_number, #format_state, #format_tag, #format_username, #indent, #page, #paginate?, #paging?, #past_due?, #percent, #puts, #throb, #truncate

Methods included from Formatting::Colors

#bg, #blink, #bright, #colorize?, colorize?, #fg, #highlight, #inverse, #no_color, #to_hex, #underline

Constructor Details

This class inherits a constructor from GHI::Commands::Command

Instance Attribute Details

#patchObject

Returns the value of attribute patch.



4
5
6
# File 'lib/ghi/commands/show.rb', line 4

def patch
  @patch
end

#webObject

Returns the value of attribute web.



4
5
6
# File 'lib/ghi/commands/show.rb', line 4

def web
  @web
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

#optionsObject



6
7
8
9
10
11
12
13
# 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