Skip to content

Commit f7f000a

Browse files
committed
Show git-notes
1 parent c385dcc commit f7f000a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

modules/templates/helper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func NewFuncMap() []template.FuncMap {
125125
"RenderCommitMessage": RenderCommitMessage,
126126
"RenderCommitMessageLink": RenderCommitMessageLink,
127127
"RenderCommitBody": RenderCommitBody,
128+
"RenderNote": RenderNote,
128129
"IsMultilineCommitMessage": IsMultilineCommitMessage,
129130
"ThemeColorMetaTag": func() string {
130131
return setting.UI.ThemeColorMetaTag
@@ -392,6 +393,17 @@ func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.H
392393
return template.HTML(strings.Join(body[1:], "\n"))
393394
}
394395

396+
// RenderNote renders the contents of a git-notes file as a commit message.
397+
func RenderNote(msg, urlPrefix string, metas map[string]string) template.HTML {
398+
cleanMsg := template.HTMLEscapeString(msg)
399+
fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas)
400+
if err != nil {
401+
log.Error("RenderNote: %v", err)
402+
return ""
403+
}
404+
return template.HTML(string(fullMessage))
405+
}
406+
395407
// IsMultilineCommitMessage checks to see if a commit message contains multiple lines.
396408
func IsMultilineCommitMessage(msg string) bool {
397409
return strings.Count(strings.TrimSpace(msg), "\n") >= 1

routers/repo/commit.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package repo
77

88
import (
9+
"io/ioutil"
910
"path"
1011
"strings"
1112

@@ -15,6 +16,7 @@ import (
1516
"code.gitea.io/gitea/modules/git"
1617
"code.gitea.io/gitea/modules/log"
1718
"code.gitea.io/gitea/modules/setting"
19+
"code.gitea.io/gitea/modules/templates"
1820
)
1921

2022
const (
@@ -246,6 +248,23 @@ func Diff(ctx *context.Context) {
246248
ctx.Data["Parents"] = parents
247249
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
248250
ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", commitID)
251+
252+
notes, err := ctx.Repo.GitRepo.GetCommit("refs/notes/commits")
253+
if err == nil {
254+
entry, err := notes.GetTreeEntryByPath(commitID)
255+
if err == nil {
256+
blob := entry.Blob()
257+
dataRc, err := blob.DataAsync()
258+
if err == nil {
259+
d, err := ioutil.ReadAll(dataRc)
260+
dataRc.Close()
261+
if err == nil {
262+
ctx.Data["Note"] = string(templates.ToUTF8WithFallback(d))
263+
}
264+
}
265+
}
266+
}
267+
249268
if commit.ParentCount() > 0 {
250269
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", parents[0])
251270
}

templates/repo/diff/page.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
</div>
6666
{{end}}
6767
{{end}}
68+
{{if .Note}}
69+
<div class="ui top bottom attached info clearing segment">
70+
<h3>git-notes:</h3>
71+
<pre class="commit-body">{{RenderNote .Note $.RepoLink $.Repository.ComposeMetas}}</pre>
72+
</div>
73+
{{end}}
6874
{{end}}
6975

7076
{{template "repo/diff/box" .}}

0 commit comments

Comments
 (0)