mirror of
https://github.com/go-gitea/gitea
synced 2024-11-15 06:34:25 +00:00
Show git-notes
This commit is contained in:
parent
c385dcc26b
commit
f7f000a097
@ -125,6 +125,7 @@ func NewFuncMap() []template.FuncMap {
|
|||||||
"RenderCommitMessage": RenderCommitMessage,
|
"RenderCommitMessage": RenderCommitMessage,
|
||||||
"RenderCommitMessageLink": RenderCommitMessageLink,
|
"RenderCommitMessageLink": RenderCommitMessageLink,
|
||||||
"RenderCommitBody": RenderCommitBody,
|
"RenderCommitBody": RenderCommitBody,
|
||||||
|
"RenderNote": RenderNote,
|
||||||
"IsMultilineCommitMessage": IsMultilineCommitMessage,
|
"IsMultilineCommitMessage": IsMultilineCommitMessage,
|
||||||
"ThemeColorMetaTag": func() string {
|
"ThemeColorMetaTag": func() string {
|
||||||
return setting.UI.ThemeColorMetaTag
|
return setting.UI.ThemeColorMetaTag
|
||||||
@ -392,6 +393,17 @@ func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.H
|
|||||||
return template.HTML(strings.Join(body[1:], "\n"))
|
return template.HTML(strings.Join(body[1:], "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RenderNote renders the contents of a git-notes file as a commit message.
|
||||||
|
func RenderNote(msg, urlPrefix string, metas map[string]string) template.HTML {
|
||||||
|
cleanMsg := template.HTMLEscapeString(msg)
|
||||||
|
fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("RenderNote: %v", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return template.HTML(string(fullMessage))
|
||||||
|
}
|
||||||
|
|
||||||
// IsMultilineCommitMessage checks to see if a commit message contains multiple lines.
|
// IsMultilineCommitMessage checks to see if a commit message contains multiple lines.
|
||||||
func IsMultilineCommitMessage(msg string) bool {
|
func IsMultilineCommitMessage(msg string) bool {
|
||||||
return strings.Count(strings.TrimSpace(msg), "\n") >= 1
|
return strings.Count(strings.TrimSpace(msg), "\n") >= 1
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -246,6 +248,23 @@ func Diff(ctx *context.Context) {
|
|||||||
ctx.Data["Parents"] = parents
|
ctx.Data["Parents"] = parents
|
||||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
||||||
ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", commitID)
|
ctx.Data["SourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", commitID)
|
||||||
|
|
||||||
|
notes, err := ctx.Repo.GitRepo.GetCommit("refs/notes/commits")
|
||||||
|
if err == nil {
|
||||||
|
entry, err := notes.GetTreeEntryByPath(commitID)
|
||||||
|
if err == nil {
|
||||||
|
blob := entry.Blob()
|
||||||
|
dataRc, err := blob.DataAsync()
|
||||||
|
if err == nil {
|
||||||
|
d, err := ioutil.ReadAll(dataRc)
|
||||||
|
dataRc.Close()
|
||||||
|
if err == nil {
|
||||||
|
ctx.Data["Note"] = string(templates.ToUTF8WithFallback(d))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if commit.ParentCount() > 0 {
|
if commit.ParentCount() > 0 {
|
||||||
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", parents[0])
|
ctx.Data["BeforeSourcePath"] = setting.AppSubURL + "/" + path.Join(userName, repoName, "src", "commit", parents[0])
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,12 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{if .Note}}
|
||||||
|
<div class="ui top bottom attached info clearing segment">
|
||||||
|
<h3>git-notes:</h3>
|
||||||
|
<pre class="commit-body">{{RenderNote .Note $.RepoLink $.Repository.ComposeMetas}}</pre>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{template "repo/diff/box" .}}
|
{{template "repo/diff/box" .}}
|
||||||
|
Loading…
Reference in New Issue
Block a user