From 7542929a3125d03cefe480dbd62877d9bdfeb912 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Mon, 20 May 2019 14:31:27 +0000 Subject: [PATCH] Display the author and time of git notes --- modules/git/notes.go | 16 +++++++++++++++- routers/repo/commit.go | 2 ++ templates/repo/diff/page.tmpl | 20 +++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/git/notes.go b/modules/git/notes.go index 65242f4581..574f5adc3e 100644 --- a/modules/git/notes.go +++ b/modules/git/notes.go @@ -6,11 +6,14 @@ package git import ( "io/ioutil" + + "gopkg.in/src-d/go-git.v4/plumbing" ) // Note stores information about a note created using git-notes. type Note struct { Message []byte + Commit *Commit } // GetNote retrieves the git-notes data for a given commit. @@ -36,7 +39,18 @@ func GetNote(repo *Repository, commitID string, note *Note) error { if err != nil { return err } - note.Message = d + + commit, err := repo.gogitRepo.CommitObject(plumbing.Hash(notes.ID)) + if err != nil { + return err + } + + lastCommits, err := getLastCommitForPaths(commit, "", []string{commitID}) + if err != nil { + return err + } + note.Commit = convertCommit(lastCommits[commitID]) + return nil } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index b7208d74e9..4a19db2c1b 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -252,6 +252,8 @@ func Diff(ctx *context.Context) { err = git.GetNote(ctx.Repo.GitRepo, commitID, ¬e) if err == nil { ctx.Data["Note"] = string(templates.ToUTF8WithFallback(note.Message)) + ctx.Data["NoteCommit"] = note.Commit + ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit) } if commit.ParentCount() > 0 { diff --git a/templates/repo/diff/page.tmpl b/templates/repo/diff/page.tmpl index 016d92a8f4..9fee2b3221 100644 --- a/templates/repo/diff/page.tmpl +++ b/templates/repo/diff/page.tmpl @@ -66,10 +66,28 @@ {{end}} {{end}} {{if .Note}} -
+

{{.i18n.Tr "repo.diff.git-notes"}}

{{RenderNote .Note $.RepoLink $.Repository.ComposeMetas}}
+
+
+
+ {{if .NoteAuthor}} + + {{if .NoteAuthor.FullName}} + {{.NoteAuthor.FullName}} + {{else}} + {{.NoteCommit.Author.Name}} + {{end}} + {{else}} + + {{.NoteCommit.Author.Name}} + {{end}} + {{TimeSince .NoteCommit.Author.When $.Lang}} +
+
+
{{end}} {{end}}