Skip to content

Commit 9f1baa7

Browse files
GiteaBotlunnywxiaoguang
authored
Fix bug when displaying git user avatar in commits list (#35006)
A quick fix for #34991 Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent e13deb7 commit 9f1baa7

File tree

5 files changed

+58
-31
lines changed

5 files changed

+58
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ been added to each release, please refer to the [blog](https://blog.gitea.com).
77
## [1.24.3](https://github.com/go-gitea/gitea/releases/tag/1.24.3) - 2025-07-10
88

99
* BUGFIXES
10+
* Fix bug when displaying git user avatar in commits list (#35006)
1011
* Fix API response for swagger spec (#35029)
1112
* Start automerge check again after the conflict check and the schedule (#34988) (#35002)
1213
* Fix the response format for actions/workflows (#35009) (#35016)

models/user/user.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,12 +1176,14 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro
11761176

11771177
needCheckEmails := make(container.Set[string])
11781178
needCheckUserNames := make(container.Set[string])
1179+
noReplyAddressSuffix := "@" + strings.ToLower(setting.Service.NoReplyAddress)
11791180
for _, email := range emails {
1180-
if strings.HasSuffix(email, "@"+setting.Service.NoReplyAddress) {
1181-
username := strings.TrimSuffix(email, "@"+setting.Service.NoReplyAddress)
1182-
needCheckUserNames.Add(strings.ToLower(username))
1181+
emailLower := strings.ToLower(email)
1182+
if noReplyUserNameLower, ok := strings.CutSuffix(emailLower, noReplyAddressSuffix); ok {
1183+
needCheckUserNames.Add(noReplyUserNameLower)
1184+
needCheckEmails.Add(emailLower)
11831185
} else {
1184-
needCheckEmails.Add(strings.ToLower(email))
1186+
needCheckEmails.Add(emailLower)
11851187
}
11861188
}
11871189

models/user/user_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func TestUserEmails(t *testing.T) {
8585
testGetUserByEmail(t, c.Email, c.UID)
8686
})
8787
}
88+
t.Run("NoReplyConflict", func(t *testing.T) {
89+
setting.Service.NoReplyAddress = "example.com"
90+
testGetUserByEmail(t, "[email protected]", 1)
91+
})
8892
})
8993
}
9094

templates/repo/commits_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<td class="author">
1717
<div class="tw-flex">
1818
{{$userName := .Author.Name}}
19-
{{if .User}}
19+
{{if and .User (gt .User.ID 0)}}
2020
{{if and .User.FullName DefaultShowFullName}}
2121
{{$userName = .User.FullName}}
2222
{{end}}

tests/integration/repo_commits_test.go

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,59 @@ import (
2323

2424
func TestRepoCommits(t *testing.T) {
2525
defer tests.PrepareTestEnv(t)()
26-
2726
session := loginUser(t, "user2")
2827

29-
// Request repository commits page
30-
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
31-
resp := session.MakeRequest(t, req, http.StatusOK)
32-
33-
doc := NewHTMLParser(t, resp.Body)
34-
commitURL, exists := doc.doc.Find("#commits-table .commit-id-short").Attr("href")
35-
assert.True(t, exists)
36-
assert.NotEmpty(t, commitURL)
37-
}
28+
t.Run("CommitList", func(t *testing.T) {
29+
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
30+
resp := session.MakeRequest(t, req, http.StatusOK)
31+
32+
var commits, userHrefs []string
33+
doc := NewHTMLParser(t, resp.Body)
34+
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
35+
commits = append(commits, path.Base(s.AttrOr("href", "")))
36+
})
37+
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
38+
userHrefs = append(userHrefs, s.AttrOr("href", ""))
39+
})
40+
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324", "27566bd5738fc8b4e3fef3c5e72cce608537bd95", "5099b81332712fe655e34e8dd63574f503f61811"}, commits)
41+
assert.Equal(t, []string{"/user2", "/user21", "/user2"}, userHrefs)
42+
})
3843

39-
func Test_ReposGitCommitListNotMaster(t *testing.T) {
40-
defer tests.PrepareTestEnv(t)()
41-
session := loginUser(t, "user2")
42-
req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master")
43-
resp := session.MakeRequest(t, req, http.StatusOK)
44+
t.Run("LastCommit", func(t *testing.T) {
45+
req := NewRequest(t, "GET", "/user2/repo16")
46+
resp := session.MakeRequest(t, req, http.StatusOK)
47+
doc := NewHTMLParser(t, resp.Body)
48+
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
49+
authorHref := doc.doc.Find(".latest-commit .author-wrapper").AttrOr("href", "")
50+
assert.Equal(t, "/user2/repo16/commit/69554a64c1e6030f051e5c3f94bfbd773cd6a324", commitHref)
51+
assert.Equal(t, "/user2", authorHref)
52+
})
4453

45-
doc := NewHTMLParser(t, resp.Body)
46-
var commits []string
47-
doc.doc.Find("#commits-table .commit-id-short").Each(func(i int, s *goquery.Selection) {
48-
commitURL, _ := s.Attr("href")
49-
commits = append(commits, path.Base(commitURL))
54+
t.Run("CommitListNonExistingCommiter", func(t *testing.T) {
55+
// check the commit list for a repository with no gitea user
56+
// * commit 985f0301dba5e7b34be866819cd15ad3d8f508ee (branch2)
57+
// * Author: 6543 <[email protected]>
58+
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/branch2")
59+
resp := session.MakeRequest(t, req, http.StatusOK)
60+
61+
doc := NewHTMLParser(t, resp.Body)
62+
commitHref := doc.doc.Find("#commits-table tr:first-child .commit-id-short").AttrOr("href", "")
63+
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
64+
authorElem := doc.doc.Find("#commits-table tr:first-child .author-wrapper")
65+
assert.Equal(t, "6543", authorElem.Text())
66+
assert.Equal(t, "span", authorElem.Nodes[0].Data)
5067
})
51-
assert.Equal(t, []string{"69554a64c1e6030f051e5c3f94bfbd773cd6a324", "27566bd5738fc8b4e3fef3c5e72cce608537bd95", "5099b81332712fe655e34e8dd63574f503f61811"}, commits)
5268

53-
var userHrefs []string
54-
doc.doc.Find("#commits-table .author-wrapper").Each(func(i int, s *goquery.Selection) {
55-
userHref, _ := s.Attr("href")
56-
userHrefs = append(userHrefs, userHref)
69+
t.Run("LastCommitNonExistingCommiter", func(t *testing.T) {
70+
req := NewRequest(t, "GET", "/user2/repo1/src/branch/branch2")
71+
resp := session.MakeRequest(t, req, http.StatusOK)
72+
doc := NewHTMLParser(t, resp.Body)
73+
commitHref := doc.doc.Find(".latest-commit .commit-id-short").AttrOr("href", "")
74+
assert.Equal(t, "/user2/repo1/commit/985f0301dba5e7b34be866819cd15ad3d8f508ee", commitHref)
75+
authorElem := doc.doc.Find(".latest-commit .author-wrapper")
76+
assert.Equal(t, "6543", authorElem.Text())
77+
assert.Equal(t, "span", authorElem.Nodes[0].Data)
5778
})
58-
assert.Equal(t, []string{"/user2", "/user21", "/user2"}, userHrefs)
5979
}
6080

6181
func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {

0 commit comments

Comments
 (0)