ci: generate new report if old one failed to be updated

This commit is contained in:
Fu Hanxi
2024-10-21 12:11:47 +02:00
parent b2bc90d97a
commit bdc2998e4b

View File

@@ -11,6 +11,7 @@ from textwrap import dedent
import yaml import yaml
from artifacts_handler import ArtifactType from artifacts_handler import ArtifactType
from gitlab import GitlabUpdateError
from gitlab_api import Gitlab from gitlab_api import Gitlab
from idf_build_apps import App from idf_build_apps import App
from idf_build_apps.constants import BuildStatus from idf_build_apps.constants import BuildStatus
@@ -254,6 +255,10 @@ class ReportGenerator:
) )
del_retry_job_pic_pattern = re.escape(RETRY_JOB_TITLE) + r'.*?' + re.escape(f'{RETRY_JOB_PICTURE_PATH})') del_retry_job_pic_pattern = re.escape(RETRY_JOB_TITLE) + r'.*?' + re.escape(f'{RETRY_JOB_PICTURE_PATH})')
new_comment = f'{COMMENT_START_MARKER}\n\n{comment}'
if print_retry_jobs_message:
new_comment += retry_job_picture_comment
for note in self.mr.notes.list(iterator=True): for note in self.mr.notes.list(iterator=True):
if note.body.startswith(COMMENT_START_MARKER): if note.body.startswith(COMMENT_START_MARKER):
updated_str = self._get_updated_comment(note.body, comment) updated_str = self._get_updated_comment(note.body, comment)
@@ -264,14 +269,13 @@ class ReportGenerator:
updated_str += retry_job_picture_comment updated_str += retry_job_picture_comment
note.body = updated_str note.body = updated_str
note.save() try:
note.save()
except GitlabUpdateError:
print('Failed to update MR comment, Creating a new comment')
self.mr.notes.create({'body': new_comment})
break break
else: else:
# Create a new comment if no existing comment is found
new_comment = f'{COMMENT_START_MARKER}\n\n{comment}'
if print_retry_jobs_message:
new_comment += retry_job_picture_comment
self.mr.notes.create({'body': new_comment}) self.mr.notes.create({'body': new_comment})
def _get_updated_comment(self, existing_comment: str, new_comment: str) -> str: def _get_updated_comment(self, existing_comment: str, new_comment: str) -> str: