diff --git a/templates/repo/commit_author.tmpl b/templates/repo/commit_author.tmpl
new file mode 100644
index 0000000000000..4b96c55f3c51b
--- /dev/null
+++ b/templates/repo/commit_author.tmpl
@@ -0,0 +1,55 @@
+{{/* Template Attributes:
+* User: The user associated with the commit, if any
+* Commit: The commit
+* Author: The author, currently only the commit page passes this
+* AvatarSize: Avatar size in pixels
+* AuthorBold: Whether to render the author as bold text
+*/}}
+
+ {{if .User}}
+ {{ctx.AvatarUtils.Avatar .User .AvatarSize}}
+ {{$username := ""}}
+ {{if and .User.FullName DefaultShowFullName}}
+ {{$username = .User.FullName}}
+ {{else if .User.Name}}
+ {{$username = .User.Name}}
+ {{end}}
+
+ {{$username}}
+
+ {{else if .Author}}
+ {{$username := ""}}
+ {{if and .Author.FullName DefaultShowFullName}}
+ {{$username = .Author.FullName}}
+ {{else if .Author.Name}}
+ {{$username = .Author.Name}}
+ {{else if .Commit.Author.Name}}
+ {{$username = .Commit.Author.Name}}
+ {{end}}
+ {{ctx.AvatarUtils.AvatarByEmail .Author.Email $username .AvatarSize}}
+
+ {{if .Author.HomeLink}}
+
+ {{$username}}
+
+ {{else}}
+ {{$username}}
+ {{end}}
+
+ {{else}}
+ {{$username := ""}}
+ {{if .Commit.Author.Name}}
+ {{$username = .Commit.Author.Name}}
+ {{else}}
+ {{$username = .Author.Name}}
+ {{end}}
+ {{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email $username .AvatarSize}}
+
+ {{if .Commit.Author.Name}}
+ {{.Commit.Author.Name}}
+ {{else}}
+ {{.Author.Name}}
+ {{end}}
+
+ {{end}}
+
diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl
index 68ccf9d275f4a..c086a53624f6c 100644
--- a/templates/repo/commit_page.tmpl
+++ b/templates/repo/commit_page.tmpl
@@ -128,19 +128,12 @@
-
- {{if .Author}}
- {{ctx.AvatarUtils.Avatar .Author 20}}
- {{if .Author.FullName}}
-
{{.Author.FullName}}
- {{else}}
-
{{.Commit.Author.Name}}
- {{end}}
- {{else}}
- {{ctx.AvatarUtils.AvatarByEmail .Commit.Author.Email .Commit.Author.Email 20}}
-
{{.Commit.Author.Name}}
- {{end}}
-
+ {{template "repo/commit_author" (dict
+ "Commit" .Commit
+ "Author" .Author
+ "AvatarSize" 20
+ "AuthorBold" true
+ )}}
{{DateUtils.TimeSince .Commit.Author.When}}
diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl
index 959f2a9398575..0ab466d407c99 100644
--- a/templates/repo/commits_list.tmpl
+++ b/templates/repo/commits_list.tmpl
@@ -15,16 +15,11 @@
- {{$userName := .Author.Name}}
- {{if .User}}
- {{if and .User.FullName DefaultShowFullName}}
- {{$userName = .User.FullName}}
- {{end}}
- {{ctx.AvatarUtils.Avatar .User 28 "tw-mr-2"}} {{$userName}}
- {{else}}
- {{ctx.AvatarUtils.AvatarByEmail .Author.Email .Author.Name 28 "tw-mr-2"}}
- {{$userName}}
- {{end}}
+ {{template "repo/commit_author" (dict
+ "Commit" .
+ "User" .User
+ "AvatarSize" 28
+ )}}
|
diff --git a/templates/repo/latest_commit.tmpl b/templates/repo/latest_commit.tmpl
index cff338949f219..5b2bdfcb6e343 100644
--- a/templates/repo/latest_commit.tmpl
+++ b/templates/repo/latest_commit.tmpl
@@ -2,20 +2,12 @@
{{if not .LatestCommit}}
…
{{else}}
- {{if .LatestCommitUser}}
- {{ctx.AvatarUtils.Avatar .LatestCommitUser 24}}
- {{if and .LatestCommitUser.FullName DefaultShowFullName}}
- {{.LatestCommitUser.FullName}}
- {{else}}
- {{if .LatestCommit.Author}}{{.LatestCommit.Author.Name}}{{else}}{{.LatestCommitUser.Name}}{{end}}
- {{end}}
- {{else}}
- {{if .LatestCommit.Author}}
- {{ctx.AvatarUtils.AvatarByEmail .LatestCommit.Author.Email .LatestCommit.Author.Name 24}}
- {{.LatestCommit.Author.Name}}
- {{end}}
- {{end}}
-
+ {{template "repo/commit_author" (dict
+ "User" .LatestCommitUser
+ "Commit" .LatestCommit
+ "AvatarSize" 24
+ "AuthorBold" true
+ )}}
{{template "repo/commit_sign_badge" dict "Commit" .LatestCommit "CommitBaseLink" (print .RepoLink "/commit") "CommitSignVerification" .LatestCommitVerification}}
{{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses}}
diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go
index b8f086e2b15ce..c611ecf3f48c0 100644
--- a/tests/integration/repo_commits_test.go
+++ b/tests/integration/repo_commits_test.go
@@ -8,6 +8,7 @@ import (
"net/http"
"net/http/httptest"
"path"
+ "strings"
"sync"
"testing"
@@ -63,7 +64,7 @@ func TestRepoCommits(t *testing.T) {
commitHref := doc.doc.Find("#commits-table tr:first-child .commit-id-short").AttrOr("href", "")
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
authorElem := doc.doc.Find("#commits-table tr:first-child .author-wrapper")
- assert.Equal(t, "6543", authorElem.Text())
+ assert.Equal(t, "6543", strings.TrimSpace(authorElem.Text()))
assert.Equal(t, "span", authorElem.Nodes[0].Data)
})
@@ -74,7 +75,7 @@ func TestRepoCommits(t *testing.T) {
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
authorElem := doc.doc.Find(".latest-commit .author-wrapper")
- assert.Equal(t, "6543", authorElem.Text())
+ assert.Equal(t, "6543", strings.TrimSpace(authorElem.Text()))
assert.Equal(t, "span", authorElem.Nodes[0].Data)
})
}
|