Skip to content

Commit 2eb3b57

Browse files
author
Matthieu Honel
committed
Merge branch 'release/2.9.0'
2 parents ba8b4fd + 785cff5 commit 2eb3b57

File tree

5 files changed

+99
-61
lines changed

5 files changed

+99
-61
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Since data is pulled from YWH platform to your server, only regular outbound web
4949

5050
## Changelog
5151

52+
- v2.9:
53+
- prevented issue synchronization to fail when tracker file upload is unsuccessful
5254
- v2.8:
5355
- improved Python versions support (>=3.7 to <=3.12)
5456
- removed the GUI from the default installation (use `pip install 'ywh2bt[gui]'` to include the GUI)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ywh2bt"
3-
version = "2.8.2"
3+
version = "2.9.0"
44
description = "ywh2bt - YesWeHack to Bug Tracker"
55
readme = "README.md"
66
authors = ["m.honel <m.honel@yeswehack.com>"]

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
isolated_build = True
33
isolated_build_env = .pkg
44
toxworkdir={env:TOX_WORK_DIR:.tox}
5-
envlist = py37, py38, py39, py310, py311, py312
5+
envlist = py38, py39, py310, py311, py312
66

77
[testenv]
88
parallel_show_output = True

ywh2bt/core/api/trackers/gitlab.py

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
_TITLE_MAX_SIZE = 255
4949
_TEXT_MAX_SIZE = 1000000
5050

51+
AttachmentUploadResult = Tuple[Attachment, Optional[str], Optional[str]]
52+
5153

