From fc7f4e74f4e7cad10866983b6761f2d2a70380da Mon Sep 17 00:00:00 2001 From: micha91 Date: Wed, 4 Sep 2024 07:13:29 +0200 Subject: [PATCH] chore: Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ernst Würger --- .../connectors/polarion_worker.py | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/capella2polarion/connectors/polarion_worker.py b/capella2polarion/connectors/polarion_worker.py index 48f80580..a63e1e34 100644 --- a/capella2polarion/connectors/polarion_worker.py +++ b/capella2polarion/connectors/polarion_worker.py @@ -123,6 +123,7 @@ def load_polarion_work_item_map(self): work_items = self.project_client.work_items.get_all( "HAS_VALUE:uuid_capella", fields={"workitems": "id,uuid_capella,checksum,status,type"}, + work_item_cls=data_models.CapellaWorkItem, ) self.polarion_data_repo.update_work_items(work_items) @@ -141,11 +142,13 @@ def delete_orphaned_work_items( if work_item.status != "deleted" } uuids: set[str] = existing_work_items - set(converter_session) - work_items = [ - self.polarion_data_repo.get_work_item_by_capella_uuid(uuid) - for uuid in uuids - ] - if work_items: + work_items: list[data_models.CapellaWorkitem] = [] + for uuid in uuids: + if wi := self.polarion_data_repo.get_work_item_by_capella_uuid( + uuid + ): + logger.info("Delete work item %r...", wi.id) + work_items.append(wi) try: self.project_client.work_items.delete(work_items) self.polarion_data_repo.remove_work_items_by_capella_uuid( @@ -214,7 +217,9 @@ def compare_and_update_work_item( work_item_changed = new_work_item_check_sum != old_work_item_check_sum try: if work_item_changed or self.force_update: - old = self.project_client.work_items.get(old.id) + old = self.project_client.work_items.get( + old.id, work_item_cls=data_models.CapellaWorkItem + ) if old.attachments: old_attachments = ( self.project_client.work_items.attachments.get_all( @@ -466,7 +471,13 @@ def create_documents( document_datas: list[data_models.DocumentData], document_project: str | None = None, ): - """Create new documents.""" + """Create new documents. + + Notes + ----- + If the ``document_project`` is ``None`` the default client is + taken. + """ client = self._get_client(document_project) documents, _ = self._process_document_datas(client, document_datas) @@ -477,7 +488,13 @@ def update_documents( document_datas: list[data_models.DocumentData], document_project: str | None = None, ): - """Update existing documents.""" + """Update existing documents. + + Notes + ----- + If the ``document_project`` is ``None`` the default client is + taken. + """ client = self._get_client(document_project) documents, headings = self._process_document_datas( client, document_datas @@ -491,10 +508,10 @@ def _process_document_datas( client: polarion_api.ProjectClient, document_datas: list[data_models.DocumentData], ): - documents = [] - headings = [] + documents: list[polarion_api.Document] = [] + headings: list[polarion_api.WorkItem] = [] for document_data in document_datas: - headings += document_data.headings + headings.extend(document_data.headings) documents.append(document_data.document) if document_data.text_work_item_provider.new_text_work_items: self._create_and_update_text_work_items( @@ -509,7 +526,13 @@ def _process_document_datas( def get_document( self, space: str, name: str, document_project: str | None = None ) -> polarion_api.Document | None: - """Get a document from polarion and return None if not found.""" + """Get a document from polarion and return None if not found. + + Notes + ----- + If the ``document_project`` is ``None`` the default client is + taken. + """ client = self._get_client(document_project) try: return client.documents.get(