Skip to content

Commit 8a1993f

Browse files
authored
Set return_records to false (#75)
Signed-off-by: Eric Pickard <piceri@github.com>
1 parent 1b2e649 commit 8a1993f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pkg/deploymentrecord/client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
189189

190190
url := fmt.Sprintf("%s/orgs/%s/artifacts/metadata/deployment-record", c.baseURL, c.org)
191191

192-
body, err := json.Marshal(record)
192+
body, err := buildRequestBody(record)
193193
if err != nil {
194194
return fmt.Errorf("failed to marshal record: %w", err)
195195
}
@@ -398,6 +398,18 @@ func parseRateLimitDelay(resp *http.Response) time.Duration {
398398
}
399399
}
400400

401+
// buildRequestBody adds return_records=false to a deployment record request body
402+
// which results in a minimal response payload.
403+
func buildRequestBody(record *DeploymentRecord) ([]byte, error) {
404+
return json.Marshal(struct {
405+
DeploymentRecord
406+
ReturnRecords bool `json:"return_records"`
407+
}{
408+
DeploymentRecord: *record,
409+
ReturnRecords: false,
410+
})
411+
}
412+
401413
func waitForBackoff(ctx context.Context, attempt int) error {
402414
if attempt > 0 {
403415
backoff := time.Duration(math.Pow(2,

pkg/deploymentrecord/client_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package deploymentrecord
22

33
import (
4+
"bytes"
45
"context"
56
"errors"
7+
"io"
68
"net/http"
79
"net/http/httptest"
810
"strconv"
@@ -593,6 +595,13 @@ func TestPostOneSendsCorrectRequest(t *testing.T) {
593595
if got := r.Header.Get("Authorization"); got != "Bearer test-token" {
594596
t.Errorf("Authorization = %s, want Bearer test-token", got)
595597
}
598+
body, err := io.ReadAll(r.Body)
599+
if err != nil {
600+
t.Fatal("unable to read request body")
601+
}
602+
if !bytes.Contains(body, []byte("\"return_records\":false")) {
603+
t.Error("expected '\"return_records\":false' in the request body")
604+
}
596605
w.WriteHeader(http.StatusOK)
597606
}))
598607
t.Cleanup(srv.Close)

0 commit comments

Comments
 (0)