Skip to content

Commit 47b8788

Browse files
authored
1 parent dcf4b9e commit 47b8788

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

models/git/branch_list.go

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type FindBranchOptions struct {
7070
ExcludeBranchNames []string
7171
IsDeletedBranch util.OptionalBool
7272
OrderBy string
73+
Keyword string
7374
}
7475

7576
func (opts *FindBranchOptions) Cond() builder.Cond {
@@ -84,6 +85,9 @@ func (opts *FindBranchOptions) Cond() builder.Cond {
8485
if !opts.IsDeletedBranch.IsNone() {
8586
cond = cond.And(builder.Eq{"is_deleted": opts.IsDeletedBranch.IsTrue()})
8687
}
88+
if opts.Keyword != "" {
89+
cond = cond.And(builder.Like{"name", opts.Keyword})
90+
}
8791
return cond
8892
}
8993

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,7 @@ branch.default_deletion_failed = Branch "%s" is the default branch. It cannot be
25152515
branch.restore = Restore Branch "%s"
25162516
branch.download = Download Branch "%s"
25172517
branch.rename = Rename Branch "%s"
2518+
branch.search = Search Branch
25182519
branch.included_desc = This branch is part of the default branch
25192520
branch.included = Included
25202521
branch.create_new_branch = Create branch from branch:

routers/web/repo/branch.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ func Branches(ctx *context.Context) {
5151
}
5252
pageSize := setting.Git.BranchesRangeSize
5353

54-
defaultBranch, branches, branchesCount, err := repo_service.LoadBranches(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, util.OptionalBoolNone, page, pageSize)
54+
kw := ctx.FormString("q")
55+
56+
defaultBranch, branches, branchesCount, err := repo_service.LoadBranches(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, util.OptionalBoolNone, kw, page, pageSize)
5557
if err != nil {
5658
ctx.ServerError("LoadBranches", err)
5759
return
@@ -73,6 +75,7 @@ func Branches(ctx *context.Context) {
7375
commitStatus[commitID] = git_model.CalcCommitStatus(cs)
7476
}
7577

78+
ctx.Data["Keyword"] = kw
7679
ctx.Data["Branches"] = branches
7780
ctx.Data["CommitStatus"] = commitStatus
7881
ctx.Data["CommitStatuses"] = commitStatuses

services/repository/branch.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Branch struct {
6666
}
6767

6868
// LoadBranches loads branches from the repository limited by page & pageSize.
69-
func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch util.OptionalBool, page, pageSize int) (*Branch, []*Branch, int64, error) {
69+
func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, isDeletedBranch util.OptionalBool, keyword string, page, pageSize int) (*Branch, []*Branch, int64, error) {
7070
defaultDBBranch, err := git_model.GetBranch(ctx, repo.ID, repo.DefaultBranch)
7171
if err != nil {
7272
return nil, nil, 0, err
@@ -79,6 +79,7 @@ func LoadBranches(ctx context.Context, repo *repo_model.Repository, gitRepo *git
7979
Page: page,
8080
PageSize: pageSize,
8181
},
82+
Keyword: keyword,
8283
}
8384

8485
totalNumOfBranches, err := git_model.CountBranches(ctx, branchOpts)

templates/repo/branch/list.tmpl

+13-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,20 @@
7070
{{end}}
7171

7272
{{if .Branches}}
73-
<h4 class="ui top attached header">
74-
{{.locale.Tr "repo.branches"}}
73+
<h4 class="ui top attached header gt-df gt-ac gt-sb">
74+
<div class="gt-df gt-ac">
75+
{{.locale.Tr "repo.branches"}}
76+
</div>
77+
<div class="gt-whitespace-nowrap">
78+
<form class="ignore-dirty" method="get">
79+
<div class="ui tiny search input">
80+
<input name="q" placeholder="{{.locale.Tr "repo.branch.search"}}" value="{{.Keyword}}" autofocus>
81+
</div>
82+
<button class="ui primary tiny button gt-mr-0" data-tooltip-content={{.locale.Tr "repo.commits.search.tooltip"}}>{{.locale.Tr "repo.commits.find"}}</button>
83+
</form>
84+
</div>
7585
</h4>
86+
7687
<div class="ui attached table segment">
7788
<table class="ui very basic striped fixed table single line">
7889
<tbody>

0 commit comments

Comments
 (0)