diff --git a/models/repo/release.go b/models/repo/release.go index e2cd7d7ed3..d96eac0d19 100644 --- a/models/repo/release.go +++ b/models/repo/release.go @@ -249,6 +249,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 + Keyword string } func (opts FindReleasesOptions) ToConds() builder.Cond { @@ -276,6 +277,15 @@ func (opts FindReleasesOptions) ToConds() builder.Cond { cond = cond.And(builder.Eq{"sha1": ""}) } } + + if opts.Keyword != "" { + keywordCond := builder.NewCond() + keywordCond = keywordCond.Or(builder.Like{"lower_tag_name", strings.ToLower(opts.Keyword)}) + keywordCond = keywordCond.Or(db.BuildCaseInsensitiveLike("title", opts.Keyword)) + keywordCond = keywordCond.Or(db.BuildCaseInsensitiveLike("note", opts.Keyword)) + cond = cond.And(keywordCond) + } + return cond } diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index 5ea4dc8cfc..2fc5f095cb 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -136,6 +136,10 @@ func ListReleases(ctx *context.APIContext) { // in: query // description: filter (exclude / include) pre-releases // type: boolean + // - name: q + // in: query + // description: Search string + // type: string // - name: page // in: query // description: page number of results to return (1-based) @@ -158,6 +162,7 @@ func ListReleases(ctx *context.APIContext) { IsDraft: ctx.FormOptionalBool("draft"), IsPreRelease: ctx.FormOptionalBool("pre-release"), RepoID: ctx.Repo.Repository.ID, + Keyword: ctx.FormTrim("q"), } releases, err := db.Find[repo_model.Release](ctx, opts) diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 2266debd6e..65d526d2f2 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -168,6 +168,10 @@ func Releases(ctx *context.Context) { // Disable the showCreateNewBranch form in the dropdown on this page. ctx.Data["CanCreateBranch"] = false ctx.Data["HideBranchesInDropdown"] = true + ctx.Data["ShowReleaseSearch"] = true + + keyword := ctx.FormTrim("q") + ctx.Data["Keyword"] = keyword listOptions := db.ListOptions{ Page: ctx.FormInt("page"), @@ -188,6 +192,7 @@ func Releases(ctx *context.Context) { // only show draft releases for users who can write, read-only users shouldn't see draft releases. IncludeDrafts: writeAccess, RepoID: ctx.Repo.Repository.ID, + Keyword: keyword, }) if err != nil { ctx.ServerError("getReleaseInfos", err) @@ -258,6 +263,10 @@ func TagsList(ctx *context.Context) { ctx.Data["CanCreateBranch"] = false ctx.Data["HideBranchesInDropdown"] = true ctx.Data["CanCreateRelease"] = ctx.Repo.CanWrite(unit.TypeReleases) && !ctx.Repo.Repository.IsArchived + ctx.Data["ShowReleaseSearch"] = true + + keyword := ctx.FormTrim("q") + ctx.Data["Keyword"] = keyword listOptions := db.ListOptions{ Page: ctx.FormInt("page"), @@ -278,6 +287,7 @@ func TagsList(ctx *context.Context) { IncludeTags: true, HasSha1: optional.Some(true), RepoID: ctx.Repo.Repository.ID, + Keyword: keyword, } releases, err := db.Find[repo_model.Release](ctx, opts) diff --git a/templates/repo/release_tag_header.tmpl b/templates/repo/release_tag_header.tmpl index dafe9f2fa6..63d0689c50 100644 --- a/templates/repo/release_tag_header.tmpl +++ b/templates/repo/release_tag_header.tmpl @@ -5,15 +5,20 @@