5254
class GitLabTrackerClientError(TrackerClientError):
5355
"""A GitLab tracker client error."""
@@ -423,36 +425,57 @@ def _get_gitlab_issue(
423425

424426
def _replace_attachments_references(
425427
self,
426-
uploads: List[Tuple[Attachment, str]],
428+
uploads: List[AttachmentUploadResult],
427429
referencing_texts: List[str],
428430
) -> List[str]:
429-
for attachment, upload_url in uploads:
430-
referencing_texts = [
431-
text.replace(
432-
attachment.url,
433-
f"{self.configuration.url}/{self.configuration.project}{upload_url}",
434-
)
435-
for text in referencing_texts
436-
]
431+
for attachment, upload_url, error_message in uploads:
432+
if upload_url:
433+
referencing_texts = [
434+
text.replace(
435+
attachment.url,
436+
f"{self.configuration.url}/{self.configuration.project}{upload_url}",
437+
)
438+
for text in referencing_texts
439+
]
440+
elif error_message:
441+
referencing_texts = [
442+
text.replace(
443+
attachment.url,
444+
error_message,
445+
)
446+
for text in referencing_texts
447+
]
437448
return referencing_texts
438449

439450
def _upload_attachments(
440451
self,
441452
gitlab_project: Project,
442453
attachments: List[Attachment],
443-
) -> List[Tuple[Attachment, str]]:
444-
try:
445-
return [
446-
(
447-
attachment,
448-
gitlab_project.upload(attachment.original_name, attachment.data)["url"],
454+
) -> List[AttachmentUploadResult]:
455+
uploads: List[AttachmentUploadResult] = []
456+
for attachment in attachments:
457+
try:
458+
upload = gitlab_project.upload(attachment.original_name, attachment.data)
459+
except GitlabError as e:
460+
uploads.append(
461+
(
462+
attachment,
463+
None,
464+
(
465+
f'(Attachment "{attachment.original_name}" not available due to upload error: '
466+
f'{getattr(e, "error_message", "Unknown error")})'
467+
),
468+
),
449469
)
450-
for attachment in attachments
451-
]
452-
except GitlabError as e:
453-
raise GitLabTrackerClientError(
454-
f"Unable to upload attachments for project {self.configuration.project} to GitLab",
455-
) from e
470+
else:
471+
uploads.append(
472+
(
473+
attachment,
474+
upload["url"],
475+
None,
476+
),
477+
)
478+
return uploads
456479

457480
def _get_attachments_list_description(
458481
self,

ywh2bt/core/api/trackers/jira/tracker.py

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
_TITLE_MAX_SIZE = 255
4343
_TEXT_MAX_SIZE = 32767
4444

45+
AttachmentUploadResult = Tuple[Attachment, Optional[str], Optional[str]]
46+
4547

4648
class JiraTrackerClientError(TrackerClientError):
4749
"""A Jira tracker client error."""
@@ -488,45 +490,47 @@ def _add_comment(
488490

489491
def _replace_attachments_references(
490492
self,
491-
uploads: List[Tuple[Attachment, str]],
493+
uploads: List[AttachmentUploadResult],
492494
referencing_texts: List[str],
493495
unique_name_prefix: str,
494496
) -> List[str]:
495-
for attachment, upload_url in uploads:
496-
referencing_texts = [
497-
(
498-
text
499-
# use the unique attachment name for thumbnails otherwise jira is much confused
500-
.replace(
501-
f"[{attachment.original_name}|{attachment.url}]",
502-
(
503-
f"[{self._make_attachment_unique_name(prefix=unique_name_prefix, attachment=attachment)}"
504-
f"|{attachment.url}]"
505-
),
506-
)
507-
.replace(
508-
f"!{attachment.original_name}|{attachment.url}!",
509-
(
510-
f"!{self._make_attachment_unique_name(prefix=unique_name_prefix, attachment=attachment)}"
511-
f"|{attachment.url}!"
512-
),
513-
)
497+
for attachment, upload_url, error_message in uploads:
498+
# use the unique attachment name for thumbnails otherwise jira is much confused
499+
unique_name = self._make_attachment_unique_name(prefix=unique_name_prefix, attachment=attachment)
500+
if upload_url:
501+
referencing_texts = [
502+
text.replace(f"[{attachment.original_name}|{attachment.url}]", f"[{unique_name}|{attachment.url}]")
503+
.replace(f"[{attachment.original_name}]({attachment.url})", f"[{unique_name}|{attachment.url}]")
504+
.replace(f"!{attachment.original_name}|{attachment.url}!", f"!{unique_name}|{attachment.url}!")
514505
.replace(
515506
attachment.url,
516507
upload_url,
517508
)
518-
)
519-
for text in referencing_texts
520-
]
509+
for text in referencing_texts
510+
]
511+
elif error_message:
512+
referencing_texts = [
513+
(
514+
text
515+
# replace attachment with the error message
516+
.replace(f"[{unique_name}|{attachment.url}]", error_message)
517+
.replace(f"[{unique_name}]({attachment.url})", error_message)
518+
.replace(f"!{unique_name}|{attachment.url}!", error_message)
519+
.replace(f"[{attachment.original_name}|{attachment.url}]", error_message)
520+
.replace(f"[{attachment.original_name}]({attachment.url})", error_message)
521+
.replace(f"!{attachment.original_name}|{attachment.url}!", error_message)
522+
)
523+
for text in referencing_texts
524+
]
521525
return referencing_texts
522526

523527
def _upload_attachments(
524528
self,
525529
issue: JIRAIssue,
526530
attachments: List[Attachment],
527531
unique_name_prefix: str,
528-
) -> List[Tuple[Attachment, str]]:
529-
uploads = []
532+
) -> List[AttachmentUploadResult]:
533+
uploads: List[AttachmentUploadResult] = []
530534
for attachment in attachments:
531535
# give each attachment a unique name so there's no confusion when jira displays a thumbnail
532536
filename = self._make_attachment_unique_name(prefix=unique_name_prefix, attachment=attachment)
@@ -537,19 +541,28 @@ def _upload_attachments(
537541
attachment=CustomBytesIO(buffer=attachment.data), # using CustomBytesIO despite jira expectations
538542
)
539543
except JIRAError as e:
540-
raise JiraTrackerClientError(
541-
f"Unable to upload attachments for project {self.configuration.project} to JIRA",
542-
) from e
543-
issue_attachment_url = quote(
544-
issue_attachment.content,
545-
safe=":/?&=",
546-
)
547-
uploads.append(
548-
(
549-
attachment,
550-
issue_attachment_url,
551-
),
552-
)
544+
uploads.append(
545+
(
546+
attachment,
547+
None,
548+
(
549+
f'(Attachment "{attachment.original_name}" not available due to upload error: '
550+
f'{getattr(e, "text", "Unknown error")})'
551+
),
552+
),
553+
)
554+
else:
555+
url = quote(
556+
issue_attachment.content,
557+
safe=":/?&=",
558+
)
559+
uploads.append(
560+
(
561+
attachment,
562+
url,
563+
None,
564+
)
565+
)
553566
return uploads
554567

555568
@classmethod

0 commit comments

Comments
 (0)