Skip to content

Commit 151d8cd

Browse files
matera-bsbsofiato
andauthored
[Cherry picked from v1.22.3] Included tag search capabilities (go-gitea#32045) (#3)
Resolves go-gitea#31998 The first screenshot shows the tag page without any filter being applied: ![image](https://github.com/user-attachments/assets/eac0e51c-9e48-42b2-bb1c-a25896ca40cb) The second one, shows the page when the given filter returns no tag: ![image](https://github.com/user-attachments/assets/98df191e-1a7b-4947-b0ef-4987a0293c3e) The last one shows a single tag being filtered: ![image](https://github.com/user-attachments/assets/79c7e05e-8c86-4f06-b17e-15818b7b9291) Signed-off-by: Bruno Sofiato <[email protected]> Co-authored-by: Bruno Sofiato <[email protected]>
1 parent 5052549 commit 151d8cd

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

models/repo/release.go

Lines changed: 6 additions & 0 deletions
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

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ code_search_by_git_grep = Current code search results are provided by "git grep"
176176
package_kind = Search packages...
177177
project_kind = Search projects...
178178
branch_kind = Search branches...
179+
tag_kind = Search tags...
180+
tag_tooltip = Search for matching tags. Use '%' to match any sequence of numbers.
179181
commit_kind = Search commits...
180182
runner_kind = Search runners...
181183
no_results = No matching results found.

routers/web/repo/release.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ func TagsList(ctx *context.Context) {
212212
ctx.Data["HideBranchesInDropdown"] = true
213213
ctx.Data["CanCreateRelease"] = ctx.Repo.CanWrite(unit.TypeReleases) && !ctx.Repo.Repository.IsArchived
214214

215+
namePattern := ctx.FormTrim("q")
216+
215217
listOptions := db.ListOptions{
216218
Page: ctx.FormInt("page"),
217219
PageSize: ctx.FormInt("limit"),
@@ -231,6 +233,7 @@ func TagsList(ctx *context.Context) {
231233
IncludeTags: true,
232234
HasSha1: optional.Some(true),
233235
RepoID: ctx.Repo.Repository.ID,
236+
NamePattern: optional.Some(namePattern),
234237
}
235238

236239
releases, err := db.Find[repo_model.Release](ctx, opts)
@@ -239,14 +242,21 @@ func TagsList(ctx *context.Context) {
239242
return
240243
}
241244

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

244-
numTags := ctx.Data["NumTags"].(int64)
245-
pager := context.NewPagination(int(numTags), opts.PageSize, opts.Page, 5)
255+
pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5)
246256
pager.SetDefaultParams(ctx)
247257
ctx.Data["Page"] = pager
248-
249258
ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases)
259+
250260
ctx.HTML(http.StatusOK, tplTagsList)
251261
}
252262

templates/repo/tag/list.tmpl

Lines changed: 12 additions & 4 deletions
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)