Skip to content
Merged
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
29 changes: 22 additions & 7 deletions util/github/scalesets/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
}
}
uri.RawQuery = q.Encode()
if baseQuery.Get("api-version") == "" {
baseQuery.Set("api-version", "6.0-preview")
}

actionsURI.Path = path.Join(actionsURI.Path, pathURI.Path)
actionsURI.RawQuery = baseQuery.Encode()

req, err := http.NewRequestWithContext(ctx, method, uri.String(), body)
req, err := http.NewRequestWithContext(ctx, method, actionsURI.String(), body)
if err != nil {
return nil, err
}
Expand Down
Loading