Skip to content

Commit

Permalink
fix: Only set those fields of a document which actually need to be up…
Browse files Browse the repository at this point in the history
…dated
  • Loading branch information
micha91 committed Dec 19, 2024
1 parent 91afc12 commit cccdc9a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
6 changes: 5 additions & 1 deletion capella2polarion/connectors/polarion_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ def get_document(
client = self._get_client(document_project)
try:
return client.documents.get(
space, name, fields={"documents": "@all"}
space,
name,
fields={
"documents": "renderingLayouts,homePageContent,status,moduleFolder,moduleName"
},
)
except polarion_api.PolarionApiBaseException as e:
if e.args[0] == 404:
Expand Down
14 changes: 12 additions & 2 deletions capella2polarion/converters/document_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ def _get_and_customize_doc(
(project_id, space, name), (None, [])
)
if old_doc is not None:
old_doc = polarion_api.Document(
id=old_doc.id,
module_folder=old_doc.module_folder,
module_name=old_doc.module_name,
status=old_doc.status,
home_page_content=old_doc.home_page_content,
rendering_layouts=old_doc.rendering_layouts,
)
if title:
old_doc.title = title
if self.overwrite_layouts:
Expand Down Expand Up @@ -422,16 +430,18 @@ def _check_document_status(
document: polarion_api.Document,
config: document_config.BaseDocumentRenderingConfig,
):
status = document.status
document.status = None
if (
config.status_allow_list is not None
and document.status not in config.status_allow_list
and status not in config.status_allow_list
):
logger.warning(
"Won't update document %s/%s due to status "
"restrictions. Status is %s and should be in %r.",
document.module_folder,
document.module_name,
document.status,
status,
config.status_allow_list,
)
return False
Expand Down
2 changes: 2 additions & 0 deletions ci-templates/gitlab/synchronise_elements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ variables:
# CAPELLA2POLARION_FORCE_UPDATE - Simulate initial run
# CAPELLA2POLARION_TYPE_PREFIX - Prefix for work item types
# CAPELLA2POLARION_ROLE_PREFIX - Prefix for work item link roles
# CAPELLA2POLARION_GENERATE_FIGURE_CAPTIONS - Generate captions for figures
# CAPELLA2POLARION_GROUPED_LINKS_CUSTOM_FIELDS - Generate custom fields for links grouped by role

capella2polarion_synchronise_elements:
needs:
Expand Down
17 changes: 16 additions & 1 deletion tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def existing_documents() -> polarion_repo.DocumentRepository:
type="text/html",
value=MIXED_AUTHORITY_DOCUMENT.read_text("utf-8"),
),
outline_numbering_prefix="X",
rendering_layouts=[
polarion_api.RenderingLayout(
"text", "paragraph", type="text"
Expand Down Expand Up @@ -496,7 +497,7 @@ def test_render_all_documents_partially_successfully(
# There are 8 documents in the config, we expect 4 rendering to fail
assert len(caplog.records) == 4
# The first tree documents weren't rendered due to an error, the fourth
# wasn't rendered because of status restrictions, which is a just warning
# wasn't rendered because of status restrictions, which is a warning
assert [lr.levelno for lr in caplog.records] == [40, 40, 40, 30]
# For one valid config we did not pass a document, so we expect a new one
assert len(projects_data[None].new_docs) == 1
Expand Down Expand Up @@ -540,6 +541,20 @@ def test_render_all_documents_partially_successfully(
assert (
projects_data[None].updated_docs[1].document.outline_numbering is None
)
assert not any(
doc.document.status is not None
for doc in (
projects_data[None].updated_docs
+ projects_data["TestProject"].updated_docs
)
)
assert not any(
doc.document.outline_numbering_prefix is not None
for doc in (
projects_data[None].updated_docs
+ projects_data["TestProject"].updated_docs
)
)


def test_insert_work_item_cross_project(
Expand Down

0 comments on commit cccdc9a

Please sign in to comment.