Skip to content

Commit ec62061

Browse files
committed
Included tag search capabilities
Signed-off-by: Bruno Sofiato <[email protected]>
1 parent f528df9 commit ec62061

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

Diff for: models/repo/release.go

+6
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ type FindReleasesOptions struct {
234234
IsDraft optional.Option[bool]
235235
TagNames []string
236236
HasSha1 optional.Option[bool] // useful to find draft releases which are created with existing tags
237+
NamePattern optional.Option[string]
237238
}
238239

239240
func (opts FindReleasesOptions) ToConds() builder.Cond {
@@ -261,6 +262,11 @@ func (opts FindReleasesOptions) ToConds() builder.Cond {
261262
cond = cond.And(builder.Eq{"sha1": ""})
262263
}
263264
}
265+
266+
if opts.NamePattern.Has() && opts.NamePattern.Value() != "" {
267+
cond = cond.And(builder.Like{"lower_tag_name", strings.ToLower(opts.NamePattern.Value())})
268+
}
269+
264270
return cond
265271
}
266272

Diff for: options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ code_search_by_git_grep = Current code search results are provided by "git grep"
178178
package_kind = Search packages...
179179
project_kind = Search projects...
180180
branch_kind = Search branches...
181+
tag_kind = Search tags...
182+
tag_tooltip = Search for matching tags. Use '%' to match any sequence of numbers.
181183
commit_kind = Search commits...
182184
runner_kind = Search runners...
183185
no_results = No matching results found.

Diff for: routers/web/repo/release.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ func TagsList(ctx *context.Context) {
214214
ctx.Data["HideBranchesInDropdown"] = true
215215
ctx.Data["CanCreateRelease"] = ctx.Repo.CanWrite(unit.TypeReleases) && !ctx.Repo.Repository.IsArchived
216216

217+
namePattern := ctx.FormTrim("q")
218+
217219
listOptions := db.ListOptions{
218220
Page: ctx.FormInt("page"),
219221
PageSize: ctx.FormInt("limit"),
@@ -233,6 +235,7 @@ func TagsList(ctx *context.Context) {
233235
IncludeTags: true,
234236
HasSha1: optional.Some(true),
235237
RepoID: ctx.Repo.Repository.ID,
238+
NamePattern: optional.Some(namePattern),
236239
}
237240

238241
releases, err := db.Find[repo_model.Release](ctx, opts)
@@ -241,14 +244,21 @@ func TagsList(ctx *context.Context) {
241244
return
242245
}
243246

247+
count, err := db.Count[repo_model.Release](ctx, opts)
248+
if err != nil {
249+
ctx.ServerError("GetReleasesByRepoID", err)
250+
return
251+
}
252+
253+
ctx.Data["Keyword"] = namePattern
244254
ctx.Data["Releases"] = releases
255+
ctx.Data["TagCount"] = count
245256

246-
numTags := ctx.Data["NumTags"].(int64)
247-
pager := context.NewPagination(int(numTags), opts.PageSize, opts.Page, 5)
257+
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
248258
pager.SetDefaultParams(ctx)
249259
ctx.Data["Page"] = pager
250-
251260
ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases)
261+
252262
ctx.HTML(http.StatusOK, tplTagsList)
253263
}
254264

Diff for: templates/repo/tag/list.tmpl

+12-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
<div class="ui container">
55
{{template "base/alert" .}}
66
{{template "repo/release_tag_header" .}}
7-
{{if .Releases}}
87
<h4 class="ui top attached header">
98
<div class="five wide column tw-flex tw-items-center">
10-
{{svg "octicon-tag" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.release.tags"}}
9+
{{.TagCount}} {{ctx.Locale.Tr "repo.release.tags"}}
1110
</div>
1211
</h4>
1312
{{$canReadReleases := $.Permission.CanRead ctx.Consts.RepoUnitTypeReleases}}
13+
<div class="ui attached segment">
14+
<form class="ignore-dirty" method="get">
15+
{{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.tag_kind") "Tooltip" (ctx.Locale.Tr "search.tag_tooltip")}}
16+
</form>
17+
</div>
1418
<div class="ui attached table segment">
19+
{{if .Releases}}
1520
<table class="ui very basic striped fixed table single line" id="tags-table">
1621
<tbody class="tag-list">
1722
{{range $idx, $release := .Releases}}
@@ -57,9 +62,12 @@
5762
{{end}}
5863
</tbody>
5964
</table>
65+
{{else}}
66+
{{if .NumTags}}
67+
<p class="tw-p-4">{{ctx.Locale.Tr "no_results_found"}}</p>
68+
{{end}}
69+
{{end}}
6070
</div>
61-
{{end}}
62-
6371
{{template "base/paginate" .}}
6472
</div>
6573
</div>

0 commit comments

Comments
 (0)