The source project of this merge request has been removed.
Handle created_at with timezone information
Description
When running the script against a self-managed GL_SERVER, it is possible that the timezone of the system is set. In that case created at returns timestamp like: '2023-09-20T14:03:04.805+02:00' which throws an exception when trying to parse via strptime in current format.
Traceback (most recent call last): File "/app/gitlab_storage_analyzer.py", line 466, in <module> gl_storage_analyzer.create_summary() File "/app/gitlab_storage_analyzer.py", line 329, in create_summary out += self.gen_summary_job_artifacts() File "/app/gitlab_storage_analyzer.py", line 152, in gen_summary_job_artifacts self.request_job_artifact_data() # TODO: consider caching File "/app/gitlab_storage_analyzer.py", line 106, in request_job_artifact_data self.request_project_job_artifacts_data(project) File "/app/gitlab_storage_analyzer.py", line 122, in request_project_job_artifacts_data created_at = datetime.datetime.strptime(job.created_at, '%Y-%m-%dT%H:%M:%S.%fZ') File "/usr/local/lib/python3.10/\_strptime.py", line 568, in \_strptime_datetime tt, fraction, gmtoff_fraction = \_strptime(data_string, format) File "/usr/local/lib/python3.10/\_strptime.py", line 349, in \_strptime raise ValueError("time data %r does not match format %r" % ValueError: time data '2023-09-20T14:03:04.805+02:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
The change should fix this behaviour by getting the date to isoformat and then setting to naive datetime. I did not spend additional effort to change other parts of code to use datetime with timezone instead of naive datetime as datetime.datetime.now() would return naive datetime. Thefore I added this workaround to replace tzinfo at the end.
Tasks
- Change datetime for created_at to isoformat to support timezones
How does success look like
No more exceptions regardless of the format of created_at (naive or with timezone)