95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/gh_issues/cli.rb', line 95
def show(repo=nil, issue_number=0)
ENV['GH_ISSUES_COLORIZE'] = '1' if options[:color]
origin_url=`git remote get-url origin 2>/dev/null`.strip
current_repo = nil
if GhIssues.in_github_repo?(origin_url)
current_repo = GhIssues.get_repo_name(origin_url)
end
unless repo
repo = current_repo if current_repo
else
if is_numeric?(repo)
issue_number = repo.to_i
repo = current_repo
end
end
issue_number = issue_number.to_i
puts "Listing current GitHub repo: #{repo}" if repo == current_repo
if issue_number > 0
markdown = Redcarpet::Markdown.new(GhIssues::TextRenderer)
issue = GhIssues.get_issue(repo, issue_number)
table = Terminal::Table.new do |t|
t.add_row [colorize("Repo/Issue", :yellow), colorize("#{repo}/#{issue_number}", :white)]
t.add_separator
t.add_row [colorize("Title", :yellow), issue[:title]]
t.add_separator
t.add_row [colorize("Opener", :yellow), issue[:user]]
t.add_row [colorize("Labes", :yellow), issue[:labels].join(',')] if issue[:labels].count > 0
t.add_row [colorize("Assignees", :yellow), issue[:assignees].join(', ')] if issue[:assignees].count > 0
t.add_separator
created_at = issue[:created_at].strftime(DEFAULT_DATE_FORMAT)
updated_at = issue[:updated_at].strftime(DEFAULT_DATE_FORMAT)
now = Time.now
created_at_diff = TimeDifference.between(now, issue[:created_at]).in_days.to_i
updated_at_diff = TimeDifference.between(now, issue[:updated_at]).in_days.to_i
t.add_row [colorize("Created at", :yellow), "#{created_at} (#{created_at_diff} #{pluralize("day", "days", created_at_diff)} ago)"]
t.add_row [colorize("Updated at", :yellow), "#{updated_at} (#{updated_at_diff} #{pluralize("day", "days", updated_at_diff)} ago)"]
if issue[:body].length > 0
body_text = markdown.render(issue[:body])
t.add_separator
t.add_row [colorize("Body", :yellow), wrap(body_text, WRAP_TEXT_AT)]
end
if issue[:comments].length > 0
t.add_separator
t.add_row [{value: "#{colorize(pluralize('Comment', 'Comments', issue[:comments].length), :yellow)} (#{issue[:comments].length})", colspan: 2, alignment: :center}]
issue[:comments].each do ||
t.add_separator
= [:created_at].strftime(DEFAULT_DATE_FORMAT)
= TimeDifference.between(now, [:created_at]).in_days.to_i
= "#{markdown.render([:body])}\n---\n#{} (#{} #{pluralize("day", "days", )} ago)"
t.add_row [colorize([:user], :green), wrap(, WRAP_TEXT_AT)]
end
end
end
puts table
else
issues = GhIssues.show_repos_issues(repo)
if issues.count > 0
table = Terminal::Table.new do |t|
t.add_row ["", colorize(repo, :yellow), colorize("Url", :yellow)]
t.add_separator
issues.each do |issue|
t.add_row [
{value: colorize("##{issue[:number]}", :white), alignment: :left},
issue[:title],
"#{issue[:html_url]}",
]
end
end
puts table
else
puts "Hooray! You have no issue here..."
end
end
end
|