diff --git a/models/repo/release.go b/models/repo/release.go index 1643258301..7c66cbc1af 100644 --- a/models/repo/release.go +++ b/models/repo/release.go @@ -234,6 +234,7 @@ type FindReleasesOptions struct { IsDraft optional.Option[bool] TagNames []string HasSha1 optional.Option[bool] // useful to find draft releases which are created with existing tags + NamePattern optional.Option[string] } func (opts FindReleasesOptions) ToConds() builder.Cond { @@ -261,6 +262,11 @@ func (opts FindReleasesOptions) ToConds() builder.Cond { cond = cond.And(builder.Eq{"sha1": ""}) } } + + if opts.NamePattern.Has() && opts.NamePattern.Value() != "" { + cond = cond.And(builder.Like{"lower_tag_name", strings.ToLower(opts.NamePattern.Value())}) + } + return cond } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 601671d8b9..951994253a 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -178,6 +178,8 @@ code_search_by_git_grep = Current code search results are provided by "git grep" package_kind = Search packages... project_kind = Search projects... branch_kind = Search branches... +tag_kind = Search tags... +tag_tooltip = Search for matching tags. Use '%' to match any sequence of numbers. commit_kind = Search commits... runner_kind = Search runners... no_results = No matching results found. diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index a283303492..f551fffe95 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -214,6 +214,8 @@ func TagsList(ctx *context.Context) { ctx.Data["HideBranchesInDropdown"] = true ctx.Data["CanCreateRelease"] = ctx.Repo.CanWrite(unit.TypeReleases) && !ctx.Repo.Repository.IsArchived + namePattern := ctx.FormTrim("q") + listOptions := db.ListOptions{ Page: ctx.FormInt("page"), PageSize: ctx.FormInt("limit"), @@ -233,6 +235,7 @@ func TagsList(ctx *context.Context) { IncludeTags: true, HasSha1: optional.Some(true), RepoID: ctx.Repo.Repository.ID, + NamePattern: optional.Some(namePattern), } releases, err := db.Find[repo_model.Release](ctx, opts) @@ -241,14 +244,21 @@ func TagsList(ctx *context.Context) { return } - ctx.Data["Releases"] = releases + count, err := db.Count[repo_model.Release](ctx, opts) + if err != nil { + ctx.ServerError("GetReleasesByRepoID", err) + return + } - numTags := ctx.Data["NumTags"].(int64) - pager := context.NewPagination(int(numTags), opts.PageSize, opts.Page, 5) + ctx.Data["Keyword"] = namePattern + ctx.Data["Releases"] = releases + ctx.Data["TagCount"] = count + + pager := context.NewPagination(int(count), opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) ctx.Data["Page"] = pager - ctx.Data["PageIsViewCode"] = !ctx.Repo.Repository.UnitEnabled(ctx, unit.TypeReleases) + ctx.HTML(http.StatusOK, tplTagsList) } diff --git a/templates/repo/tag/list.tmpl b/templates/repo/tag/list.tmpl index 354808ed2e..eac846da7d 100644 --- a/templates/repo/tag/list.tmpl +++ b/templates/repo/tag/list.tmpl @@ -4,14 +4,19 @@
{{template "base/alert" .}} {{template "repo/release_tag_header" .}} - {{if .Releases}}

- {{svg "octicon-tag" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.release.tags"}} + {{.TagCount}} {{ctx.Locale.Tr "repo.release.tags"}}

{{$canReadReleases := $.Permission.CanRead ctx.Consts.RepoUnitTypeReleases}} +
+
+ {{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.tag_kind") "Tooltip" (ctx.Locale.Tr "search.tag_tooltip")}} +
+
+ {{if .Releases}} {{range $idx, $release := .Releases}} @@ -57,9 +62,12 @@ {{end}}
+ {{else}} + {{if .NumTags}} +

{{ctx.Locale.Tr "no_results_found"}}

+ {{end}} + {{end}}
- {{end}} - {{template "base/paginate" .}}