Coverage for sel_tools/gitlab_api/attachments.py: 100%
10 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-04 21:22 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-04 21:22 +0000
1"""Upload attachments to gitlab."""
3from pathlib import Path
5from gitlab.v4.objects.projects import Project
7from sel_tools.config import REPO_DIR
10def upload_attachments(attachments: list[Path], gitlab_project: Project) -> list:
11 """Upload attachments to gitlab and return the URL."""
12 return [gitlab_project.upload(attachment.name, filepath=attachment) for attachment in attachments]
15def replace_file_paths_with_urls(description: str, uploaded_files: list, attachments: list[Path]) -> str:
16 """Replace local file paths in description with gitlab URLs."""
17 for uploaded_file, attachment in zip(uploaded_files, attachments, strict=True):
18 file_path_in_description = f"/{attachment.relative_to(REPO_DIR)}"
19 description = description.replace(file_path_in_description, uploaded_file["url"])
20 return description