refactor(pkg/search): rename KeywordsVerbatim to ImmutableKeywords
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
1533d8177c
commit
56cdc36013
3 changed files with 29 additions and 28 deletions
|
|
@ -222,7 +222,7 @@ func SearchQueryBuild(options FilterOptions, advancedIssueSearchSyntax bool) str
|
|||
Is: []string{is},
|
||||
Type: options.Entity,
|
||||
},
|
||||
KeywordsVerbatim: options.Search,
|
||||
ImmutableKeywords: options.Search,
|
||||
}
|
||||
|
||||
if !advancedIssueSearchSyntax {
|
||||
|
|
|
|||
|
|
@ -21,14 +21,15 @@ type Query struct {
|
|||
// as needed. This is useful when the input can be supplied as a list of
|
||||
// search keywords.
|
||||
//
|
||||
// This field is mutually exclusive with KeywordsVerbatim.
|
||||
// This field is overridden by ImmutableKeywords.
|
||||
Keywords []string
|
||||
// KeywordsVerbatim holds the search keywords as a single string, and will
|
||||
|
||||
// ImmutableKeywords holds the search keywords as a single string, and will
|
||||
// be treated as is (e.g. no additional quoting). This is useful when the
|
||||
// input is meant to be taken verbatim from the user.
|
||||
//
|
||||
// This field is mutually exclusive with Keywords.
|
||||
KeywordsVerbatim string
|
||||
// This field takes precedence over Keywords.
|
||||
ImmutableKeywords string
|
||||
|
||||
Kind string
|
||||
Limit int
|
||||
|
|
@ -117,8 +118,8 @@ type Qualifiers struct {
|
|||
func (q Query) StandardSearchString() string {
|
||||
qualifiers := formatQualifiers(q.Qualifiers, nil)
|
||||
var keywords []string
|
||||
if q.KeywordsVerbatim != "" {
|
||||
keywords = []string{q.KeywordsVerbatim}
|
||||
if q.ImmutableKeywords != "" {
|
||||
keywords = []string{q.ImmutableKeywords}
|
||||
} else if ks := formatKeywords(q.Keywords); len(ks) > 0 {
|
||||
keywords = ks
|
||||
}
|
||||
|
|
@ -143,7 +144,7 @@ func (q Query) StandardSearchString() string {
|
|||
// The advanced syntax is documented at https://github.blog/changelog/2025-03-06-github-issues-projects-api-support-for-issues-advanced-search-and-more
|
||||
func (q Query) AdvancedIssueSearchString() string {
|
||||
qualifiers := strings.Join(formatQualifiers(q.Qualifiers, formatAdvancedIssueSearch), " ")
|
||||
keywords := q.KeywordsVerbatim
|
||||
keywords := q.ImmutableKeywords
|
||||
if keywords == "" {
|
||||
keywords = strings.Join(formatKeywords(q.Keywords), " ")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,29 +75,29 @@ func TestStandardSearchString(t *testing.T) {
|
|||
out: `topic:"quote qualifier"`,
|
||||
},
|
||||
{
|
||||
name: "respects verbatim keywords",
|
||||
name: "respects immutable keywords",
|
||||
query: Query{
|
||||
KeywordsVerbatim: "verbatim keyword that should be left as is",
|
||||
ImmutableKeywords: "immutable keyword that should be left as is",
|
||||
},
|
||||
out: `verbatim keyword that should be left as is`,
|
||||
out: `immutable keyword that should be left as is`,
|
||||
},
|
||||
{
|
||||
name: "respects verbatim keywords, with qualifiers",
|
||||
name: "respects immutable keywords, with qualifiers",
|
||||
query: Query{
|
||||
KeywordsVerbatim: "verbatim keyword that should be left as is",
|
||||
ImmutableKeywords: "immutable keyword that should be left as is",
|
||||
Qualifiers: Qualifiers{
|
||||
Topic: []string{"quote qualifier"},
|
||||
},
|
||||
},
|
||||
out: `verbatim keyword that should be left as is topic:"quote qualifier"`,
|
||||
out: `immutable keyword that should be left as is topic:"quote qualifier"`,
|
||||
},
|
||||
{
|
||||
name: "prioritises verbatim keywords over keywords slice",
|
||||
name: "prioritises immutable keywords over keywords slice",
|
||||
query: Query{
|
||||
Keywords: []string{"foo", "bar"},
|
||||
KeywordsVerbatim: "verbatim keyword",
|
||||
Keywords: []string{"foo", "bar"},
|
||||
ImmutableKeywords: "immutable keyword",
|
||||
},
|
||||
out: `verbatim keyword`,
|
||||
out: `immutable keyword`,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
@ -141,29 +141,29 @@ func TestAdvancedIssueSearchString(t *testing.T) {
|
|||
out: `label:"quote qualifier"`,
|
||||
},
|
||||
{
|
||||
name: "respects verbatim keywords",
|
||||
name: "respects immutable keywords",
|
||||
query: Query{
|
||||
KeywordsVerbatim: "verbatim keyword that should be left as is",
|
||||
ImmutableKeywords: "immutable keyword that should be left as is",
|
||||
},
|
||||
out: `verbatim keyword that should be left as is`,
|
||||
out: `immutable keyword that should be left as is`,
|
||||
},
|
||||
{
|
||||
name: "respects verbatim keywords, with qualifiers",
|
||||
name: "respects immutable keywords, with qualifiers",
|
||||
query: Query{
|
||||
KeywordsVerbatim: "verbatim keyword that should be left as is",
|
||||
ImmutableKeywords: "immutable keyword that should be left as is",
|
||||
Qualifiers: Qualifiers{
|
||||
Topic: []string{"quote qualifier"},
|
||||
},
|
||||
},
|
||||
out: `( verbatim keyword that should be left as is ) topic:"quote qualifier"`,
|
||||
out: `( immutable keyword that should be left as is ) topic:"quote qualifier"`,
|
||||
},
|
||||
{
|
||||
name: "prioritises verbatim keywords over keywords slice",
|
||||
name: "prioritises immutable keywords over keywords slice",
|
||||
query: Query{
|
||||
Keywords: []string{"foo", "bar"},
|
||||
KeywordsVerbatim: "verbatim keyword",
|
||||
Keywords: []string{"foo", "bar"},
|
||||
ImmutableKeywords: "immutable keyword",
|
||||
},
|
||||
out: `verbatim keyword`,
|
||||
out: `immutable keyword`,
|
||||
},
|
||||
{
|
||||
name: "unused qualifiers should not appear in query",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue