Class: Github::Issues

Inherits:
Thor
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, CLI::ShellHelpers
Defined in:
lib/github/issues.rb

Instance Method Summary collapse

Methods included from CLI::ShellHelpers

#hr, #width_for_percent

Instance Method Details

#listObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/github/issues.rb', line 15

def list
  issues = Github::CLI.repository.issues(page: options[:page])
  page_count = issues.count_pages == 0 ? 1 : issues.count_pages

  say "Issues for #{Github::CLI.repository.id} (Page #{options[:page]}/#{page_count})"

  title_width = width_for_percent(0.45)
  creator_width = width_for_percent(0.15)
  format_s = "%-8s %-#{title_width}.#{title_width}s %-#{creator_width}s %s"

  say sprintf(format_s, '#', 'Title', 'User', 'Date')
  issues.each do |issue|
    say sprintf(format_s, "##{issue.number}", issue.title, issue.user., time_ago_in_words(Date.parse(issue.updated_at)) + ' ago')
  end
end

#show(number) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/github/issues.rb', line 32

def show(number)
  issue = Github::CLI.repository.issue(number)

  say "##{number} - #{issue.title}"
  say sprintf("%#{terminal_width}s", "#{issue.user.} on #{issue.created_at}")
  say hr
  say issue.body + "\n"

  return if issue.comments == 0

  comments = Github::CLI.repository.issue_comments(number)

  comments.each do |comment|
    say hr
    say sprintf("%#{terminal_width}s", "#{comment.user.} on #{comment.created_at}")
    say comment.body
  end
end