Module: Terjira::IssuePresenter

Included in:
BaseCLI
Defined in:
lib/terjira/presenters/issue_presenter.rb

Instance Method Summary collapse

Instance Method Details

#render_divided_issues_by_status(issues) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/terjira/presenters/issue_presenter.rb', line 27

def render_divided_issues_by_status(issues)
  extract_status_names(issues).each do |name|
    selected_issues = issues.select { |issue| issue.status.name == name }
    title = colorize_issue_stastus(selected_issues.first.status)
    title += "(#{selected_issues.size})"
    render(title)
    render_issues(selected_issues, header: false)
  end
end

#render_issue_detail(issue) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/terjira/presenters/issue_presenter.rb', line 37

def render_issue_detail(issue)
  header_title = "#{pastel.bold(issue.key)} in #{issue.project.name}"
  header = [insert_new_line(header_title, screen_width - 10)]

  rows = []
  rows << pastel.underline.bold(issue.summary)
  rows << ''
  rows << issue_sutats_bar(issue)
  rows << ''

  rows << [pastel.bold('Assignee'), username_with_email(issue.assignee)].join(' ')
  rows << [pastel.bold('Reporter'), username_with_email(issue.reporter)].join(' ')
  rows << ''
  rows << pastel.bold('Description')
  rows << (issue.description.blank? ? 'None' : issue.description)

  if issue.respond_to?(:environment) && issue.environment.present?
    rows << pastel.bold('Environment')
    rows << issue.environment
  end

  if issue.comments.present?
    rows << ''
    rows << pastel.bold('Comments')
    remain_comments = issue.comments
    comments = remain_comments.pop(4)

    if comments.size.zero?
      rows << 'None'
    elsif remain_comments.empty?
      rows << pastel.dim("- #{remain_comments.size} previous comments exist -")
    end

    comments.each do |comment|
      comment_title = pastel.bold(comment.author['displayName'])
      comment_title += " #{formatted_date(comment.created)}"
      rows << comment_title
      rows << comment.body
      rows << ''
    end
  end

  rows = rows.map { |row| insert_new_line(row, screen_width - 10) }

  table = TTY::Table.new header, rows.map { |r| [r] }
  result = table.render(:unicode, padding: [0, 1, 0, 1], multiline: true)

  render(result)
end

#render_issues(issues, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/terjira/presenters/issue_presenter.rb', line 9

def render_issues(issues, opts = {})
  return render('Empty') if issues.blank?

  header = [pastel.bold('Key'), pastel.bold('Summary')] if opts[:header]

  rows = issues.map do |issue|
    [pastel.bold(issue.key), summarise_issue(issue)]
  end

  table = TTY::Table.new header, rows
  table_opts = { padding: [0, 1, 0, 1], multiline: true }
  result = table.render(:unicode, table_opts) do |renderer|
    renderer.border.separator = :each_row
  end

  render(result)
end

#summarise_issue(issue) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/terjira/presenters/issue_presenter.rb', line 87

def summarise_issue(issue)
  first_line = [colorize_issue_stastus(issue.status),
                issue.summary.tr("\t", ' ')].join

  second_line = [colorize_priority(issue.priority),
                 colorize_issue_type(issue.issuetype),
                 assign_info(issue)].join(' ')

  lines = [first_line, second_line].map do |line|
    insert_new_line(line, screen_width - 30)
  end
  lines.join("\n")
end