From ed51686240ff84e3cc12be8bc4311c529d44faee Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Sat, 4 Feb 2023 12:22:37 +0800 Subject: refactor(db): migrate methods off `user.go` (#7333) --- internal/route/repo/commit.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'internal/route/repo/commit.go') diff --git a/internal/route/repo/commit.go b/internal/route/repo/commit.go index 3e09bd06..da8c5e48 100644 --- a/internal/route/repo/commit.go +++ b/internal/route/repo/commit.go @@ -5,6 +5,7 @@ package repo import ( + gocontext "context" "path" "time" @@ -110,6 +111,13 @@ func FileHistory(c *context.Context) { renderCommits(c, c.Repo.TreePath) } +// tryGetUserByEmail returns a non-nil value if the email is corresponding to an +// existing user. +func tryGetUserByEmail(ctx gocontext.Context, email string) *db.User { + user, _ := db.Users.GetByEmail(ctx, email) + return user +} + func Diff(c *context.Context) { c.PageIs("Diff") c.RequireHighlightJS() @@ -156,7 +164,7 @@ func Diff(c *context.Context) { c.Data["IsImageFile"] = commit.IsImageFile c.Data["IsImageFileByIndex"] = commit.IsImageFileByIndex c.Data["Commit"] = commit - c.Data["Author"] = db.ValidateCommitWithEmail(commit) + c.Data["Author"] = tryGetUserByEmail(c.Req.Context(), commit.Author.Email) c.Data["Diff"] = diff c.Data["Parents"] = parents c.Data["DiffNotAvailable"] = diff.NumFiles() == 0 -- cgit v1.2.3