From a57b14166e72bfe439d159a1627a62fdc3a4254c Mon Sep 17 00:00:00 2001 From: Eric Pickard Date: Thu, 9 Apr 2026 15:19:50 -0400 Subject: [PATCH] Set return_records to false Signed-off-by: Eric Pickard --- pkg/deploymentrecord/client.go | 14 +++++++++++++- pkg/deploymentrecord/client_test.go | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/deploymentrecord/client.go b/pkg/deploymentrecord/client.go index 8ea996c..e4e71c1 100644 --- a/pkg/deploymentrecord/client.go +++ b/pkg/deploymentrecord/client.go @@ -189,7 +189,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error { url := fmt.Sprintf("%s/orgs/%s/artifacts/metadata/deployment-record", c.baseURL, c.org) - body, err := json.Marshal(record) + body, err := buildRequestBody(record) if err != nil { return fmt.Errorf("failed to marshal record: %w", err) } @@ -398,6 +398,18 @@ func parseRateLimitDelay(resp *http.Response) time.Duration { } } +// buildRequestBody adds return_records=false to a deployment record request body +// which results in a minimal response payload. +func buildRequestBody(record *DeploymentRecord) ([]byte, error) { + return json.Marshal(struct { + DeploymentRecord + ReturnRecords bool `json:"return_records"` + }{ + DeploymentRecord: *record, + ReturnRecords: false, + }) +} + func waitForBackoff(ctx context.Context, attempt int) error { if attempt > 0 { backoff := time.Duration(math.Pow(2, diff --git a/pkg/deploymentrecord/client_test.go b/pkg/deploymentrecord/client_test.go index 0fbbff3..7a7f861 100644 --- a/pkg/deploymentrecord/client_test.go +++ b/pkg/deploymentrecord/client_test.go @@ -1,8 +1,10 @@ package deploymentrecord import ( + "bytes" "context" "errors" + "io" "net/http" "net/http/httptest" "strconv" @@ -593,6 +595,13 @@ func TestPostOneSendsCorrectRequest(t *testing.T) { if got := r.Header.Get("Authorization"); got != "Bearer test-token" { t.Errorf("Authorization = %s, want Bearer test-token", got) } + body, err := io.ReadAll(r.Body) + if err != nil { + t.Fatal("unable to read request body") + } + if !bytes.Contains(body, []byte("\"return_records\":false")) { + t.Error("expected '\"return_records\":false' in the request body") + } w.WriteHeader(http.StatusOK) })) t.Cleanup(srv.Close)