Skip to content

Instantly share code, notes, and snippets.

@ursm
Created July 29, 2008 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ursm/3100 to your computer and use it in GitHub Desktop.
Save ursm/3100 to your computer and use it in GitHub Desktop.
require 'time'
module Ditz
class Issue
def hg_commits
return @hg_commits if @hg_commits
output = `hg log --template '{date|rfc822date}\t{author}\t{node|short}\t{desc|firstline}\n' #{pathname}`
@hg_commits = output.split("\n").map {|line|
date, *vals = line.split("\t")
[Time.parse(date), *vals]
}
end
end
class Config
field :mercurial_commit_url_prefix, :prompt => "URL prefix (if any) to link mercurial commits to"
end
class ScreenView
add_to_view :issue_details do |issue, config|
next if (commits = issue.hg_commits[0...5]).empty?
commits.map {|date, author, node, desc|
"- #{desc} [#{node}] (#{author.shortened_email}, #{date.ago} ago)"
}.unshift('Recent commits:').join("\n") + "\n\n"
end
end
class HtmlView
add_to_view :issue_details do |issue, config|
next if (commits = issue.hg_commits).empty?
[<<-EOS, {:commits => commits, :url_prefix => config.mercurial_commit_url_prefix}]
<h2>Commits for this issue</h2>
<table>
<% commits.each_with_index do |(date, author, node, desc), i| %>
<tr class="logentry<%= i % 2 == 0 ? 'even' : 'odd' %>">
<td class="logtime"><%=t date %></td>
<td class="logwho"><%=obscured_email author %></td>
<td class="logwhat"><%=h desc %> [<%= url_prefix ? link_to([url_prefix, node].join, node) : node %>]</td>
</tr>
<% end %>
</table>
EOS
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment