Skip to content

Included tag search capabilities #32045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions models/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really a fan of allowing end users to set SQL LIKE statements (i.e. they might not expect that entering v1_% shows all tags in Version 1X).
However, what would be the alternative?
Parsing a glob instead and mapping it to the LIKE syntax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we choose to merge this as it is, please add a docs page in https://gitea.com/gitea/docs describing that this search accepts the SQL LIKE syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ideia behind is to macht all tags whose related commit message contains the criterion (i.e., if the user passes "2" as the criterion. It should matches v2, v1.2, v.1.32, and so on). I double-checked the generated SQL and xorm puts the wildcard on both sides of the literal (see evidence attached). This behavior is inline with how the commit search works.

image

About the documentation changes, gonna submitt a PR latter today :)

Copy link
Member

@lunny lunny Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses builder.Like{"lower_tag_name", strings.ToLower(opts.NamePattern.Value())}, which will generate a SQL like lower_tag_name = ?, And the % will be added automatically if it hasn't been added. If you search with '2%', then the '%' will not be added automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delvh do you think we still need to add a docs page for this particular change after the explanation ? I can't seem to find any existing page that is closely related to this change (the closest seem to be Usage > Protected tags but I feel is not quite right). Any ideas ?

Copy link
Member

@delvh delvh Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My problem is simply that I don't like hiding functionality from the user in intransparent ways.
What we could do as a simple workaround is add a tooltip (data-tooltip-content=… attribute) to the search bar stating
Search for matching tags. Use '%' as a placeholder for any sequence of chars and '_' for a single unknown char or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delvh Cool, I'm gonna add the tooltip latter today :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@delvh What do you think ?

image

If you guys think it is ok, I'll push the changes :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last thing: I'm not quite happy with using the query param q as tag name.
I mean… it is sort of a query.
However, it might be confusing in the future if there are multiple search boxes why one is q while the other one isn't.

Copy link
Contributor Author

@bsofiato bsofiato Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last thing: I'm not quite happy with using the query param q as tag name.
I mean… it is sort of a query.
However, it might be confusing in the future if there are multiple search boxes why one is q while the other one isn't.

Hey @delvh, this one could be a little tricky :(

The thing is that the page is using the combo.tmpl template. Which, in turn uses the input,tmpl. The latter (source-code attached) assumes the name of the field to be q. I could change it to receive a custom name, but it feels that it is out of the scope of this particular PR.

How do you guys want to proceed ? Do you want me to create another PR that allows a custom name for the combo component and them rebase the this one when the new one is merged ? Or do you want me to put it all together on a single PR ?

image


listOptions := db.ListOptions{
Page: ctx.FormInt("page"),
PageSize: ctx.FormInt("limit"),
Expand All @@ -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)
Expand All @@ -241,14 +244,21 @@ func TagsList(ctx *context.Context) {
return
}

count, err := db.Count[repo_model.Release](ctx, opts)
if err != nil {
ctx.ServerError("GetReleasesByRepoID", err)
return
}

ctx.Data["Keyword"] = namePattern
ctx.Data["Releases"] = releases
ctx.Data["TagCount"] = count

numTags := ctx.Data["NumTags"].(int64)
pager := context.NewPagination(int(numTags), opts.PageSize, opts.Page, 5)
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)
}

Expand Down
16 changes: 12 additions & 4 deletions templates/repo/tag/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
<div class="ui container">
{{template "base/alert" .}}
{{template "repo/release_tag_header" .}}
{{if .Releases}}
<h4 class="ui top attached header">
<div class="five wide column tw-flex tw-items-center">
{{svg "octicon-tag" 16 "tw-mr-1"}}{{ctx.Locale.Tr "repo.release.tags"}}
{{.TagCount}} {{ctx.Locale.Tr "repo.release.tags"}}
</div>
</h4>
{{$canReadReleases := $.Permission.CanRead ctx.Consts.RepoUnitTypeReleases}}
<div class="ui attached segment">
<form class="ignore-dirty" method="get">
{{template "shared/search/combo" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.tag_kind") "Tooltip" (ctx.Locale.Tr "search.tag_tooltip")}}
</form>
</div>
<div class="ui attached table segment">
{{if .Releases}}
<table class="ui very basic striped fixed table single line" id="tags-table">
<tbody class="tag-list">
{{range $idx, $release := .Releases}}
Expand Down Expand Up @@ -57,9 +62,12 @@
{{end}}
</tbody>
</table>
{{else}}
{{if .NumTags}}
<p class="tw-p-4">{{ctx.Locale.Tr "no_results_found"}}</p>
{{end}}
{{end}}
</div>
{{end}}

{{template "base/paginate" .}}
</div>
</div>
Expand Down
Loading