2626"""
2727import sys
2828import csv
29+
30+ from typing import Union
31+
2932from http import HTTPStatus
3033from requests .exceptions import HTTPError
3134from sonar .util import types
@@ -277,6 +280,23 @@ def __check_options_vs_edition(edition: str, params: dict[str, str]) -> dict[str
277280 return params
278281
279282
283+ def __get_measures (obj : object , wanted_metrics : types .KeyList , hist : bool ) -> Union [dict [str , any ], None ]:
284+ """Returns object measures (last measures or history of measures)"""
285+ data = obj .component_data ()
286+ try :
287+ if hist :
288+ data .update (__get_json_measures_history (obj , wanted_metrics ))
289+ else :
290+ data .update (__get_object_measures (obj , wanted_metrics ))
291+ except HTTPError as e :
292+ if e .response .status_code == HTTPStatus .FORBIDDEN :
293+ log .error ("Insufficient permission to retrieve measures of %s, export skipped for this object" , str (obj ))
294+ else :
295+ log .error ("HTTP Error %s while retrieving measures of %s, export skipped for this object" , str (e ), str (obj ))
296+ return None
297+ return data
298+
299+
280300def main () -> None :
281301 """Entry point for sonar-measures-export"""
282302 start_time = util .start_clock ()
@@ -299,19 +319,9 @@ def main() -> None:
299319
300320 measure_list = []
301321 for obj in obj_list :
302- data = obj .component_data ()
303- try :
304- if kwargs ["history" ]:
305- data .update (__get_json_measures_history (obj , wanted_metrics ))
306- else :
307- data .update (__get_object_measures (obj , wanted_metrics ))
308- except HTTPError as e :
309- if e .response .status_code == HTTPStatus .FORBIDDEN :
310- log .error ("Insufficient permission to retrieve measures of %s, export skipped for this object" , str (obj ))
311- else :
312- log .error ("HTTP Error %s while retrieving measures of %s, export skipped for this object" , str (e ), str (obj ))
313- continue
314- measure_list += [data ]
322+ data = __get_measures (obj , wanted_metrics , kwargs ["history" ])
323+ if data is not None :
324+ measure_list += [data ]
315325
316326 if fmt == "json" :
317327 with util .open_file (file ) as fd :
0 commit comments