Fix commit log presentation.

This commit is contained in:
takezoe
2013-06-19 04:27:57 +09:00
parent 1679fb98d0
commit 7a3512ee18
9 changed files with 66 additions and 25 deletions

View File

@@ -75,7 +75,7 @@ class CommitLogHook(owner: String, repository: String) extends PostReceiveHook {
commands.asScala.foreach { command =>
JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name).foreach { commit =>
// TODO extract issue id and add comment to issue
logger.debug(commit.id + ":" + commit.message)
logger.debug(commit.id + ":" + commit.shortMessage)
}
}
}

View File

@@ -50,11 +50,22 @@ object JGitUtil {
* @param id the commit id
* @param time the commit time
* @param committer the commiter name
* @param message the commit message
* @param shortMessage the short message
* @param fullMessage the full message
*/
case class CommitInfo(id: String, time: Date, committer: String, message: String){
case class CommitInfo(id: String, time: Date, committer: String, shortMessage: String, fullMessage: String){
def this(rev: org.eclipse.jgit.revwalk.RevCommit) =
this(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getFullMessage)
this(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getShortMessage, rev.getFullMessage)
val description = {
val i = fullMessage.trim.indexOf("\n")
if(i >= 0){
Some(fullMessage.trim.substring(i).trim)
} else {
None
}
}
}
case class DiffInfo(changeType: ChangeType, oldPath: String, newPath: String, oldContent: Option[String], newContent: Option[String])

View File

@@ -14,11 +14,28 @@ object helpers {
* Format java.util.Date to "yyyy/MM/dd".
*/
def date(date: Date): String = new SimpleDateFormat("yyyy/MM/dd").format(date)
def format(value: String): Html =
Html(value.replaceAll(" ", "&nbsp;").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll("\n", "<br>"))
// TODO escape html tags using HtmlEscapeUtils (Commons Lang)
def format(value: String): Html = Html(
value.replaceAll(" ", "&nbsp;").replaceAll("\t", "&nbsp;&nbsp;&nbsp;&nbsp;").replaceAll("\n", "<br>"))
def formatCommitLog(message: String): Html = {
val i = message.trim.indexOf("\n")
val (firstLine, description) = if(i >= 0){
(message.trim.substring(0, i).trim, Some(message.trim.substring(i).trim))
} else {
(message.trim, None)
}
val sb = new StringBuilder()
sb.append("<div class=\"summary\">").append(format(firstLine).text).append("</div>")
if(description.isDefined){
sb.append("<div class=\"description\">").append(format(description.get).text).append("</div>")
}
Html(sb.toString)
}
/**
* Converts Markdown of Wiki pages to HTML.
*/
@@ -27,15 +44,15 @@ object helpers {
Html(Markdown.toHtml(value, repository, enableWikiLink, enableCommitLink, enableIssueLink))
}
/**
* Cut the given string by specified length.
*/
def cut(message: String, length: Int): String = {
if(message.length > length){
message.substring(0, length) + "..."
} else {
message
}
}
// /**
// * Cut the given string by specified length.
// */
// def cut(message: String, length: Int): String = {
// if(message.length > length){
// message.substring(0, length) + "..."
// } else {
// message
// }
// }
}