Skip to content

Commit

Permalink
fix: Fix fragment semantic resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Nov 2, 2023
1 parent db39fa7 commit 8f34128
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions capella_git_hooks/fix_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

fragment_pattern = re.compile(
rf"{prefix_pattern}fragments/.*\.(capella|aird)fragment"
rf"({prefix_pattern}fragments/).*\.(capella|aird)fragment"
)
fragment_reference_pattern = re.compile(
f"{fragment_pattern.pattern}{reference_pattern.pattern}"
Expand Down Expand Up @@ -72,14 +72,24 @@ def fix_semantic_resources(
"""Patch the semantic resource file paths and return a bool."""
changed = False
danalysis = next(root.iterchildren(DIAGRAM_OVERVIEW_TAG))
is_fragment = "fragments" in root.base
for resource in danalysis.iterchildren("semanticResources"):
if resource.text is None:
if not resource.text or root.base in resource.text:
danalysis.remove(resource)
changed = True
continue

text = search_and_replace(
fragment_pattern, resource.text, fragment_repl
)
text = search_and_replace(root_pattern, resource.text, root_repl)
if resource.text == text:
replacement = fragment_repl if is_fragment else root_repl
text = search_and_replace(root_pattern, resource.text, replacement)

if is_fragment and not resource.text.endswith("fragment"):
if not resource.text.startswith(root_repl):
text = f"{root_repl}{resource.text}"

if resource.text != text:
resource.text = text
changed = True
Expand Down

0 comments on commit 8f34128

Please sign in to comment.