From 65d6d1ae8742dd74b58054179281b837b69f2244 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Wed, 16 Jul 2025 06:39:46 +0000 Subject: [PATCH] Handle query args Merge any query args from both the GH url and the supplied URL. Signed-off-by: Gabriel Adrian Samfira --- util/github/scalesets/util.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/util/github/scalesets/util.go b/util/github/scalesets/util.go index ac5468bf..e8387e63 100644 --- a/util/github/scalesets/util.go +++ b/util/github/scalesets/util.go @@ -19,9 +19,11 @@ import ( "fmt" "io" "net/http" + "net/url" + "path" ) -func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error) { +func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, uriPath string, body io.Reader) (*http.Request, error) { if err := s.ensureAdminInfo(ctx); err != nil { return nil, fmt.Errorf("failed to update token: %w", err) } @@ -31,14 +33,27 @@ func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path str return nil, fmt.Errorf("failed to get pipeline URL: %w", err) } - uri := actionsURI.JoinPath(path) - q := uri.Query() - if q.Get("api-version") == "" { - q.Set("api-version", "6.0-preview") + pathURI, err := url.Parse(uriPath) + if err != nil { + return nil, fmt.Errorf("failed to parse path: %w", err) + } + pathQuery := pathURI.Query() + baseQuery := actionsURI.Query() + for k, values := range pathQuery { + if baseQuery.Get(k) == "" { + for _, val := range values { + baseQuery.Add(k, val) + } + } + } + if baseQuery.Get("api-version") == "" { + baseQuery.Set("api-version", "6.0-preview") } - uri.RawQuery = q.Encode() - req, err := http.NewRequestWithContext(ctx, method, uri.String(), body) + actionsURI.Path = path.Join(actionsURI.Path, pathURI.Path) + actionsURI.RawQuery = baseQuery.Encode() + + req, err := http.NewRequestWithContext(ctx, method, actionsURI.String(), body) if err != nil { return nil, err }