@@ -76,15 +76,7 @@ def update_pull_request(dependency_change, base_commit_sha)
7676 "base-commit-sha" : base_commit_sha
7777 }
7878 }
79- response = http_client . post ( api_url , json : body )
80- raise ApiError , response . body if response . code >= 400
81- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
82- retry_count ||= 0
83- retry_count += 1
84- raise if retry_count > MAX_REQUEST_RETRIES
85-
86- sleep ( rand ( 3.0 ..10.0 ) )
87- retry
79+ send_post_request_with_network_retries ( api_url , body )
8880 end
8981 end
9082
@@ -96,15 +88,7 @@ def close_pull_request(dependency_names, reason)
9688
9789 api_url = "#{ base_url } /update_jobs/#{ job_id } /close_pull_request"
9890 body = { data : { "dependency-names" : dependency_names , reason : reason } }
99- response = http_client . post ( api_url , json : body )
100- raise ApiError , response . body if response . code >= 400
101- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
102- retry_count ||= 0
103- retry_count += 1
104- raise if retry_count > MAX_REQUEST_RETRIES
105-
106- sleep ( rand ( 3.0 ..10.0 ) )
107- retry
91+ send_post_request_with_network_retries ( api_url , body )
10892 end
10993 end
11094
@@ -123,15 +107,7 @@ def record_update_job_error(error_type:, error_details:)
123107 "error-details" : error_details
124108 }
125109 }
126- response = http_client . post ( api_url , json : body )
127- raise ApiError , response . body if response . code >= 400
128- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
129- retry_count ||= 0
130- retry_count += 1
131- raise if retry_count > MAX_REQUEST_RETRIES
132-
133- sleep ( rand ( 3.0 ..10.0 ) )
134- retry
110+ send_post_request_with_network_retries ( api_url , body )
135111 end
136112 end
137113
@@ -158,15 +134,7 @@ def record_update_job_warning(warn_type:, warn_title:, warn_description:)
158134 "warn-description" : warn_description
159135 }
160136 }
161- response = http_client . post ( api_url , json : body )
162- raise ApiError , response . body if response . code >= 400
163- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
164- retry_count ||= 0
165- retry_count += 1
166- raise if retry_count > MAX_REQUEST_RETRIES
167-
168- sleep ( rand ( 3.0 ..10.0 ) )
169- retry
137+ send_post_request_with_network_retries ( api_url , body )
170138 end
171139 end
172140
@@ -184,15 +152,7 @@ def record_update_job_unknown_error(error_type:, error_details:)
184152 "error-details" : error_details
185153 }
186154 }
187- response = http_client . post ( api_url , json : body )
188- raise ApiError , response . body if response . code >= 400
189- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
190- retry_count ||= 0
191- retry_count += 1
192- raise if retry_count > MAX_REQUEST_RETRIES
193-
194- sleep ( rand ( 3.0 ..10.0 ) )
195- retry
155+ send_post_request_with_network_retries ( api_url , body )
196156 end
197157 end
198158
@@ -204,15 +164,7 @@ def mark_job_as_processed(base_commit_sha)
204164
205165 api_url = "#{ base_url } /update_jobs/#{ job_id } /mark_as_processed"
206166 body = { data : { "base-commit-sha" : base_commit_sha } }
207- response = http_client . patch ( api_url , json : body )
208- raise ApiError , response . body if response . code >= 400
209- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
210- retry_count ||= 0
211- retry_count += 1
212- raise if retry_count > MAX_REQUEST_RETRIES
213-
214- sleep ( rand ( 3.0 ..10.0 ) )
215- retry
167+ send_post_request_with_network_retries ( api_url , body )
216168 end
217169 end
218170
@@ -228,15 +180,7 @@ def update_dependency_list(dependencies, dependency_files)
228180 dependency_files : dependency_files
229181 }
230182 }
231- response = http_client . post ( api_url , json : body )
232- raise ApiError , response . body if response . code >= 400
233- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
234- retry_count ||= 0
235- retry_count += 1
236- raise if retry_count > MAX_REQUEST_RETRIES
237-
238- sleep ( rand ( 3.0 ..10.0 ) )
239- retry
183+ send_post_request_with_network_retries ( api_url , body )
240184 end
241185 end
242186
@@ -249,17 +193,9 @@ def create_dependency_submission(dependency_submission)
249193 body = {
250194 data : dependency_submission
251195 }
252- response = http_client . post ( api_url , json : body )
253- raise ApiError , response . body if response . code >= 400
254- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
255- retry_count ||= 0
256- retry_count += 1
257- raise if retry_count > MAX_REQUEST_RETRIES
258-
259- sleep ( rand ( 3.0 ..10.0 ) )
260- retry
196+ send_post_request_with_network_retries ( api_url , body )
197+ end
261198 end
262- end
263199
264200 sig { params ( ecosystem_versions : T ::Hash [ Symbol , T . untyped ] ) . void }
265201 def record_ecosystem_versions ( ecosystem_versions )
@@ -268,15 +204,7 @@ def record_ecosystem_versions(ecosystem_versions)
268204 body = {
269205 data : { ecosystem_versions : ecosystem_versions }
270206 }
271- response = http_client . post ( api_url , json : body )
272- raise ApiError , response . body if response . code >= 400
273- rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError
274- retry_count ||= 0
275- retry_count += 1
276- raise if retry_count > MAX_REQUEST_RETRIES
277-
278- sleep ( rand ( 3.0 ..10.0 ) )
279- retry
207+ send_post_request_with_network_retries ( api_url , body )
280208 end
281209 end
282210
@@ -406,6 +334,30 @@ def record_cooldown_meta(job)
406334
407335 private
408336
337+ sig { params ( url : String , body : T ::Hash [ T . untyped , T . untyped ] ) . returns ( Excon ::Response ) }
338+ # Sends a POST request to the given API URL with the provided body.
339+ # Retries the request up to MAX_REQUEST_RETRIES times in case of network errors.
340+ # Raises ApiError if the response code is >= 400.
341+ #
342+ # @param api_url [String] The endpoint to send the POST request to.
343+ # @param json [Hash] The JSON body to send in the request.
344+ # @return [Excon::Response] The response from the API.
345+ def send_post_request_with_network_retries ( api_url , json )
346+ retry_count ||= 0
347+
348+ begin
349+ response = http_client . post ( api_url , json )
350+ raise ApiError , response . body if response . code >= 400
351+ response
352+ rescue HTTP ::ConnectionError , OpenSSL ::SSL ::SSLError => e
353+ retry_count += 1
354+ raise e if retry_count > MAX_REQUEST_RETRIES
355+
356+ sleep ( rand ( 3.0 ..10.0 ) )
357+ retry
358+ end
359+ end
360+
409361 # Update return type to allow returning a Hash or nil
410362 sig do
411363 params ( version_manager : T . nilable ( Dependabot ::Ecosystem ::VersionManager ) )
0 commit comments