Merge pull request #2112 from nanoant/patch/better-git-message-display

Render commit msg as header + verbatim description
This commit is contained in:
Unknwon 2015-12-06 20:06:23 -05:00
commit abb02889f2
6 changed files with 52 additions and 25 deletions

View File

@ -183,15 +183,27 @@ func ReplaceLeft(s, old, new string) string {
} }
// RenderCommitMessage renders commit message with XSS-safe and special links. // RenderCommitMessage renders commit message with XSS-safe and special links.
func RenderCommitMessage(msg, urlPrefix string, metas map[string]string) template.HTML { func RenderCommitMessage(full bool, msg, urlPrefix string, metas map[string]string) template.HTML {
cleanMsg := template.HTMLEscapeString(msg) cleanMsg := template.HTMLEscapeString(msg)
fullMessage := string(base.RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix, metas)) fullMessage := string(base.RenderIssueIndexPattern([]byte(cleanMsg), urlPrefix, metas))
msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n")
for i := range msgLines { numLines := len(msgLines)
msgLines[i] = ReplaceLeft(msgLines[i], " ", " ") if numLines == 0 {
return template.HTML("")
} else if !full {
return template.HTML(msgLines[0])
} else if numLines == 1 || (numLines >= 2 && len(msgLines[1]) == 0) {
// First line is a header, standalone or followed by empty line
header := fmt.Sprintf("<h3>%s</h3>", msgLines[0])
if numLines >= 2 {
fullMessage = header + fmt.Sprintf("\n<pre>%s</pre>", strings.Join(msgLines[2:], "\n"))
} else {
fullMessage = header
}
} else {
// Non-standard git message, there is no header line
fullMessage = fmt.Sprintf("<h4>%s</h4>", strings.Join(msgLines, "<br>"))
} }
fullMessage = strings.Join(msgLines, "<br>")
return template.HTML(fullMessage) return template.HTML(fullMessage)
} }

View File

@ -895,13 +895,22 @@ pre.raw {
.ui .warning.segment { .ui .warning.segment {
border-color: #F0C36D; border-color: #F0C36D;
} }
.ui .info.header {
background-color: #d9edf7 !important;
border-color: #85c5e5;
}
.ui .info.segment { .ui .info.segment {
border-color: #85c5e5; border-color: #85c5e5;
} }
.ui .info.segment.top {
background-color: #d9edf7 !important;
}
.ui .info.segment.top h3,
.ui .info.segment.top h4 {
margin-top: 0;
}
.ui .info.segment.top h3:last-child {
margin-top: 4px;
}
.ui .info.segment.top > :last-child {
margin-bottom: 0;
}
.ui .normal.header { .ui .normal.header {
font-weight: normal; font-weight: normal;
} }

View File

@ -196,12 +196,20 @@ pre {
} }
} }
.info { .info {
&.header {
background-color: #d9edf7 !important;
border-color: #85c5e5;
}
&.segment { &.segment {
border-color: #85c5e5; border-color: #85c5e5;
&.top {
background-color: #d9edf7 !important;
h3, h4 {
margin-top: 0;
}
h3:last-child {
margin-top: 4px;
}
> :last-child {
margin-bottom: 0;
}
}
} }
} }

View File

@ -37,7 +37,7 @@
</td> </td>
<td class="message collapsing"> <td class="message collapsing">
<a rel="nofollow" class="ui sha label" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.ID}}">{{ShortSha .ID.String}}</a> <a rel="nofollow" class="ui sha label" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{.ID}}">{{ShortSha .ID.String}}</a>
{{RenderCommitMessage .Summary $.RepoLink $.Repository.ComposeMetas}} {{RenderCommitMessage false .Summary $.RepoLink $.Repository.ComposeMetas}}
</td> </td>
<td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td> <td class="grey text right aligned">{{TimeSince .Author.When $.Lang}}</td>
</tr> </tr>

View File

@ -5,14 +5,12 @@
{{if .IsDiffCompare }} {{if .IsDiffCompare }}
{{template "repo/commits_table" .}} {{template "repo/commits_table" .}}
{{else}} {{else}}
<h4 class="ui top attached info header"> <div class="ui top attached info clearing segment">
<div class="ui right"> <a class="ui floated right blue tiny button" href="{{EscapePound .SourcePath}}">
<a class="ui blue tiny button" href="{{EscapePound .SourcePath}}">
{{.i18n.Tr "repo.diff.browse_source"}} {{.i18n.Tr "repo.diff.browse_source"}}
</a> </a>
{{RenderCommitMessage true .Commit.Message $.RepoLink $.Repository.ComposeMetas}}
</div> </div>
{{RenderCommitMessage .Commit.Message $.RepoLink $.Repository.ComposeMetas}}
</h4>
<div class="ui attached info segment"> <div class="ui attached info segment">
{{if .Author}} {{if .Author}}
<img class="ui avatar image" src="{{.Author.AvatarLink}}" /> <img class="ui avatar image" src="{{.Author.AvatarLink}}" />

View File

@ -10,7 +10,7 @@
<strong>{{.LastCommit.Author.Name}}</strong> <strong>{{.LastCommit.Author.Name}}</strong>
{{end}} {{end}}
<a rel="nofollow" class="ui sha label" href="{{.RepoLink}}/commit/{{.LastCommit.ID}}" rel="nofollow">{{ShortSha .LastCommit.ID.String}}</a> <a rel="nofollow" class="ui sha label" href="{{.RepoLink}}/commit/{{.LastCommit.ID}}" rel="nofollow">{{ShortSha .LastCommit.ID.String}}</a>
<span class="grey">{{RenderCommitMessage .LastCommit.Summary .RepoLink $.Repository.ComposeMetas}}</span> <span class="grey">{{RenderCommitMessage false .LastCommit.Summary .RepoLink $.Repository.ComposeMetas}}</span>
</th> </th>
<th class="nine wide"> <th class="nine wide">
</th> </th>
@ -44,7 +44,7 @@
{{end}} {{end}}
<td class="message collapsing"> <td class="message collapsing">
<a rel="nofollow" class="ui sha label" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{$commit.ID}}">{{ShortSha $commit.ID.String}}</a> <a rel="nofollow" class="ui sha label" href="{{AppSubUrl}}/{{$.Username}}/{{$.Reponame}}/commit/{{$commit.ID}}">{{ShortSha $commit.ID.String}}</a>
{{RenderCommitMessage $commit.Summary $.RepoLink $.Repository.ComposeMetas}} {{RenderCommitMessage false $commit.Summary $.RepoLink $.Repository.ComposeMetas}}
</td> </td>
<td class="text grey right age">{{TimeSince $commit.Committer.When $.Lang}}</td> <td class="text grey right age">{{TimeSince $commit.Committer.When $.Lang}}</td>
</tr> </tr>