3434)
3535from ywh2bt .core .api .tracker import (
3636 SendLogsResult ,
37+ TrackerAttachment ,
3738 TrackerClient ,
3839 TrackerClientError ,
3940 TrackerIssue ,
7677 SynchronizerStartFetchReportsEvent ,
7778 SynchronizerStartSendReportEvent ,
7879)
80+ from ywh2bt .size import sizeof_fmt_si
7981
8082
8183class Synchronizer :
@@ -624,6 +626,7 @@ def _download_comment(
624626 tracker_issue : TrackerIssue ,
625627 tracker_comment : TrackerIssueComment ,
626628 ) -> None :
629+ failed_attachments = {}
627630 attachments = {}
628631 for attachment_key , attachment in tracker_comment .attachments .items ():
629632 try :
@@ -633,10 +636,9 @@ def _download_comment(
633636 file_content = attachment .content ,
634637 file_type = attachment .mime_type ,
635638 )
636- except YesWeHackApiClientError as upload_attachment_error :
637- raise SynchronizerError (
638- f'Unable to upload attachment { attachment .filename } for report #{ self ._report .report_id } ' ,
639- ) from upload_attachment_error
639+ except YesWeHackApiClientError :
640+ failed_attachments [attachment_key ] = attachment
641+ continue
640642 attachments [attachment_key ] = uploaded_attachment
641643 try :
642644 self ._yeswehack_client .post_report_tracker_message (
@@ -647,6 +649,7 @@ def _download_comment(
647649 comment = self ._message_formatter .format_download_comment (
648650 comment = tracker_comment ,
649651 attachments = attachments ,
652+ failed_attachments = failed_attachments ,
650653 ),
651654 attachments = [uploaded_attachment .name for attachment_key , uploaded_attachment in attachments .items ()],
652655 )
@@ -783,13 +786,15 @@ def format_download_comment(
783786 self ,
784787 comment : TrackerIssueComment ,
785788 attachments : Dict [str , Attachment ],
789+ failed_attachments : Dict [str , TrackerAttachment ],
786790 ) -> str :
787791 """
788792 Format a downloaded comment.
789793
790794 Args:
791795 comment: a comment
792796 attachments: a dict of attachments
797+ failed_attachments: a dict of tracker attachments that failed to be uploaded
793798 """
794799
795800 @abstractmethod
@@ -835,6 +840,15 @@ class SynchronizerMessageFormatter(AbstractSynchronizerMessageFormatter):
835840 + '\n \n '
836841 + '${comment}' ,
837842 )
843+ _failed_attachments_template : Template = Template (
844+ '**YWH2BT note:**'
845+ + '\n *There was an issue while uploading the following attachments from the bugtracker*:'
846+ + '\n \n '
847+ + '${attachments}' ,
848+ )
849+ _failed_attachment_template : Template = Template (
850+ '- ${filename} (size=${size}, mime=${mimetype})' ,
851+ )
838852 _status_update_comment_template : Template = Template (
839853 '${comment}' ,
840854 )
@@ -909,25 +923,42 @@ def format_download_comment(
909923 self ,
910924 comment : TrackerIssueComment ,
911925 attachments : Dict [str , Attachment ],
926+ failed_attachments : Dict [str , TrackerAttachment ],
912927 ) -> str :
913928 """
914929 Format a downloaded comment.
915930
916931 Args:
917932 comment: a comment
918933 attachments: a dict of attachments
934+ failed_attachments: a dict of tracker attachments that failed to be uploaded
919935
920936 Returns:
921937 a formatted comment
922938 """
923- return self ._download_comment_template .substitute (
939+ formatted_comment = self ._download_comment_template .substitute (
924940 date = comment .created_at ,
925941 author = comment .author ,
926942 comment = markdown_to_ywh (
927943 message = comment .body ,
928944 attachments = attachments ,
929945 ),
930946 )
947+ if failed_attachments :
948+ formatted_attachments = []
949+ for _attachment_key , failed_attachment in failed_attachments .items ():
950+ formatted_attachments .append (
951+ self ._failed_attachment_template .substitute (
952+ filename = failed_attachment .filename ,
953+ mimetype = failed_attachment .mime_type ,
954+ size = sizeof_fmt_si (len (failed_attachment .content ), precision = 2 ),
955+ ),
956+ )
957+ formatted_failed_attachments = self ._failed_attachments_template .substitute (
958+ attachments = '\n ' .join (formatted_attachments ),
959+ )
960+ formatted_comment = f'{ formatted_comment } \n \n { formatted_failed_attachments } '
961+ return formatted_comment
931962
932963 def format_status_update_comment (
933964 self ,
0 commit comments