From 9a65d011f6b289dd6e7acb18a4b86c51d4d388ee Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 1 Aug 2023 15:25:11 +0800 Subject: [PATCH] Some fixes of the prompt of new branches (#26257) Related to #26239 This PR makes some fixes: - do not show the prompt for mirror repos and repos with pull request units disabled - use `commit_time` instead of `updated_unix`, as `commit_time` is the real time when the branch was pushed --- models/git/branch.go | 4 ++-- routers/web/repo/view.go | 16 ++++++++++++---- .../repo/code/recently_pushed_new_branches.tmpl | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index c68da1be78..6d50fb9fb6 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -395,9 +395,9 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, ex Where("pusher_id=? AND is_deleted=?", userID, false). And("name <> ?", excludeBranchName). And("repo_id = ?", repoID). - And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()). + And("commit_time >= ?", time.Now().Add(-time.Hour*6).Unix()). NotIn("name", subQuery). - OrderBy("branch.updated_unix DESC"). + OrderBy("branch.commit_time DESC"). Limit(2). Find(&branches) return branches, err diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 9e6b3e7825..15c85f6427 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -999,10 +999,18 @@ func renderCode(ctx *context.Context) { ctx.ServerError("GetBaseRepo", err) return } - ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.Repository.DefaultBranch) - if err != nil { - ctx.ServerError("GetRecentlyPushedBranches", err) - return + + showRecentlyPushedNewBranches := true + if ctx.Repo.Repository.IsMirror || + !ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypePullRequests) { + showRecentlyPushedNewBranches = false + } + if showRecentlyPushedNewBranches { + ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.Repository.DefaultBranch) + if err != nil { + ctx.ServerError("GetRecentlyPushedBranches", err) + return + } } } diff --git a/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index e936fa4bb4..ad68b15831 100644 --- a/templates/repo/code/recently_pushed_new_branches.tmpl +++ b/templates/repo/code/recently_pushed_new_branches.tmpl @@ -1,7 +1,7 @@ {{range .RecentlyPushedNewBranches}}
- {{$timeSince := TimeSince .UpdatedUnix.AsTime $.locale}} + {{$timeSince := TimeSince .CommitTime.AsTime $.locale}} {{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments .Name) $timeSince | Safe}}