From caee70c8efb8c271d01df7726060d9f25d3ea8c6 Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Tue, 20 Oct 2026 12:29:39 +0000 Subject: [PATCH] Fix $__multiVar for values that contain spaces --- docs/sources/template-variables.md | 2 +- pkg/github/macros.go | 11 ++++++++++- pkg/github/macros_test.go | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/sources/template-variables.md b/docs/sources/template-variables.md index 0749d052..d333454b 100644 --- a/docs/sources/template-variables.md +++ b/docs/sources/template-variables.md @@ -66,7 +66,7 @@ The GitHub data source provides macros that add dynamic parts to your queries. M | Macro | Syntax | Description | Example | |-------|--------|-------------|---------| -| **multiVar** | `$__multiVar(qualifier,$var)` | Expands a multi-value variable into GitHub search qualifiers. Each selected value is combined with the qualifier name in `qualifier:value` format. | `$__multiVar(label,$labels)` expands to `label:first-label label:second-label` | +| **multiVar** | `$__multiVar(qualifier,$var)` | Expands a multi-value variable into GitHub search qualifiers. Each selected value is combined with the qualifier name in `qualifier:value` format. Values that contain spaces are wrapped in double quotes, for example `label:"good first issue"`. | `$__multiVar(label,$labels)` expands to `label:first-label label:second-label` | | **toDay** | `$__toDay(diff)` | Returns the current date in UTC, formatted as `YYYY-MM-DD`. An optional `diff` parameter offsets the date by the specified number of days. | `created:$__toDay(-7)` on 2022-01-17 expands to `created:2022-01-10` | ### Use multiVar with "All" selection diff --git a/pkg/github/macros.go b/pkg/github/macros.go index 8bad217a..d7c229f7 100644 --- a/pkg/github/macros.go +++ b/pkg/github/macros.go @@ -28,6 +28,15 @@ func trimAll(s []string) []string { return r } +// quoteQualifierValue wraps a qualifier value that contains whitespace in double quotes, +// so GitHub search treats it as one value (ex: label:"good first issue") +func quoteQualifierValue(v string) string { + if !strings.ContainsAny(v, " \t") || (len(v) > 1 && strings.HasPrefix(v, `"`) && strings.HasSuffix(v, `"`)) { + return v + } + return `"` + v + `"` +} + // InterPolateMacros interpolate macros on a given query string func InterPolateMacros(query string) (string, error) { macros := map[string]macroFunc{ @@ -45,7 +54,7 @@ func InterPolateMacros(query string) (string, error) { prop = arg continue } - out = strings.Trim(fmt.Sprintf("%s %s:%s", out, prop, arg), " ") + out = strings.Trim(fmt.Sprintf("%s %s:%s", out, prop, quoteQualifierValue(arg)), " ") } return out, nil }, diff --git a/pkg/github/macros_test.go b/pkg/github/macros_test.go index df45537f..9e636ecf 100644 --- a/pkg/github/macros_test.go +++ b/pkg/github/macros_test.go @@ -25,6 +25,8 @@ func TestInterPolateMacros(t *testing.T) { {query: "hello $__multiVar(repo,*) world", want: "hello world"}, {query: "hello $__multiVar(repo,a,b,c)", want: "hello repo:a repo:b repo:c"}, {query: "hello $__multiVar(repo,a,b,c) $__multiVar(label,c,b,a) world", want: "hello repo:a repo:b repo:c label:c label:b label:a world"}, + {query: "is:open $__multiVar(label,good first issue,bug)", want: `is:open label:"good first issue" label:bug`}, + {query: `is:open $__multiVar(label,"help wanted")`, want: `is:open label:"help wanted"`}, {query: "created:$__toDay(today)", wantErr: errors.New("argument for day is not an integer")}, {query: "created:$__toDay()", want: "created:" + time.Now().UTC().Format("2006-01-02")}, {query: "$__toDay(0)", want: time.Now().UTC().Format("2006-01-02")},