Skip to content

Commit 9a65d01

Browse files
authored
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
1 parent b9baed2 commit 9a65d01

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

models/git/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,9 @@ func FindRecentlyPushedNewBranches(ctx context.Context, repoID, userID int64, ex
395395
Where("pusher_id=? AND is_deleted=?", userID, false).
396396
And("name <> ?", excludeBranchName).
397397
And("repo_id = ?", repoID).
398-
And("updated_unix >= ?", time.Now().Add(-time.Hour*6).Unix()).
398+
And("commit_time >= ?", time.Now().Add(-time.Hour*6).Unix()).
399399
NotIn("name", subQuery).
400-
OrderBy("branch.updated_unix DESC").
400+
OrderBy("branch.commit_time DESC").
401401
Limit(2).
402402
Find(&branches)
403403
return branches, err

routers/web/repo/view.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -999,10 +999,18 @@ func renderCode(ctx *context.Context) {
999999
ctx.ServerError("GetBaseRepo", err)
10001000
return
10011001
}
1002-
ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.Repository.DefaultBranch)
1003-
if err != nil {
1004-
ctx.ServerError("GetRecentlyPushedBranches", err)
1005-
return
1002+
1003+
showRecentlyPushedNewBranches := true
1004+
if ctx.Repo.Repository.IsMirror ||
1005+
!ctx.Repo.Repository.UnitEnabled(ctx, unit_model.TypePullRequests) {
1006+
showRecentlyPushedNewBranches = false
1007+
}
1008+
if showRecentlyPushedNewBranches {
1009+
ctx.Data["RecentlyPushedNewBranches"], err = git_model.FindRecentlyPushedNewBranches(ctx, ctx.Repo.Repository.ID, ctx.Doer.ID, ctx.Repo.Repository.DefaultBranch)
1010+
if err != nil {
1011+
ctx.ServerError("GetRecentlyPushedBranches", err)
1012+
return
1013+
}
10061014
}
10071015
}
10081016

templates/repo/code/recently_pushed_new_branches.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{range .RecentlyPushedNewBranches}}
22
<div class="ui positive message gt-df gt-ac">
33
<div class="gt-f1">
4-
{{$timeSince := TimeSince .UpdatedUnix.AsTime $.locale}}
4+
{{$timeSince := TimeSince .CommitTime.AsTime $.locale}}
55
{{$.locale.Tr "repo.pulls.recently_pushed_new_branches" (PathEscapeSegments .Name) $timeSince | Safe}}
66
</div>
77
<a aria-role="button" class="ui compact positive button gt-m-0" href="{{$.Repository.ComposeBranchCompareURL $.Repository.BaseRepo (PathEscapeSegments .Name)}}">

0 commit comments

Comments
 (0)