feat(api): add tag_filter query parameter to release list API (#38681)

Adds a `tag_filter` query parameter to `GET /repos/{owner}/{repo}/releases` that filters releases by tag name, with `*` as a wildcard (e.g. `v1*`, `*beta`, `*rc*`). Matching is
case-insensitive and done in the database query. Literal `%`, `_` and `\` in the filter are escaped.

Fixes: https://github.com/go-gitea/gitea/issues/38513
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
Mitrahsoft
2026-07-31 16:10:17 +05:30
committed by GitHub
parent a30d865b78
commit bcf45803af
5 changed files with 59 additions and 42 deletions
+9 -1
View File
@@ -266,6 +266,7 @@ type FindReleasesOptions struct {
TagNames []string
HasSha1 optional.Option[bool] // useful to find draft releases which are created with existing tags
NamePattern optional.Option[string]
TagFilter string
}
func (opts FindReleasesOptions) ToConds() builder.Cond {
@@ -297,7 +298,14 @@ func (opts FindReleasesOptions) ToConds() builder.Cond {
if opts.NamePattern.Has() && opts.NamePattern.Value() != "" {
cond = cond.And(builder.Like{"lower_tag_name", strings.ToLower(opts.NamePattern.Value())})
}
if opts.TagFilter != "" {
pattern := strings.ToLower(opts.TagFilter)
pattern = strings.ReplaceAll(pattern, "\\", "\\\\")
pattern = strings.ReplaceAll(pattern, "_", "\\_")
pattern = strings.ReplaceAll(pattern, "%", "\\%")
pattern = strings.ReplaceAll(pattern, "*", "%")
cond = cond.And(builder.Like{"lower_tag_name", pattern})
}
return cond
}