From 79810ba2e37a5b5b7840a7737a877fc7f1ea7c38 Mon Sep 17 00:00:00 2001 From: puni9869 <80308335+puni9869@users.noreply.github.com> Date: Tue, 2 Jun 2026 12:38:23 +0530 Subject: [PATCH] fix: use committer time where ever possible as default (#37969) Fix https://github.com/go-gitea/gitea/issues/37857 --------- Co-authored-by: wxiaoguang --- MAINTAINERS | 2 +- routers/web/repo/wiki.go | 6 +++--- templates/repo/commit_page.tmpl | 3 +-- templates/repo/wiki/revision.tmpl | 4 ++-- templates/repo/wiki/view.tmpl | 4 ++-- tests/integration/repo_commits_test.go | 22 ++++++++++++++++++++++ 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 26192eff44..03ff6999f3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -64,4 +64,4 @@ metiftikci (@metiftikci) Christopher Homberger (@ChristopherHX) Tobias Balle-Petersen (@tobiasbp) TheFox (@TheFox0x7) -Nicolas (@bircni) \ No newline at end of file +Nicolas (@bircni) diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index 4d9cd21c13..dcb0c25829 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -496,7 +496,7 @@ func Wiki(ctx *context.Context) { ctx.ServerError("GetCommitByPath", err) return } - ctx.Data["Author"] = lastCommit.Author + ctx.Data["Committer"] = lastCommit.Committer ctx.HTML(http.StatusOK, tplWikiView) } @@ -528,7 +528,7 @@ func WikiRevision(ctx *context.Context) { ctx.ServerError("GetCommitByPath", err) return } - ctx.Data["Author"] = lastCommit.Author + ctx.Data["Committer"] = lastCommit.Committer ctx.HTML(http.StatusOK, tplWikiRevision) } @@ -587,7 +587,7 @@ func WikiPages(ctx *context.Context) { Name: displayName, SubURL: wiki_service.WebPathToURLPath(wikiName), GitEntryName: entry.Entry.Name(), - UpdatedUnix: timeutil.TimeStamp(entry.Commit.Author.When.Unix()), + UpdatedUnix: timeutil.TimeStamp(entry.Commit.Committer.When.Unix()), }) } ctx.Data["Pages"] = pages diff --git a/templates/repo/commit_page.tmpl b/templates/repo/commit_page.tmpl index 975cd303ec..9618eda761 100644 --- a/templates/repo/commit_page.tmpl +++ b/templates/repo/commit_page.tmpl @@ -139,8 +139,7 @@ {{.Commit.Author.Name}} {{end}} - - {{DateUtils.TimeSince .Commit.Author.When}} + {{DateUtils.TimeSince .Commit.Committer.When}}
{{if or (ne .Commit.Committer.Name .Commit.Author.Name) (ne .Commit.Committer.Email .Commit.Author.Email)}} diff --git a/templates/repo/wiki/revision.tmpl b/templates/repo/wiki/revision.tmpl index c59047a640..a9df43ea46 100644 --- a/templates/repo/wiki/revision.tmpl +++ b/templates/repo/wiki/revision.tmpl @@ -9,8 +9,8 @@
{{$title}}
- {{$timeSince := DateUtils.TimeSince .Author.When}} - {{ctx.Locale.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince}} + {{$timeSince := DateUtils.TimeSince .Committer.When}} + {{ctx.Locale.Tr "repo.wiki.last_commit_info" .Committer.Name $timeSince}}
diff --git a/templates/repo/wiki/view.tmpl b/templates/repo/wiki/view.tmpl index 4c7ef364d2..967a8814c9 100644 --- a/templates/repo/wiki/view.tmpl +++ b/templates/repo/wiki/view.tmpl @@ -37,8 +37,8 @@
{{$title}}
- {{$timeSince := DateUtils.TimeSince .Author.When}} - {{ctx.Locale.Tr "repo.wiki.last_commit_info" .Author.Name $timeSince}} + {{$timeSince := DateUtils.TimeSince .Committer.When}} + {{ctx.Locale.Tr "repo.wiki.last_commit_info" .Committer.Name $timeSince}}
diff --git a/tests/integration/repo_commits_test.go b/tests/integration/repo_commits_test.go index ab7119769f..9335ef7065 100644 --- a/tests/integration/repo_commits_test.go +++ b/tests/integration/repo_commits_test.go @@ -69,6 +69,28 @@ func TestRepoCommits(t *testing.T) { assert.Equal(t, "6543", strings.TrimSpace(authorElem.Text())) }) + t.Run("CommitPageUsesCommitterDate", func(t *testing.T) { + const ( + commitID = "5099b81332712fe655e34e8dd63574f503f61811" + expectedCommitterTime = "2017-08-06T19:56:13+02:00" + authorTime = "2017-08-06T19:55:01+02:00" + ) + + req := NewRequest(t, "GET", "/user2/repo16/commits/branch/master") + resp := session.MakeRequest(t, req, http.StatusOK) + doc := NewHTMLParser(t, resp.Body) + + var commitListTime string + doc.doc.Find("#commits-table tbody tr").EachWithBreak(func(_ int, row *goquery.Selection) bool { + if path.Base(row.Find(".commit-id-short").AttrOr("href", "")) != commitID { + return true + } + commitListTime = row.Find("td").Eq(3).Find("relative-time").AttrOr("datetime", "") + return false + }) + require.Equal(t, expectedCommitterTime, commitListTime) + }) + t.Run("LastCommitNonExistingCommiter", func(t *testing.T) { req := NewRequest(t, "GET", "/user2/repo1/src/branch/branch2") resp := session.MakeRequest(t, req, http.StatusOK)