@@ -165,6 +165,8 @@ func (c *ClientError) Unwrap() error {
165165 return c .err
166166}
167167
168+ // ClusterNoRepositoriesError represents a 404 response from the cluster endpoint
169+ // indicating no repositories were found for the given cluster.
168170type ClusterNoRepositoriesError struct {
169171 err error
170172}
@@ -195,27 +197,27 @@ func (n *NoArtifactError) Unwrap() error {
195197
196198// PostOne posts a single deployment record to the GitHub deployment
197199// records API.
198- func (c * Client ) PostOne (ctx context.Context , record * DeploymentRecord ) error {
200+ func (c * Client ) PostOne (ctx context.Context , record * Record ) error {
199201 if record == nil {
200202 return errors .New ("record cannot be nil" )
201203 }
202204
203- singleUrl := fmt .Sprintf ("%s/orgs/%s/artifacts/metadata/deployment-record" , c .baseURL , c .org )
205+ singleURL := fmt .Sprintf ("%s/orgs/%s/artifacts/metadata/deployment-record" , c .baseURL , c .org )
204206
205207 body , err := buildRequestBody (record )
206208 if err != nil {
207209 return fmt .Errorf ("failed to marshal record: %w" , err )
208210 }
209211
210- respBody , statusCode , lastErr := c .postWithRetry (ctx , singleUrl , body )
212+ respBody , statusCode , lastErr := c .postWithRetry (ctx , singleURL , body )
211213
212214 var clientErr * ClientError
213215 switch {
214216 case errors .As (lastErr , & clientErr ):
215217 dtmetrics .PostDeploymentRecordClientError .Inc ()
216218 slog .Warn ("client error, aborting" ,
217219 "status_code" , statusCode ,
218- "url" , singleUrl ,
220+ "url" , singleURL ,
219221 "resp_msg" , string (respBody ),
220222 )
221223 return fmt .Errorf ("client error: %w" , lastErr )
@@ -244,28 +246,28 @@ func (c *Client) PostOne(ctx context.Context, record *DeploymentRecord) error {
244246
245247// PostCluster sends a full cluster state of records to GitHub deployment
246248// records cluster API.
247- func (c * Client ) PostCluster (ctx context.Context , records []* DeploymentRecord , cluster string ) ([]byte , error ) {
248- if len (records ) < = 0 {
249+ func (c * Client ) PostCluster (ctx context.Context , records []* Record , cluster string ) ([]byte , error ) {
250+ if len (records ) = = 0 {
249251 slog .Debug ("Records is empty, skipping" )
250252 return nil , nil
251253 }
252254
253- clusterUrl := fmt .Sprintf ("%s/orgs/%s/artifacts/metadata/deployment-record/cluster/%s" , c .baseURL , c .org , url .PathEscape (cluster ))
255+ clusterURL := fmt .Sprintf ("%s/orgs/%s/artifacts/metadata/deployment-record/cluster/%s" , c .baseURL , c .org , url .PathEscape (cluster ))
254256
255257 body , err := buildClusterRequestBody (records )
256258 if err != nil {
257259 return nil , fmt .Errorf ("failed to marshal records: %w" , err )
258260 }
259261
260- respBody , statusCode , lastErr := c .postWithRetry (ctx , clusterUrl , body )
262+ respBody , statusCode , lastErr := c .postWithRetry (ctx , clusterURL , body )
261263
262264 var clientErr * ClientError
263265 switch {
264266 case errors .As (lastErr , & clientErr ):
265267 dtmetrics .PostDeploymentRecordClientError .Inc ()
266268 slog .Warn ("client error, aborting" ,
267269 "status_code" , statusCode ,
268- "url" , clusterUrl ,
270+ "url" , clusterURL ,
269271 "resp_msg" , string (respBody ),
270272 )
271273 return nil , fmt .Errorf ("client error: %w" , lastErr )
@@ -274,7 +276,7 @@ func (c *Client) PostCluster(ctx context.Context, records []*DeploymentRecord, c
274276 return respBody , nil
275277 case statusCode == 404 :
276278 dtmetrics .PostDeploymentRecordUnknownArtifact .Inc ()
277- return nil , & ClusterNoRepositoriesError {err : fmt . Errorf ("no repositories found" )}
279+ return nil , & ClusterNoRepositoriesError {err : errors . New ("no repositories found" )}
278280 default :
279281 dtmetrics .PostDeploymentRecordHardFail .Inc ()
280282 slog .Error ("all retries exhausted" ,
@@ -286,7 +288,7 @@ func (c *Client) PostCluster(ctx context.Context, records []*DeploymentRecord, c
286288 }
287289}
288290
289- func (c * Client ) postWithRetry (ctx context.Context , url string , body []byte ) ([]byte , int , error ) {
291+ func (c * Client ) postWithRetry (ctx context.Context , targetURL string , body []byte ) ([]byte , int , error ) {
290292 bodyReader := bytes .NewReader (body )
291293 var lastErr error
292294 // The first attempt is not a retry!
@@ -306,7 +308,7 @@ func (c *Client) postWithRetry(ctx context.Context, url string, body []byte) ([]
306308 // Reset reader position for retries
307309 bodyReader .Reset (body )
308310
309- req , err := http .NewRequestWithContext (ctx , http .MethodPost , url , bodyReader )
311+ req , err := http .NewRequestWithContext (ctx , http .MethodPost , targetURL , bodyReader )
310312 if err != nil {
311313 return nil , 0 , fmt .Errorf ("failed to create request: %w" , err )
312314 }
@@ -363,7 +365,7 @@ func (c *Client) postWithRetry(ctx context.Context, url string, body []byte) ([]
363365 "retry-after" , resp .Header .Get ("Retry-After" ),
364366 "x-ratelimit-remaining" , resp .Header .Get ("X-Ratelimit-Remaining" ),
365367 "retry_delay" , retryDelay .Seconds (),
366- "url" , url ,
368+ "url" , targetURL ,
367369 "resp_msg" , string (respBody ),
368370 )
369371 lastErr = fmt .Errorf ("rate limited, attempt %d" , attempt )
@@ -377,7 +379,7 @@ func (c *Client) postWithRetry(ctx context.Context, url string, body []byte) ([]
377379 slog .Debug ("retriable error" ,
378380 "attempt" , attempt ,
379381 "status_code" , resp .StatusCode ,
380- "url" , url ,
382+ "url" , targetURL ,
381383 "resp_msg" , string (respBody ),
382384 )
383385 lastErr = fmt .Errorf ("server error, attempt %d" , attempt )
@@ -463,29 +465,29 @@ func parseRateLimitDelay(resp *http.Response) time.Duration {
463465
464466// buildRequestBody adds return_records=false to a deployment record request body
465467// which results in a minimal response payload.
466- func buildRequestBody (record * DeploymentRecord ) ([]byte , error ) {
468+ func buildRequestBody (record * Record ) ([]byte , error ) {
467469 return json .Marshal (struct {
468- DeploymentRecord
470+ Record
469471 ReturnRecords bool `json:"return_records"`
470472 }{
471- DeploymentRecord : * record ,
472- ReturnRecords : false ,
473+ Record : * record ,
474+ ReturnRecords : false ,
473475 })
474476}
475477
476- // buildClusterRequestBody count the total records, builds DeploymentRecords ,
478+ // buildClusterRequestBody count the total records, builds ClusterRecordsBody ,
477479// and returns []byte.
478- func buildClusterRequestBody (records []* DeploymentRecord ) ([]byte , error ) {
479- if len (records ) < = 0 {
480+ func buildClusterRequestBody (records []* Record ) ([]byte , error ) {
481+ if len (records ) = = 0 {
480482 return nil , nil
481483 }
482- deploymentRecords := []DeploymentRecordBase {}
484+ deploymentRecords := []BaseRecord {}
483485
484486 for _ , r := range records {
485- deploymentRecords = append (deploymentRecords , r .DeploymentRecordBase )
487+ deploymentRecords = append (deploymentRecords , r .BaseRecord )
486488 }
487489
488- return json .Marshal (DeploymentRecords {
490+ return json .Marshal (ClusterRecordsBody {
489491 LogicalEnvironment : records [0 ].LogicalEnvironment ,
490492 PhysicalEnvironment : records [0 ].PhysicalEnvironment ,
491493 PartialSuccess : true ,
0 commit comments