mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-31 06:21:11 +00:00 
			
		
		
		
	Display the author and time of git notes
This commit is contained in:
		
					parent
					
						
							
								89dc23f359
							
						
					
				
			
			
				commit
				
					
						7542929a31
					
				
			
		
					 3 changed files with 36 additions and 2 deletions
				
			
		|  | @ -6,11 +6,14 @@ package git | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
|  | 
 | ||||||
|  | 	"gopkg.in/src-d/go-git.v4/plumbing" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // Note stores information about a note created using git-notes. | // Note stores information about a note created using git-notes. | ||||||
| type Note struct { | type Note struct { | ||||||
| 	Message []byte | 	Message []byte | ||||||
|  | 	Commit  *Commit | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetNote retrieves the git-notes data for a given 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 { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 |  | ||||||
| 	note.Message = d | 	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 | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -252,6 +252,8 @@ func Diff(ctx *context.Context) { | ||||||
| 	err = git.GetNote(ctx.Repo.GitRepo, commitID, ¬e) | 	err = git.GetNote(ctx.Repo.GitRepo, commitID, ¬e) | ||||||
| 	if err == nil { | 	if err == nil { | ||||||
| 		ctx.Data["Note"] = string(templates.ToUTF8WithFallback(note.Message)) | 		ctx.Data["Note"] = string(templates.ToUTF8WithFallback(note.Message)) | ||||||
|  | 		ctx.Data["NoteCommit"] = note.Commit | ||||||
|  | 		ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if commit.ParentCount() > 0 { | 	if commit.ParentCount() > 0 { | ||||||
|  |  | ||||||
|  | @ -66,10 +66,28 @@ | ||||||
| 				{{end}} | 				{{end}} | ||||||
| 			{{end}} | 			{{end}} | ||||||
| 			{{if .Note}} | 			{{if .Note}} | ||||||
| 				<div class="ui top bottom attached info clearing segment"> | 				<div class="ui top attached info clearing segment"> | ||||||
| 					<h3>{{.i18n.Tr "repo.diff.git-notes"}}</h3> | 					<h3>{{.i18n.Tr "repo.diff.git-notes"}}</h3> | ||||||
| 					<pre class="commit-body">{{RenderNote .Note $.RepoLink $.Repository.ComposeMetas}}</pre> | 					<pre class="commit-body">{{RenderNote .Note $.RepoLink $.Repository.ComposeMetas}}</pre> | ||||||
| 				</div> | 				</div> | ||||||
|  | 				<div class="ui bottom attached info segment"> | ||||||
|  | 					<div class="ui stackable grid"> | ||||||
|  | 						<div class="nine wide column"> | ||||||
|  | 							{{if .NoteAuthor}} | ||||||
|  | 								<img class="ui avatar image" src="{{.NoteAuthor.RelAvatarLink}}" /> | ||||||
|  | 							{{if .NoteAuthor.FullName}} | ||||||
|  | 							<a href="{{.NoteAuthor.HomeLink}}"><strong>{{.NoteAuthor.FullName}}</strong></a> | ||||||
|  | 							{{else}} | ||||||
|  | 							<a href="{{.NoteAuthor.HomeLink}}"><strong>{{.NoteCommit.Author.Name}}</strong></a> | ||||||
|  | 							{{end}} | ||||||
|  | 							{{else}} | ||||||
|  | 								<img class="ui avatar image" src="{{AvatarLink .NoteCommit.Author.Email}}" /> | ||||||
|  | 								<strong>{{.NoteCommit.Author.Name}}</strong> | ||||||
|  | 							{{end}} | ||||||
|  | 							<span class="text grey" id="note-authored-time">{{TimeSince .NoteCommit.Author.When $.Lang}}</span> | ||||||
|  | 						</div> | ||||||
|  | 					</div><!-- end grid --> | ||||||
|  | 				</div> | ||||||
| 			{{end}} | 			{{end}} | ||||||
| 		{{end}} | 		{{end}} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue