From 0e074ac75d47e92e07766b9691bd61af1a8b6cc1 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Mon, 31 Jul 2023 18:03:55 +0800 Subject: [PATCH 1/3] don't show newly pushed branch prompt in some cases --- routers/web/repo/view.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 221c1f4c4f62b..0080a7ad112aa 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -23,6 +23,7 @@ import ( git_model "code.gitea.io/gitea/models/git" issue_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unit" unit_model "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/actions" @@ -982,10 +983,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.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 + } } } From 86a81350c826c3506b3c6e75830ddd99dbfab250 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 1 Aug 2023 09:13:09 +0800 Subject: [PATCH 2/3] use CommitTime --- models/git/branch.go | 4 ++-- templates/repo/code/recently_pushed_new_branches.tmpl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/models/git/branch.go b/models/git/branch.go index c68da1be78062..6d50fb9fb6a18 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/templates/repo/code/recently_pushed_new_branches.tmpl b/templates/repo/code/recently_pushed_new_branches.tmpl index e936fa4bb462b..ad68b15831508 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}}