Skip to content

Commit 7542929

Browse files
committed
Display the author and time of git notes
1 parent 89dc23f commit 7542929

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

modules/git/notes.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ package git
66

77
import (
88
"io/ioutil"
9+
10+
"gopkg.in/src-d/go-git.v4/plumbing"
911
)
1012

1113
// Note stores information about a note created using git-notes.
1214
type Note struct {
1315
Message []byte
16+
Commit *Commit
1417
}
1518

1619
// GetNote retrieves the git-notes data for a given commit.
@@ -36,7 +39,18 @@ func GetNote(repo *Repository, commitID string, note *Note) error {
3639
if err != nil {
3740
return err
3841
}
39-
4042
note.Message = d
43+
44+
commit, err := repo.gogitRepo.CommitObject(plumbing.Hash(notes.ID))
45+
if err != nil {
46+
return err
47+
}
48+
49+
lastCommits, err := getLastCommitForPaths(commit, "", []string{commitID})
50+
if err != nil {
51+
return err
52+
}
53+
note.Commit = convertCommit(lastCommits[commitID])
54+
4155
return nil
4256
}

routers/repo/commit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ func Diff(ctx *context.Context) {
252252
err = git.GetNote(ctx.Repo.GitRepo, commitID, &note)
253253
if err == nil {
254254
ctx.Data["Note"] = string(templates.ToUTF8WithFallback(note.Message))
255+
ctx.Data["NoteCommit"] = note.Commit
256+
ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit)
255257
}
256258

257259
if commit.ParentCount() > 0 {

templates/repo/diff/page.tmpl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,28 @@
6666
{{end}}
6767
{{end}}
6868
{{if .Note}}
69-
<div class="ui top bottom attached info clearing segment">
69+
<div class="ui top attached info clearing segment">
7070
<h3>{{.i18n.Tr "repo.diff.git-notes"}}</h3>
7171
<pre class="commit-body">{{RenderNote .Note $.RepoLink $.Repository.ComposeMetas}}</pre>
7272
</div>
73+
<div class="ui bottom attached info segment">
74+
<div class="ui stackable grid">
75+
<div class="nine wide column">
76+
{{if .NoteAuthor}}
77+
<img class="ui avatar image" src="{{.NoteAuthor.RelAvatarLink}}" />
78+
{{if .NoteAuthor.FullName}}
79+
<a href="{{.NoteAuthor.HomeLink}}"><strong>{{.NoteAuthor.FullName}}</strong></a>
80+
{{else}}
81+
<a href="{{.NoteAuthor.HomeLink}}"><strong>{{.NoteCommit.Author.Name}}</strong></a>
82+
{{end}}
83+
{{else}}
84+
<img class="ui avatar image" src="{{AvatarLink .NoteCommit.Author.Email}}" />
85+
<strong>{{.NoteCommit.Author.Name}}</strong>
86+
{{end}}
87+
<span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When $.Lang}}</span>
88+
</div>
89+
</div><!-- end grid -->
90+
</div>
7391
{{end}}
7492
{{end}}
7593

0 commit comments

Comments
 (0)