mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 12:34:34 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user