Convert issue id and commit id in commit message to link.

This commit is contained in:
takezoe
2013-06-22 14:07:26 +09:00
parent fb51210ccc
commit 0ee827eaf5
6 changed files with 28 additions and 12 deletions

View File

@@ -61,6 +61,9 @@ object JGitUtil {
rev.getParents().map(_.name).toList)
val description = {
if(shortMessage == fullMessage){
None
} else {
val i = fullMessage.trim.indexOf("\n")
if(i >= 0){
Some(fullMessage.trim.substring(i).trim)
@@ -68,6 +71,7 @@ object JGitUtil {
None
}
}
}
}

View File

@@ -26,6 +26,18 @@ object helpers {
Html(Markdown.toHtml(value, repository, enableWikiLink, enableCommitLink, enableIssueLink))
}
/**
* Converts issue id and commit id to link.
*/
def link(value: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context): Html =
Html(value
// escape HTML tags
.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;")
// convert issue id to link
.replaceAll("(^|\\W)#([0-9]+)(\\W|$)", "$1<a href=\"%s/%s/%s/issues/$2\">#$2</a>$3".format(context.path, repository.owner, repository.name))
// convert commit id to link
.replaceAll("(^|\\W)([a-f0-9]{40})(\\W|$)", "$1<a href=\"%s/%s/%s/commit/$0\">$2</a>$3").format(context.path, repository.owner, repository.name))
}
/**

View File

@@ -21,7 +21,7 @@
<div class="pull-left">
<a href="@path/@latestCommit.committer" class="username">@latestCommit.committer</a>
<span class="description">@helpers.datetime(latestCommit.time)</span>
<a href="@path/@repository.owner/@repository.name/commit/@latestCommit.id" class="commit-message">@latestCommit.shortMessage</a>
<a href="@path/@repository.owner/@repository.name/commit/@latestCommit.id" class="commit-message">@helpers.link(latestCommit.shortMessage, repository)</a>
</div>
<div class="btn-group pull-right">
<a class="btn btn-mini" href="?raw=true">Raw</a>

View File

@@ -12,9 +12,9 @@
<div class="pull-right align-right">
<a href="@path/@repository.owner/@repository.name/tree/@commit.id" class="btn btn-small">Browse code</a>
</div>
<div class="commit-log">@commit.shortMessage</div>
<div class="commit-log">@helpers.link(commit.shortMessage, repository)</div>
@if(commit.description.isDefined){
<pre class="commit-description">@commit.description.get</pre>
<pre class="commit-description">@helpers.link(commit.description.get, repository)</pre>
}
<div class="small" style="font-weight: normal;">
@if(branches.nonEmpty){

View File

@@ -30,13 +30,13 @@
<tr>
<td>
<div class="pull-left">
<a href="@path/@repository.owner/@repository.name/commit/@commit.id" class="commit-message" style="font-weight: bold;">@commit.shortMessage</a>
<a href="@path/@repository.owner/@repository.name/commit/@commit.id" class="commit-message" style="font-weight: bold;">@helpers.link(commit.shortMessage, repository)</a>
@if(commit.description.isDefined){
<a href="javascript:void(0)" onclick="$('#description-@commit.id').toggle();" class="omit">...</a>
}
<br>
@if(commit.description.isDefined){
<pre id="description-@commit.id" style="display: none;" class="commit-description">@commit.description.get</pre>
<pre id="description-@commit.id" style="display: none;" class="commit-description">@helpers.link(commit.description.get, repository)</pre>
}
<div class="small">
<a href="@path/@commit.committer" class="committer">@commit.committer</a>

View File

@@ -14,12 +14,12 @@
<table class="table table-file-list" style="border: 1px solid silver;">
<tr>
<th colspan="4" style="font-weight: normal;">
<a href="@path/@repository.owner/@repository.name/commit/@latestCommit.id" class="commit-message">@latestCommit.shortMessage</a>
<a href="@path/@repository.owner/@repository.name/commit/@latestCommit.id" class="commit-message">@helpers.link(latestCommit.shortMessage, repository)</a>
@if(latestCommit.description.isDefined){
<a href="javascript:void(0)" onclick="$('#description-@latestCommit.id').toggle();" class="omit">...</a>
}
@if(latestCommit.description.isDefined){
<pre id="description-@latestCommit.id" class="commit-description" style="display: none;">@latestCommit.description.get</pre>
<pre id="description-@latestCommit.id" class="commit-description" style="display: none;">@helpers.link(latestCommit.description.get, repository)</pre>
}
</th>
</tr>
@@ -59,7 +59,7 @@
}
</td>
<td>@helpers.datetime(file.time)</td>
<td><a href="@path/@repository.owner/@repository.name/commit/@file.commitId" class="commit-message">@file.message</a> [<a href="@path/@file.committer">@file.committer</a>]</td>
<td><a href="@path/@repository.owner/@repository.name/commit/@file.commitId" class="commit-message">@helpers.link(file.message, repository)</a> [<a href="@path/@file.committer">@file.committer</a>]</td>
</tr>
}
</table>